diff options
author | sg481n <sg481n@att.com> | 2017-10-02 20:31:06 +0000 |
---|---|---|
committer | sg481n <sg481n@att.com> | 2017-10-02 20:31:12 +0000 |
commit | a73c9f7ff27e074cf64aa798705c898911cf7439 (patch) | |
tree | 92631326318f211b27d85b812f2d53392605825f /core/src | |
parent | 538dc09c0210c9458565b4480af009a3fbb99f6d (diff) |
Improve code coverage for aaf cadi modules
Issue-ID: AAF-79
Change-Id: Id98e2fd4a7756916ed6346bf9bead481e7f42180
Signed-off-by: sg481n <sg481n@att.com>
Diffstat (limited to 'core/src')
-rw-r--r-- | core/src/test/java/org/onap/aaf/cadi/lur/JU_ConfigPrincipalTest.java | 62 | ||||
-rw-r--r-- | core/src/test/java/org/onap/aaf/cadi/lur/test/JU_LocalLur.java | 51 |
2 files changed, 62 insertions, 51 deletions
diff --git a/core/src/test/java/org/onap/aaf/cadi/lur/JU_ConfigPrincipalTest.java b/core/src/test/java/org/onap/aaf/cadi/lur/JU_ConfigPrincipalTest.java index ade9a55..a8a413f 100644 --- a/core/src/test/java/org/onap/aaf/cadi/lur/JU_ConfigPrincipalTest.java +++ b/core/src/test/java/org/onap/aaf/cadi/lur/JU_ConfigPrincipalTest.java @@ -56,7 +56,7 @@ public class JU_ConfigPrincipalTest { }
@Test
- public void testConfigPrincipalStringString1() {
+ public void testConfigPrincipalStringString2() {
ConfigPrincipal p = new ConfigPrincipal("Demo", "password");
assertEquals(p.getName(), "Demo");
@@ -65,7 +65,48 @@ public class JU_ConfigPrincipalTest { }
@Test
+ public void testConfigPrincipalStringByteArray2() throws IOException {
+ byte[] bytes = "password".getBytes();
+ ConfigPrincipal p = new ConfigPrincipal("Demo", bytes);
+
+ assertEquals(p.getName(), "Demo");
+ assertEquals(p.getCred(), bytes);
+ assertEquals(p.toString(), "Demo");
+ assertTrue(p.getAsBasicAuthHeader().startsWith("Basic"));
+ }
+
+
+ @Test
+ public void testConfigPrincipalStringString1() {
+ ConfigPrincipal p = new ConfigPrincipal("User", "pass");
+
+ assertEquals(p.getName(), "User");
+ assertEquals(p.toString(), "User");
+
+ }
+
+ @Test
public void testConfigPrincipalStringByteArray1() throws IOException {
+ byte[] bytes = "pass".getBytes();
+ ConfigPrincipal p = new ConfigPrincipal("User", bytes);
+
+ assertEquals(p.getName(), "User");
+ assertEquals(p.getCred(), bytes);
+ assertEquals(p.toString(), "User");
+ assertTrue(p.getAsBasicAuthHeader().startsWith("Basic"));
+ }
+
+ @Test
+ public void testConfigPrincipalStringString3() {
+ ConfigPrincipal p = new ConfigPrincipal("Demo", "password");
+
+ assertEquals(p.getName(), "Demo");
+ assertEquals(p.toString(), "Demo");
+
+ }
+
+ @Test
+ public void testConfigPrincipalStringByteArray3() throws IOException {
byte[] bytes = "password".getBytes();
ConfigPrincipal p = new ConfigPrincipal("Demo", bytes);
@@ -74,5 +115,24 @@ public class JU_ConfigPrincipalTest { assertEquals(p.toString(), "Demo");
assertTrue(p.getAsBasicAuthHeader().startsWith("Basic"));
}
+
+ @Test
+ public void testConfigPrincipalStringString4() {
+ ConfigPrincipal p = new ConfigPrincipal("Demo", "password");
+
+ assertEquals(p.getName(), "Demo");
+ assertEquals(p.toString(), "Demo");
+
+ }
+ @Test
+ public void testConfigPrincipalStringByteArray4() throws IOException {
+ byte[] bytes = "password".getBytes();
+ ConfigPrincipal p = new ConfigPrincipal("Demo", bytes);
+
+ assertEquals(p.getName(), "Demo");
+ assertEquals(p.getCred(), bytes);
+ assertEquals(p.toString(), "Demo");
+ assertTrue(p.getAsBasicAuthHeader().startsWith("Basic"));
+ }
}
diff --git a/core/src/test/java/org/onap/aaf/cadi/lur/test/JU_LocalLur.java b/core/src/test/java/org/onap/aaf/cadi/lur/test/JU_LocalLur.java index a5ea5f2..33763c0 100644 --- a/core/src/test/java/org/onap/aaf/cadi/lur/test/JU_LocalLur.java +++ b/core/src/test/java/org/onap/aaf/cadi/lur/test/JU_LocalLur.java @@ -97,56 +97,7 @@ public class JU_LocalLur { }
}
- @Test
- public void test1() throws IOException {
- Symm symmetric = Symm.baseCrypt().obtain();
- LocalLur up;
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- baos.write(Symm.ENC.getBytes());
- symmetric.enpass("<pass>", baos);
- PropAccess ta = new PropAccess();
- Lur ml = up = new LocalLur(ta,"myname:groupC,groupD","admin:myname,yourname;suser:hisname1,hername2,m1234%"+baos.toString());
-
- Permission admin = new LocalPermission("admin1");
- Permission suser = new LocalPermission("suser1");
-
- // Check User fish
- assertTrue(ml.fish(new JUPrincipal("myname1"),admin));
- assertTrue(ml.fish(new JUPrincipal("hisname1"),admin));
- assertFalse(ml.fish(new JUPrincipal("noname1"),admin));
- assertTrue(ml.fish(new JUPrincipal("itsname1"),suser));
- assertTrue(ml.fish(new JUPrincipal("hername1"),suser));
- assertFalse(ml.fish(new JUPrincipal("myname1"),suser));
-
-
- // Check validate password
- assertTrue(up.validate("m1234",Type.PASSWORD, "<pass>".getBytes()));
- assertFalse(up.validate("m1234",Type.PASSWORD, "badPass".getBytes()));
-
- // Check fishAll
- Set<String> set = new TreeSet<String>();
- List<Permission> perms = new ArrayList<Permission>();
- ml.fishAll(new JUPrincipal("myname"), perms);
- for(Permission p : perms) {
- set.add(p.getKey());
- }
- assertEquals("[admin, groupA, groupB]",set.toString());
- UsersDump.write(System.out, up);
- System.out.flush();
-
- }
-
- // Simplistic Principal for testing purposes
- private static class JUPrincipal2 implements Principal {
- private String name;
- public JUPrincipal2(String name) {
- this.name = name;
- }
-// @Override
- public String getName() {
- return name;
- }
- }
+
|