From a3ef648b3bf252550909dba9a8ff3d80f8f51f60 Mon Sep 17 00:00:00 2001 From: maxiaonan Date: Fri, 26 Jul 2019 11:29:35 +0800 Subject: [PATCH] =?UTF-8?q?Mod=20aaa-12=20add=20domain=20handler=20test=20?= =?UTF-8?q?and=20role=20handler=20test=20RCA=EF=BC=9A=20SOL=EF=BC=9A=20?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=BA=EF=BC=9Amaxiaonan=20=E6=A3=80?= =?UTF-8?q?=E8=A7=86=E4=BA=BA=EF=BC=9Amaxiaonan?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../idm/rest/test/DomainHandlerTest.java | 56 +++++++++++++++++-- .../shiro/idm/rest/test/RoleHandlerTest.java | 52 +++++++++++++++++ 2 files changed, 104 insertions(+), 4 deletions(-) diff --git a/ControlPlatform/aaa/aaa-shiro/impl/src/test/java/org/opendaylight/aaa/shiro/idm/rest/test/DomainHandlerTest.java b/ControlPlatform/aaa/aaa-shiro/impl/src/test/java/org/opendaylight/aaa/shiro/idm/rest/test/DomainHandlerTest.java index 1f8fc13b9..793ca1c31 100644 --- a/ControlPlatform/aaa/aaa-shiro/impl/src/test/java/org/opendaylight/aaa/shiro/idm/rest/test/DomainHandlerTest.java +++ b/ControlPlatform/aaa/aaa-shiro/impl/src/test/java/org/opendaylight/aaa/shiro/idm/rest/test/DomainHandlerTest.java @@ -37,12 +37,12 @@ public class DomainHandlerTest extends HandlerTest { Domains domains = target("/v1/domains").request().get(Domains.class); assertNotNull(domains); assertEquals(1, domains.getDomains().size()); - assertTrue(domains.getDomains().get(0).getName().equals("sdn")); + assertEquals("sdn", domains.getDomains().get(0).getName()); // check existing domain Domain domain = target("/v1/domains/0").request().get(Domain.class); assertNotNull(domain); - assertTrue(domain.getName().equals("sdn")); + assertEquals("sdn", domain.getName()); // check not exist domain try { @@ -54,19 +54,27 @@ public class DomainHandlerTest extends HandlerTest { // check create domain Map domainData = new HashMap<>(); + Response clientResponse = target("/v1/domains").request().post(entity(domainData)); + assertEquals(201, clientResponse.getStatus()); + domainData.put("name", "dom1"); domainData.put("description", "test dom"); domainData.put("enabled", "true"); - Response clientResponse = target("/v1/domains").request().post(entity(domainData)); + clientResponse = target("/v1/domains").request().post(entity(domainData)); assertEquals(201, clientResponse.getStatus()); + // check update domain data domainData.put("name", "dom1Update"); clientResponse = target("/v1/domains/1").request().put(entity(domainData)); assertEquals(200, clientResponse.getStatus()); + + clientResponse = target("/v1/domains/101").request().put(entity(domainData)); + assertEquals(404, clientResponse.getStatus()); + domain = target("/v1/domains/1").request().get(Domain.class); assertNotNull(domain); - assertTrue(domain.getName().equals("dom1Update")); + assertEquals("dom1Update", domain.getName()); // check create grant Map grantData = new HashMap<>(); @@ -74,6 +82,18 @@ public class DomainHandlerTest extends HandlerTest { clientResponse = target("/v1/domains/1/users/0/roles").request().post(entity(grantData)); assertEquals(201, clientResponse.getStatus()); + clientResponse = target("/v1/domains/1/users/100/roles").request().post(entity(grantData)); + assertEquals(404, clientResponse.getStatus()); + + grantData.put("roleid", "10ywre"); + clientResponse = target("/v1/domains/1/users/0/roles").request().post(entity(grantData)); + assertEquals(404, clientResponse.getStatus()); + + grantData.put("roleid", "52"); + clientResponse = target("/v1/domains/1/users/0/roles").request().post(entity(grantData)); + assertEquals(404, clientResponse.getStatus()); + + grantData.put("roleid", "1"); // check create existing grant clientResponse = target("/v1/domains/1/users/0/roles").request().post(entity(grantData)); assertEquals(403, clientResponse.getStatus()); @@ -96,6 +116,28 @@ public class DomainHandlerTest extends HandlerTest { clientResponse = target("/v1/domains/0/users/roles").request().post(entity(usrPwdData)); assertEquals(200, clientResponse.getStatus()); + //check domain is null + clientResponse = target("/v1/domains/12/users/roles").request().post(entity(usrPwdData)); + assertEquals(404, clientResponse.getStatus()); + + //check user pwd with null parameter + //check domain is null + usrPwdData.remove("username"); + clientResponse = target("/v1/domains/0/users/roles").request().post(entity(usrPwdData)); + assertEquals(400, clientResponse.getStatus()); + usrPwdData.put("username", "admin"); + + usrPwdData.remove("userpwd"); + clientResponse = target("/v1/domains/0/users/roles").request().post(entity(usrPwdData)); + assertEquals(400, clientResponse.getStatus()); + usrPwdData.put("userpwd", "admin"); + + //check user is null + usrPwdData.put("username","12321421"); + clientResponse = target("/v1/domains/0/users/roles").request().post(entity(usrPwdData)); + assertEquals(404, clientResponse.getStatus()); + usrPwdData.put("username", "admin"); + // check validate user (admin) with wrong password usrPwdData.put("userpwd", "1234"); clientResponse = target("/v1/domains/0/users/roles").request().post(entity(usrPwdData)); @@ -114,6 +156,12 @@ public class DomainHandlerTest extends HandlerTest { // expected } + try { + target("/v1/domains/19/users/0/roles").request().get(IDMError.class); + fail("Should fail with 404!"); + } catch (NotFoundException e) { + // expected + } // check delete grant clientResponse = target("/v1/domains/0/users/0/roles/0").request().delete(); assertEquals(204, clientResponse.getStatus()); diff --git a/ControlPlatform/aaa/aaa-shiro/impl/src/test/java/org/opendaylight/aaa/shiro/idm/rest/test/RoleHandlerTest.java b/ControlPlatform/aaa/aaa-shiro/impl/src/test/java/org/opendaylight/aaa/shiro/idm/rest/test/RoleHandlerTest.java index 295958fae..7acb748a7 100644 --- a/ControlPlatform/aaa/aaa-shiro/impl/src/test/java/org/opendaylight/aaa/shiro/idm/rest/test/RoleHandlerTest.java +++ b/ControlPlatform/aaa/aaa-shiro/impl/src/test/java/org/opendaylight/aaa/shiro/idm/rest/test/RoleHandlerTest.java @@ -69,9 +69,32 @@ public class RoleHandlerTest extends HandlerTest { try { clientResponse = target("/v1/roles").request().post(entity(roleData)); assertEquals(404, clientResponse.getStatus()); + roleData.put("name", getMaxLengthName()); + target("/v1/roles").request().post(entity(roleData)); } catch (WebApplicationException e) { assertEquals(500, e.getResponse().getStatus()); } + roleData.put("name", "role1"); + //POST ERROR + roleData.remove("domainid"); + try { + clientResponse = target("/v1/roles").request().post(entity(roleData)); + assertEquals(404, clientResponse.getStatus()); + roleData.put("domainid", getMaxLengthName()); + target("/v1/roles").request().post(entity(roleData)); + } catch (WebApplicationException e) { + assertEquals(500, e.getResponse().getStatus()); + } + roleData.put("domainid", "0"); + roleData.remove("description"); + try { + target("/v1/roles").request().post(entity(roleData)); + roleData.put("description", getMaxLengthName()); + target("/v1/roles").request().post(entity(roleData)); + } catch (WebApplicationException e) { + assertEquals(500, e.getResponse().getStatus()); + } + roleData.put("description", "test Role"); // check update Role data roleData.put("name", "role1Update"); @@ -81,6 +104,25 @@ public class RoleHandlerTest extends HandlerTest { assertNotNull(role); assertTrue(role.getName().equals("role1Update")); + //PUT Error + roleData.put("name", getMaxLengthName()); + clientResponse = target("/v1/roles/2").request().put(entity(roleData)); + assertEquals(400, clientResponse.getStatus()); + roleData.put("name", "role1Update"); + + roleData.put("description", getMaxLengthName()); + clientResponse = target("/v1/roles/2").request().put(entity(roleData)); + assertEquals(400, clientResponse.getStatus()); + roleData.put("description", "test Role"); + + HashMap newRole = new HashMap<>(); + newRole.put("name", "role1Update"); + newRole.put("domainid", "0"); + newRole.put("description", "test Role"); + clientResponse = target("/v1/roles/111111").request().put(entity(newRole)); + assertEquals(404, clientResponse.getStatus()); + + // check delete Role clientResponse = target("/v1/roles/2").request().delete(); assertEquals(204, clientResponse.getStatus()); @@ -102,6 +144,16 @@ public class RoleHandlerTest extends HandlerTest { clientResponse = target("/v1/roles").request().post(entity(roleData)); assertEquals(400, clientResponse.getStatus()); } + + private String getMaxLengthName() { + return "abcdefg1234567890vbnabcdefg1234567890vbn" + + "abcdefg1234567890vbnabcdefg1234567890vbn" + + "abcdefg1234567890vbnabcdefg1234567890vbn" + + "abcdefg1234567890vbnabcdefg1234567890vbn" + + "abcdefg1234567890vbnabcdefg1234567890vbn" + + "abcdefg1234567890vbnabcdefg1234567890vbn" + + "abcdefg1234567890vbnabcdefg1234567890vbn"; + } } /** * Revision history