diff options
author | Jon Marius Venstad <jvenstad@yahoo-inc.com> | 2019-04-08 13:17:17 +0200 |
---|---|---|
committer | Jon Marius Venstad <jvenstad@yahoo-inc.com> | 2019-04-08 13:17:17 +0200 |
commit | d20554f9341d14377b04fba3e9cd2f25248dff48 (patch) | |
tree | 67b7c1c5aed730fd838584b9591a85168d0e2dfd /controller-api/src/test | |
parent | 3c10a252ede1b26536bfff714951171ae4ace3d1 (diff) |
Remove RoleId and move serialisation etc to UserRoles
Diffstat (limited to 'controller-api/src/test')
2 files changed, 67 insertions, 73 deletions
diff --git a/controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/integration/user/RoleIdTest.java b/controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/integration/user/RoleIdTest.java deleted file mode 100644 index 12adcbbae89..00000000000 --- a/controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/integration/user/RoleIdTest.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.yahoo.vespa.hosted.controller.api.integration.user; - -import com.yahoo.config.provision.ApplicationName; -import com.yahoo.config.provision.SystemName; -import com.yahoo.config.provision.TenantName; -import com.yahoo.vespa.hosted.controller.api.role.ApplicationRole; -import com.yahoo.vespa.hosted.controller.api.role.Roles; -import com.yahoo.vespa.hosted.controller.api.role.TenantRole; -import org.junit.Test; - -import java.util.List; - -import static org.junit.Assert.assertEquals; - -/** - * @author jonmv - */ -public class RoleIdTest { - - @Test - public void testSerialization() { - Roles roles = new Roles(SystemName.main); - - TenantName tenant = TenantName.from("my-tenant"); - for (TenantRole role : List.of(roles.tenantOwner(tenant), - roles.tenantAdmin(tenant), - roles.tenantOperator(tenant))) - assertEquals(role, RoleId.fromRole(role).toRole(roles)); - - ApplicationName application = ApplicationName.from("my-application"); - for (ApplicationRole role : List.of(roles.applicationAdmin(tenant, application), - roles.applicationOperator(tenant, application), - roles.applicationDeveloper(tenant, application), - roles.applicationReader(tenant, application))) - assertEquals(role, RoleId.fromRole(role).toRole(roles)); - - assertEquals(roles.tenantOperator(tenant), - RoleId.fromValue("my-tenant.tenantOperator").toRole(roles)); - assertEquals(roles.applicationReader(tenant, application), - RoleId.fromValue("my-tenant.my-application.applicationReader").toRole(roles)); - } - - @Test(expected = IllegalArgumentException.class) - public void illegalTenantName() { - RoleId.fromRole(new Roles(SystemName.main).tenantAdmin(TenantName.from("my.tenant"))); - } - - @Test(expected = IllegalArgumentException.class) - public void illegalApplicationName() { - RoleId.fromRole(new Roles(SystemName.main).applicationOperator(TenantName.from("my-tenant"), ApplicationName.from("my.app"))); - } - - @Test(expected = IllegalArgumentException.class) - public void illegalRole() { - RoleId.fromRole(new Roles(SystemName.main).tenantPipeline(TenantName.from("my-tenant"), ApplicationName.from("my-app"))); - } - - @Test(expected = IllegalArgumentException.class) - public void illegalRoleValue() { - RoleId.fromValue("my-tenant.awesomePerson").toRole(new Roles(SystemName.cd)); - } - - @Test(expected = IllegalArgumentException.class) - public void illegalCombination() { - RoleId.fromValue("my-tenant.my-application.tenantOwner").toRole(new Roles(SystemName.cd)); - } - - @Test(expected = IllegalArgumentException.class) - public void illegalValue() { - RoleId.fromValue("hostedOperator").toRole(new Roles(SystemName.Public)); - } - -} diff --git a/controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/integration/user/UserRolesTest.java b/controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/integration/user/UserRolesTest.java new file mode 100644 index 00000000000..262245a3366 --- /dev/null +++ b/controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/integration/user/UserRolesTest.java @@ -0,0 +1,67 @@ +package com.yahoo.vespa.hosted.controller.api.integration.user; + +import com.yahoo.config.provision.ApplicationName; +import com.yahoo.config.provision.SystemName; +import com.yahoo.config.provision.TenantName; +import com.yahoo.vespa.hosted.controller.api.role.ApplicationRole; +import com.yahoo.vespa.hosted.controller.api.role.Roles; +import com.yahoo.vespa.hosted.controller.api.role.TenantRole; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +/** + * @author jonmv + */ +public class UserRolesTest { + + private static final Roles roles = new Roles(SystemName.main); + private static final UserRoles userRoles = new UserRoles(roles); + + @Test + public void testSerialization() { + TenantName tenant = TenantName.from("my-tenant"); + for (TenantRole role : userRoles.tenantRoles(tenant)) + assertEquals(role, userRoles.toRole(UserRoles.valueOf(role))); + + ApplicationName application = ApplicationName.from("my-application"); + for (ApplicationRole role : userRoles.applicationRoles(tenant, application)) + assertEquals(role, userRoles.toRole(UserRoles.valueOf(role))); + + assertEquals(roles.tenantOperator(tenant), + userRoles.toRole("my-tenant.tenantOperator")); + assertEquals(roles.applicationReader(tenant, application), + userRoles.toRole("my-tenant.my-application.applicationReader")); + } + + @Test(expected = IllegalArgumentException.class) + public void illegalTenantName() { + UserRoles.valueOf(roles.tenantAdmin(TenantName.from("my.tenant"))); + } + + @Test(expected = IllegalArgumentException.class) + public void illegalApplicationName() { + UserRoles.valueOf(roles.applicationOperator(TenantName.from("my-tenant"), ApplicationName.from("my.app"))); + } + + @Test(expected = IllegalArgumentException.class) + public void illegalRole() { + UserRoles.valueOf(roles.tenantPipeline(TenantName.from("my-tenant"), ApplicationName.from("my-app"))); + } + + @Test(expected = IllegalArgumentException.class) + public void illegalRoleValue() { + userRoles.toRole("my-tenant.awesomePerson"); + } + + @Test(expected = IllegalArgumentException.class) + public void illegalCombination() { + userRoles.toRole("my-tenant.my-application.tenantOwner"); + } + + @Test(expected = IllegalArgumentException.class) + public void illegalValue() { + userRoles.toRole("hostedOperator"); + } + +} |