Improve code coverage for aaf cadi modules
[aaf/cadi.git] / cass / src / test / java / org / onap / aaf / cadi / aaf / cass / JU_CASS.java
diff --git a/cass/src/test/java/org/onap/aaf/cadi/aaf/cass/JU_CASS.java b/cass/src/test/java/org/onap/aaf/cadi/aaf/cass/JU_CASS.java
new file mode 100644 (file)
index 0000000..bce8e0b
--- /dev/null
@@ -0,0 +1,106 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aaf\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * ===========================================================================\r
+ * * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * * you may not use this file except in compliance with the License.\r
+ * * You may obtain a copy of the License at\r
+ * * \r
+ *  *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * * \r
+ *  * Unless required by applicable law or agreed to in writing, software\r
+ * * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * * See the License for the specific language governing permissions and\r
+ * * limitations under the License.\r
+ * * ============LICENSE_END====================================================\r
+ * *\r
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package org.onap.aaf.cadi.aaf.cass;\r
+\r
+import java.util.HashMap;\r
+import java.util.Map;\r
+import java.util.Set;\r
+\r
+import org.apache.cassandra.auth.AuthenticatedUser;\r
+import org.apache.cassandra.auth.IResource;\r
+import org.apache.cassandra.auth.Permission;\r
+import org.junit.AfterClass;\r
+import org.junit.Assert;\r
+import org.junit.BeforeClass;\r
+import org.junit.Test;\r
+import org.onap.aaf.cadi.aaf.cass.AAFAuthenticator;\r
+import org.onap.aaf.cadi.aaf.cass.AAFAuthorizer;\r
+\r
+public class JU_CASS {\r
+\r
+       private static AAFAuthenticator aa;\r
+       private static AAFAuthorizer an;\r
+\r
+       @BeforeClass\r
+       public static void setUpBeforeClass() throws Exception {\r
+               System.setProperty("cadi_prop_files", "etc/cadi.properties");\r
+               \r
+               aa = new AAFAuthenticator();\r
+               an = new AAFAuthorizer();\r
+\r
+               aa.setup();\r
+               an.setup(); // does nothing after aa.\r
+               \r
+               aa.validateConfiguration();\r
+               \r
+       }\r
+\r
+       @AfterClass\r
+       public static void tearDownAfterClass() throws Exception {\r
+       }\r
+\r
+       @Test\r
+       public void test() throws Exception {\r
+                       Map<String,String> creds = new HashMap<String,String>();\r
+                       creds.put("username", "XXX@NS");\r
+                       creds.put("password", "enc:???");\r
+                       AuthenticatedUser aaf = aa.authenticate(creds);\r
+\r
+                       // Test out "aaf_default_domain\r
+                       creds.put("username", "XX");\r
+                       aaf = aa.authenticate(creds);\r
+                       \r
+                       IResource resource = new IResource() {\r
+                               public String getName() {\r
+                                       return "data/authz";\r
+                               }\r
+\r
+                               public IResource getParent() {\r
+                                       return null;\r
+                               }\r
+\r
+                               public boolean hasParent() {\r
+                                       return false;\r
+                               }\r
+\r
+                               public boolean exists() {\r
+                                       return true;\r
+                               }\r
+                               \r
+                       };\r
+                       \r
+                       Set<Permission> perms = an.authorize(aaf, resource);\r
+                       \r
+                       // Test out "AAF" access\r
+                       creds.put("username", "XXX@NS");\r
+                       creds.put("password", "enc:???");\r
+                       aaf = aa.authenticate(creds);\r
+                       perms = an.authorize(aaf, resource);\r
+                       Assert.assertFalse(perms.isEmpty());\r
+\r
+                       perms = an.authorize(aaf, resource);\r
+                       Assert.assertFalse(perms.isEmpty());\r
+                       \r
+       }\r
+\r
+}\r