Improve code coverage for aaf cadi modules
[aaf/cadi.git] / cass / src / test / java / org / onap / aaf / cadi / aaf / cass / test / JU_CASS.java
1 /*******************************************************************************\r
2  * ============LICENSE_START====================================================\r
3  * * org.onap.aaf\r
4  * * ===========================================================================\r
5  * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
6  * * ===========================================================================\r
7  * * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * * you may not use this file except in compliance with the License.\r
9  * * You may obtain a copy of the License at\r
10  * * \r
11  *  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  * * \r
13  *  * Unless required by applicable law or agreed to in writing, software\r
14  * * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * * See the License for the specific language governing permissions and\r
17  * * limitations under the License.\r
18  * * ============LICENSE_END====================================================\r
19  * *\r
20  * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
21  * *\r
22  ******************************************************************************/\r
23 package org.onap.aaf.cadi.aaf.cass.test;\r
24 \r
25 import java.util.HashMap;\r
26 import java.util.Map;\r
27 import java.util.Set;\r
28 \r
29 import org.apache.cassandra.auth.AuthenticatedUser;\r
30 import org.apache.cassandra.auth.IResource;\r
31 import org.apache.cassandra.auth.Permission;\r
32 import org.junit.AfterClass;\r
33 import org.junit.Assert;\r
34 import org.junit.BeforeClass;\r
35 import org.junit.Test;\r
36 import org.onap.aaf.cadi.aaf.cass.AAFAuthenticator;\r
37 import org.onap.aaf.cadi.aaf.cass.AAFAuthorizer;\r
38 \r
39 public class JU_CASS {\r
40 \r
41         private static AAFAuthenticator aa;\r
42         private static AAFAuthorizer an;\r
43 \r
44         @BeforeClass\r
45         public static void setUpBeforeClass() throws Exception {\r
46                 System.setProperty("cadi_prop_files", "etc/cadi.properties");\r
47                 \r
48                 aa = new AAFAuthenticator();\r
49                 an = new AAFAuthorizer();\r
50 \r
51                 aa.setup();\r
52                 an.setup(); // does nothing after aa.\r
53                 \r
54                 aa.validateConfiguration();\r
55                 \r
56         }\r
57 \r
58         @AfterClass\r
59         public static void tearDownAfterClass() throws Exception {\r
60         }\r
61 \r
62         @Test\r
63         public void test() throws Exception {\r
64                         Map<String,String> creds = new HashMap<String,String>();\r
65                         creds.put("username", "XXX@NS");\r
66                         creds.put("password", "enc:???");\r
67                         AuthenticatedUser aaf = aa.authenticate(creds);\r
68 \r
69                         // Test out "aaf_default_domain\r
70                         creds.put("username", "XX");\r
71                         aaf = aa.authenticate(creds);\r
72                         \r
73                         IResource resource = new IResource() {\r
74                                 public String getName() {\r
75                                         return "data/authz";\r
76                                 }\r
77 \r
78                                 public IResource getParent() {\r
79                                         return null;\r
80                                 }\r
81 \r
82                                 public boolean hasParent() {\r
83                                         return false;\r
84                                 }\r
85 \r
86                                 public boolean exists() {\r
87                                         return true;\r
88                                 }\r
89                                 \r
90                         };\r
91                         \r
92                         Set<Permission> perms = an.authorize(aaf, resource);\r
93                         \r
94                         // Test out "AAF" access\r
95                         creds.put("username", "XXX@NS");\r
96                         creds.put("password", "enc:???");\r
97                         aaf = aa.authenticate(creds);\r
98                         perms = an.authorize(aaf, resource);\r
99                         Assert.assertFalse(perms.isEmpty());\r
100 \r
101                         perms = an.authorize(aaf, resource);\r
102                         Assert.assertFalse(perms.isEmpty());\r
103                         \r
104         }\r
105 \r
106 }\r