diff options
author | James Forsyth <jf2512@att.com> | 2018-12-11 12:38:29 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2018-12-11 12:38:29 +0000 |
commit | e42c7cf9d25b5a5ec3e3bf2cbb5e04441ec45359 (patch) | |
tree | 4413dcd6a790fdbeffc792f64bef531d4c1fd4d8 /aai-core/src/test | |
parent | 80fee7d8e6bb5c28de01cefe3453618051188528 (diff) | |
parent | e2022e79c4d7e23d699bfff3fa904fb48f7d29e2 (diff) |
Merge "AAI-1523 checkstyle warnings for aai-core auth"
Diffstat (limited to 'aai-core/src/test')
-rw-r--r-- | aai-core/src/test/java/org/onap/aai/auth/AAIAuthCoreTest.java | 352 | ||||
-rw-r--r-- | aai-core/src/test/java/org/onap/aai/auth/AAIUserTest.java | 46 |
2 files changed, 199 insertions, 199 deletions
diff --git a/aai-core/src/test/java/org/onap/aai/auth/AAIAuthCoreTest.java b/aai-core/src/test/java/org/onap/aai/auth/AAIAuthCoreTest.java index 97d00c8b..2c299869 100644 --- a/aai-core/src/test/java/org/onap/aai/auth/AAIAuthCoreTest.java +++ b/aai-core/src/test/java/org/onap/aai/auth/AAIAuthCoreTest.java @@ -28,181 +28,181 @@ import static org.junit.Assert.*; public class AAIAuthCoreTest extends AAISetup { - private AAIAuthCore authCore; - - @Before - public void setup(){ - authCore = new AAIAuthCore("/aai"); - } - - @Test - public void getAuthPolicyFunctionNameTest() { - - String uri = "/aai/v3/search/edge-tag-query"; - assertEquals("Get aai function name from " + uri, "search", authCore.getAuthPolicyFunctName(uri)); - - uri = "/aai/v10/search/edge-tag-query"; - assertEquals("Get aai function name from " + uri, "search", authCore.getAuthPolicyFunctName(uri)); - - uri = "/aai/search/model"; - assertEquals("Get aai function name from " + uri, "search", authCore.getAuthPolicyFunctName(uri)); - - uri = "/aai/v9/cloud-infrastructure/cloud-regions/cloud-region/somecloudregion/some-cloud-owner"; - assertEquals("Get aai function name from " + uri, "cloud-infrastructure", authCore.getAuthPolicyFunctName(uri)); - - uri = "/aai/v8/network/pnfs/pnf/ff4ca01orc/p-interfaces"; - assertEquals("Get aai function name from " + uri, "network", authCore.getAuthPolicyFunctName(uri)); - - uri = "/aai/util/echo"; - assertEquals("Get aai function name from " + uri, "util", authCore.getAuthPolicyFunctName(uri)); - - uri = "/aai/tools"; - assertEquals("Get aai function name from " + uri, "tools", authCore.getAuthPolicyFunctName(uri)); - - uri = "/aai/v12/bulk/single-transaction"; - assertEquals("Get aai function name from " + uri, "bulk", authCore.getAuthPolicyFunctName(uri)); - - } - - @Test - public void validUsernameAuthTest() throws AAIUnrecognizedFunctionException { - assertTrue(authCore.authorize("testUser".toLowerCase(), "/aai/v0/testFunction/someUri", "PUT", "")); - } - - @Test - public void validUsernameInvalidHttpMethodAuthTest() throws AAIUnrecognizedFunctionException { - assertFalse(authCore.authorize("testUser".toLowerCase(), "/aai/v0/testFunction/someUri", "POST", "")); - } - - @Test(expected = AAIUnrecognizedFunctionException.class) - public void validUsernameInvalidFunctionInURIAuthTest() throws AAIUnrecognizedFunctionException { - authCore.authorize("testUser".toLowerCase(), "/aai/v0/badFunction/someUri", "PUT", ""); - } - - @Test - public void invalidUsernameAuthTest() throws AAIUnrecognizedFunctionException { - assertFalse(authCore.authorize("invlaidTestUser".toLowerCase(), "/aai/v0/testFunction/someUri", "PUT", "")); - } - - @Test - public void validUsernameIsTheExactWildcardIdAuthTest() throws AAIUnrecognizedFunctionException { - assertTrue(authCore.authorize("testWildcardId".toLowerCase(), "/aai/v0/testFunction/someUri", "PUT", "")); - } - - @Test - public void validUsernameContainsTheWildcardIdAuthTest() throws AAIUnrecognizedFunctionException { - assertTrue(authCore.authorize("cn=blah, testWildcardId, O=".toLowerCase(), "/aai/v0/testFunction/someUri", "PUT", "", "aafWildCardIssuer")); - } - - @Test - public void validUsernameContainsTheWildcardIdInvalidIssuerAuthTest() throws AAIUnrecognizedFunctionException { - assertFalse(authCore.authorize("cn=blah, testWildcardId, O=".toLowerCase(), "/aai/v0/testFunction/someUri", "PUT", "", "invalidIssuer")); - } - - @Test - public void invalidUsernameContainsRegularUsernameAuthTest() throws AAIUnrecognizedFunctionException { - assertFalse(authCore.authorize("cn=blah, testUser, O=".toLowerCase(), "/aai/v0/testFunction/someUri", "PUT", "")); - } - - @Test - public void haProxyUsernameAuthTest() throws AAIUnrecognizedFunctionException { - assertTrue(authCore.authorize("ha-proxy-user".toLowerCase(), "/aai/util/echo", "GET", "")); - } - - @Test - public void haProxyUsernameInvalidFunctionAuthTest() throws AAIUnrecognizedFunctionException { - assertFalse(authCore.authorize("ha-proxy-user".toLowerCase(), "/aai/v0/testFunction/someUri", "PUT", "")); - } - - @Test - public void validUsernameViaHaProxyAuthTest() throws AAIUnrecognizedFunctionException { - assertTrue(authCore.authorize("ha-proxy-user".toLowerCase(), "/aai/v0/testFunction/someUri", "PUT", "testUser".toLowerCase())); - } - - @Test - public void validUsernameInvalidHttpMethodViaHaProxyAuthTest() throws AAIUnrecognizedFunctionException { - assertFalse(authCore.authorize("ha-proxy-user".toLowerCase(), "/aai/v0/testFunction/someUri", "POST", "testUser".toLowerCase())); - } - - @Test(expected = AAIUnrecognizedFunctionException.class) - public void validUsernameInvalidFunctionInURIViaHaProxyAuthTest() throws AAIUnrecognizedFunctionException { - authCore.authorize("ha-proxy-user".toLowerCase(), "/aai/v0/badFunction/someUri", "PUT", "testUser".toLowerCase()); - } - - @Test - public void invalidUsernameViaHaProxyAuthTest() throws AAIUnrecognizedFunctionException { - assertFalse(authCore.authorize("ha-proxy-user".toLowerCase(), "/aai/v0/testFunction/someUri", "PUT", "invlaidTestUser".toLowerCase())); - } - - @Test - public void validUsernameIsTheExactWildcardIdViaHaProxyAuthTest() throws AAIUnrecognizedFunctionException { - assertTrue(authCore.authorize("ha-proxy-user".toLowerCase(), "/aai/v0/testFunction/someUri", "PUT", "testWildcardId".toLowerCase())); - } - - @Test - public void validUsernameContainsTheWildcardIdViaHaProxyAuthTest() throws AAIUnrecognizedFunctionException { - assertTrue(authCore.authorize("ha-proxy-user".toLowerCase(), "/aai/v0/testFunction/someUri", "PUT", "cn=blah, testWildcardId, O=".toLowerCase(), "aafWildCardIssuer")); - } - - @Test - public void invalidUsernameContainsRegularUsernameViaHaProxyAuthTest() throws AAIUnrecognizedFunctionException { - assertFalse(authCore.authorize("ha-proxy-user".toLowerCase(), "/aai/v0/testFunction/someUri", "PUT", "cn=blah, testUser, O=".toLowerCase())); - } - - @Test - public void haProxyUsernameTwiceAuthTest() throws AAIUnrecognizedFunctionException { - assertFalse(authCore.authorize("ha-proxy-user".toLowerCase(), "/aai/v0/testFunction/someUri", "PUT", "ha-proxy-user".toLowerCase())); - } - - - @Test - public void haProxyWildcardIdAuthTest() throws AAIUnrecognizedFunctionException { - assertTrue(authCore.authorize("cn=blah, ha-proxy-wildcard-id, O=".toLowerCase(), "/aai/util/echo", "GET", "", "aafWildCardIssuer")); - } - - @Test - public void haProxyWildcardIdInvalidFunctionAuthTest() throws AAIUnrecognizedFunctionException { - assertFalse(authCore.authorize("cn=blah, ha-proxy-wildcard-id, O=".toLowerCase(), "/aai/v0/testFunction/someUri", "PUT", "")); - } - - @Test - public void validUsernameViaHaProxyWildcardIdAuthTest() throws AAIUnrecognizedFunctionException { - assertTrue(authCore.authorize("cn=blah, ha-proxy-wildcard-id, O=".toLowerCase(), "/aai/v0/testFunction/someUri", "PUT", "testUser".toLowerCase(), "aafWildCardIssuer")); - } - - @Test - public void validUsernameInvalidHttpMethodViaHaProxyWildcardIdAuthTest() throws AAIUnrecognizedFunctionException { - assertFalse(authCore.authorize("cn=blah, ha-proxy-wildcard-id, O=".toLowerCase(), "/aai/v0/testFunction/someUri", "POST", "testUser".toLowerCase())); - } - - @Test(expected = AAIUnrecognizedFunctionException.class) - public void validUsernameInvalidFunctionInURIViaHaProxyWildcardIdAuthTest() throws AAIUnrecognizedFunctionException { - authCore.authorize("cn=blah, ha-proxy-wildcard-id, O=".toLowerCase(), "/aai/v0/badFunction/someUri", "PUT", "testUser".toLowerCase()); - } - - @Test - public void invalidUsernameViaHaProxyWildcardIdAuthTest() throws AAIUnrecognizedFunctionException { - assertFalse(authCore.authorize("cn=blah, ha-proxy-wildcard-id, O=".toLowerCase(), "/aai/v0/testFunction/someUri", "PUT", "invlaidTestUser".toLowerCase())); - } - - @Test - public void validUsernameIsTheExactWildcardIdViaHaProxyWildcardIdAuthTest() throws AAIUnrecognizedFunctionException { - assertTrue(authCore.authorize("cn=blah, ha-proxy-wildcard-id, O=".toLowerCase(), "/aai/v0/testFunction/someUri", "PUT", "testWildcardId".toLowerCase(), "aafWildCardIssuer")); - } - - @Test - public void validUsernameContainsTheWildcardIdViaHaProxyWildcardIdAuthTest() throws AAIUnrecognizedFunctionException { - assertTrue(authCore.authorize("cn=blah, ha-proxy-wildcard-id, O=".toLowerCase(), "/aai/v0/testFunction/someUri", "PUT", "cn=blah, testWildcardId, O=".toLowerCase(), "aafWildCardIssuer")); - } - - @Test - public void validUsernameContainsTheWildcardIdViaHaProxyWildcardIdInvalidIssuerAuthTest() throws AAIUnrecognizedFunctionException { - assertFalse(authCore.authorize("cn=blah, ha-proxy-wildcard-id, O=".toLowerCase(), "/aai/v0/testFunction/someUri", "PUT", "cn=blah, testWildcardId, O=".toLowerCase(), "invalidIssuer")); - } - - @Test - public void invalidUsernameContainsRegularUsernameViaHaProxyWildcardIdAuthTest() throws AAIUnrecognizedFunctionException { - assertFalse(authCore.authorize("cn=blah, ha-proxy-wildcard-id, O=".toLowerCase(), "/aai/v0/testFunction/someUri", "PUT", "cn=blah, testUser, O=".toLowerCase())); - } + private AAIAuthCore authCore; + + @Before + public void setup(){ + authCore = new AAIAuthCore("/aai"); + } + + @Test + public void getAuthPolicyFunctionNameTest() { + + String uri = "/aai/v3/search/edge-tag-query"; + assertEquals("Get aai function name from " + uri, "search", authCore.getAuthPolicyFunctName(uri)); + + uri = "/aai/v10/search/edge-tag-query"; + assertEquals("Get aai function name from " + uri, "search", authCore.getAuthPolicyFunctName(uri)); + + uri = "/aai/search/model"; + assertEquals("Get aai function name from " + uri, "search", authCore.getAuthPolicyFunctName(uri)); + + uri = "/aai/v9/cloud-infrastructure/cloud-regions/cloud-region/somecloudregion/some-cloud-owner"; + assertEquals("Get aai function name from " + uri, "cloud-infrastructure", authCore.getAuthPolicyFunctName(uri)); + + uri = "/aai/v8/network/pnfs/pnf/ff4ca01orc/p-interfaces"; + assertEquals("Get aai function name from " + uri, "network", authCore.getAuthPolicyFunctName(uri)); + + uri = "/aai/util/echo"; + assertEquals("Get aai function name from " + uri, "util", authCore.getAuthPolicyFunctName(uri)); + + uri = "/aai/tools"; + assertEquals("Get aai function name from " + uri, "tools", authCore.getAuthPolicyFunctName(uri)); + + uri = "/aai/v12/bulk/single-transaction"; + assertEquals("Get aai function name from " + uri, "bulk", authCore.getAuthPolicyFunctName(uri)); + + } + + @Test + public void validUsernameAuthTest() throws AAIUnrecognizedFunctionException { + assertTrue(authCore.authorize("testUser".toLowerCase(), "/aai/v0/testFunction/someUri", "PUT", "")); + } + + @Test + public void validUsernameInvalidHttpMethodAuthTest() throws AAIUnrecognizedFunctionException { + assertFalse(authCore.authorize("testUser".toLowerCase(), "/aai/v0/testFunction/someUri", "POST", "")); + } + + @Test(expected = AAIUnrecognizedFunctionException.class) + public void validUsernameInvalidFunctionInURIAuthTest() throws AAIUnrecognizedFunctionException { + authCore.authorize("testUser".toLowerCase(), "/aai/v0/badFunction/someUri", "PUT", ""); + } + + @Test + public void invalidUsernameAuthTest() throws AAIUnrecognizedFunctionException { + assertFalse(authCore.authorize("invlaidTestUser".toLowerCase(), "/aai/v0/testFunction/someUri", "PUT", "")); + } + + @Test + public void validUsernameIsTheExactWildcardIdAuthTest() throws AAIUnrecognizedFunctionException { + assertTrue(authCore.authorize("testWildcardId".toLowerCase(), "/aai/v0/testFunction/someUri", "PUT", "")); + } + + @Test + public void validUsernameContainsTheWildcardIdAuthTest() throws AAIUnrecognizedFunctionException { + assertTrue(authCore.authorize("cn=blah, testWildcardId, O=".toLowerCase(), "/aai/v0/testFunction/someUri", "PUT", "", "aafWildCardIssuer")); + } + + @Test + public void validUsernameContainsTheWildcardIdInvalidIssuerAuthTest() throws AAIUnrecognizedFunctionException { + assertFalse(authCore.authorize("cn=blah, testWildcardId, O=".toLowerCase(), "/aai/v0/testFunction/someUri", "PUT", "", "invalidIssuer")); + } + + @Test + public void invalidUsernameContainsRegularUsernameAuthTest() throws AAIUnrecognizedFunctionException { + assertFalse(authCore.authorize("cn=blah, testUser, O=".toLowerCase(), "/aai/v0/testFunction/someUri", "PUT", "")); + } + + @Test + public void haProxyUsernameAuthTest() throws AAIUnrecognizedFunctionException { + assertTrue(authCore.authorize("ha-proxy-user".toLowerCase(), "/aai/util/echo", "GET", "")); + } + + @Test + public void haProxyUsernameInvalidFunctionAuthTest() throws AAIUnrecognizedFunctionException { + assertFalse(authCore.authorize("ha-proxy-user".toLowerCase(), "/aai/v0/testFunction/someUri", "PUT", "")); + } + + @Test + public void validUsernameViaHaProxyAuthTest() throws AAIUnrecognizedFunctionException { + assertTrue(authCore.authorize("ha-proxy-user".toLowerCase(), "/aai/v0/testFunction/someUri", "PUT", "testUser".toLowerCase())); + } + + @Test + public void validUsernameInvalidHttpMethodViaHaProxyAuthTest() throws AAIUnrecognizedFunctionException { + assertFalse(authCore.authorize("ha-proxy-user".toLowerCase(), "/aai/v0/testFunction/someUri", "POST", "testUser".toLowerCase())); + } + + @Test(expected = AAIUnrecognizedFunctionException.class) + public void validUsernameInvalidFunctionInURIViaHaProxyAuthTest() throws AAIUnrecognizedFunctionException { + authCore.authorize("ha-proxy-user".toLowerCase(), "/aai/v0/badFunction/someUri", "PUT", "testUser".toLowerCase()); + } + + @Test + public void invalidUsernameViaHaProxyAuthTest() throws AAIUnrecognizedFunctionException { + assertFalse(authCore.authorize("ha-proxy-user".toLowerCase(), "/aai/v0/testFunction/someUri", "PUT", "invlaidTestUser".toLowerCase())); + } + + @Test + public void validUsernameIsTheExactWildcardIdViaHaProxyAuthTest() throws AAIUnrecognizedFunctionException { + assertTrue(authCore.authorize("ha-proxy-user".toLowerCase(), "/aai/v0/testFunction/someUri", "PUT", "testWildcardId".toLowerCase())); + } + + @Test + public void validUsernameContainsTheWildcardIdViaHaProxyAuthTest() throws AAIUnrecognizedFunctionException { + assertTrue(authCore.authorize("ha-proxy-user".toLowerCase(), "/aai/v0/testFunction/someUri", "PUT", "cn=blah, testWildcardId, O=".toLowerCase(), "aafWildCardIssuer")); + } + + @Test + public void invalidUsernameContainsRegularUsernameViaHaProxyAuthTest() throws AAIUnrecognizedFunctionException { + assertFalse(authCore.authorize("ha-proxy-user".toLowerCase(), "/aai/v0/testFunction/someUri", "PUT", "cn=blah, testUser, O=".toLowerCase())); + } + + @Test + public void haProxyUsernameTwiceAuthTest() throws AAIUnrecognizedFunctionException { + assertFalse(authCore.authorize("ha-proxy-user".toLowerCase(), "/aai/v0/testFunction/someUri", "PUT", "ha-proxy-user".toLowerCase())); + } + + + @Test + public void haProxyWildcardIdAuthTest() throws AAIUnrecognizedFunctionException { + assertTrue(authCore.authorize("cn=blah, ha-proxy-wildcard-id, O=".toLowerCase(), "/aai/util/echo", "GET", "", "aafWildCardIssuer")); + } + + @Test + public void haProxyWildcardIdInvalidFunctionAuthTest() throws AAIUnrecognizedFunctionException { + assertFalse(authCore.authorize("cn=blah, ha-proxy-wildcard-id, O=".toLowerCase(), "/aai/v0/testFunction/someUri", "PUT", "")); + } + + @Test + public void validUsernameViaHaProxyWildcardIdAuthTest() throws AAIUnrecognizedFunctionException { + assertTrue(authCore.authorize("cn=blah, ha-proxy-wildcard-id, O=".toLowerCase(), "/aai/v0/testFunction/someUri", "PUT", "testUser".toLowerCase(), "aafWildCardIssuer")); + } + + @Test + public void validUsernameInvalidHttpMethodViaHaProxyWildcardIdAuthTest() throws AAIUnrecognizedFunctionException { + assertFalse(authCore.authorize("cn=blah, ha-proxy-wildcard-id, O=".toLowerCase(), "/aai/v0/testFunction/someUri", "POST", "testUser".toLowerCase())); + } + + @Test(expected = AAIUnrecognizedFunctionException.class) + public void validUsernameInvalidFunctionInURIViaHaProxyWildcardIdAuthTest() throws AAIUnrecognizedFunctionException { + authCore.authorize("cn=blah, ha-proxy-wildcard-id, O=".toLowerCase(), "/aai/v0/badFunction/someUri", "PUT", "testUser".toLowerCase()); + } + + @Test + public void invalidUsernameViaHaProxyWildcardIdAuthTest() throws AAIUnrecognizedFunctionException { + assertFalse(authCore.authorize("cn=blah, ha-proxy-wildcard-id, O=".toLowerCase(), "/aai/v0/testFunction/someUri", "PUT", "invlaidTestUser".toLowerCase())); + } + + @Test + public void validUsernameIsTheExactWildcardIdViaHaProxyWildcardIdAuthTest() throws AAIUnrecognizedFunctionException { + assertTrue(authCore.authorize("cn=blah, ha-proxy-wildcard-id, O=".toLowerCase(), "/aai/v0/testFunction/someUri", "PUT", "testWildcardId".toLowerCase(), "aafWildCardIssuer")); + } + + @Test + public void validUsernameContainsTheWildcardIdViaHaProxyWildcardIdAuthTest() throws AAIUnrecognizedFunctionException { + assertTrue(authCore.authorize("cn=blah, ha-proxy-wildcard-id, O=".toLowerCase(), "/aai/v0/testFunction/someUri", "PUT", "cn=blah, testWildcardId, O=".toLowerCase(), "aafWildCardIssuer")); + } + + @Test + public void validUsernameContainsTheWildcardIdViaHaProxyWildcardIdInvalidIssuerAuthTest() throws AAIUnrecognizedFunctionException { + assertFalse(authCore.authorize("cn=blah, ha-proxy-wildcard-id, O=".toLowerCase(), "/aai/v0/testFunction/someUri", "PUT", "cn=blah, testWildcardId, O=".toLowerCase(), "invalidIssuer")); + } + + @Test + public void invalidUsernameContainsRegularUsernameViaHaProxyWildcardIdAuthTest() throws AAIUnrecognizedFunctionException { + assertFalse(authCore.authorize("cn=blah, ha-proxy-wildcard-id, O=".toLowerCase(), "/aai/v0/testFunction/someUri", "PUT", "cn=blah, testUser, O=".toLowerCase())); + } } diff --git a/aai-core/src/test/java/org/onap/aai/auth/AAIUserTest.java b/aai-core/src/test/java/org/onap/aai/auth/AAIUserTest.java index 4d0e65a6..a90c7feb 100644 --- a/aai-core/src/test/java/org/onap/aai/auth/AAIUserTest.java +++ b/aai-core/src/test/java/org/onap/aai/auth/AAIUserTest.java @@ -26,28 +26,28 @@ import static org.junit.Assert.assertEquals; public class AAIUserTest extends AAISetup { - @Test - public void testIsAuth() { - AAIUser usr = new AAIUser("testUser"); - usr.addRole("testRole"); - usr.setUserAccess("auth", "GET"); - usr.setUserAccess("auth", "PUT"); - usr.setUserAccess("authentication", "PUT", "GET", "POST"); - - assertEquals(true, usr.hasAccess("auth", "GET")); - assertEquals(true, usr.hasAccess("auth", "PUT")); - assertEquals(true, usr.hasAccess("authentication", "POST")); - } - - @Test - public void testIsNotAuth() { - AAIUser usr = new AAIUser("testUser"); - usr.addRole("testRole"); - - assertEquals(false, usr.hasAccess("auth", "GET")); - - usr.setUserAccess("auth", "GET"); - assertEquals(false, usr.hasAccess("auth", "PUT")); - } + @Test + public void testIsAuth() { + AAIUser usr = new AAIUser("testUser"); + usr.addRole("testRole"); + usr.setUserAccess("auth", "GET"); + usr.setUserAccess("auth", "PUT"); + usr.setUserAccess("authentication", "PUT", "GET", "POST"); + + assertEquals(true, usr.hasAccess("auth", "GET")); + assertEquals(true, usr.hasAccess("auth", "PUT")); + assertEquals(true, usr.hasAccess("authentication", "POST")); + } + + @Test + public void testIsNotAuth() { + AAIUser usr = new AAIUser("testUser"); + usr.addRole("testRole"); + + assertEquals(false, usr.hasAccess("auth", "GET")); + + usr.setUserAccess("auth", "GET"); + assertEquals(false, usr.hasAccess("auth", "PUT")); + } } |