aboutsummaryrefslogtreecommitdiffstats
path: root/controller-api/src/test/java
diff options
context:
space:
mode:
authorJon Marius Venstad <venstad@gmail.com>2019-04-04 16:54:27 +0200
committerJon Marius Venstad <venstad@gmail.com>2019-04-04 16:54:27 +0200
commit80c249f94ade782c3b1f2dd2781f089d1245f34a (patch)
treea46657d3740b8dc06c3af0a2ba15e17cf84a833c /controller-api/src/test/java
parentf83e2033db821695a7984577a1ee18c617fc0b55 (diff)
Add ID classes and interface for user management
Diffstat (limited to 'controller-api/src/test/java')
-rw-r--r--controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/integration/user/GroupIdTest.java74
1 files changed, 74 insertions, 0 deletions
diff --git a/controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/integration/user/GroupIdTest.java b/controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/integration/user/GroupIdTest.java
new file mode 100644
index 00000000000..acb9b3b245b
--- /dev/null
+++ b/controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/integration/user/GroupIdTest.java
@@ -0,0 +1,74 @@
+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 GroupIdTest {
+
+ @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, GroupId.fromRole(role).toRole(roles));
+
+ ApplicationName application = ApplicationName.from("my-application");
+ for (ApplicationRole role : List.of(roles.applicationOwner(tenant, application),
+ roles.applicationAdmin(tenant, application),
+ roles.applicationOperator(tenant, application),
+ roles.applicationDeveloper(tenant, application),
+ roles.applicationReader(tenant, application)))
+ assertEquals(role, GroupId.fromRole(role).toRole(roles));
+
+ assertEquals(roles.tenantOperator(tenant),
+ GroupId.fromValue("my-tenant.tenantOperator").toRole(roles));
+ assertEquals(roles.applicationReader(tenant, application),
+ GroupId.fromValue("my-tenant.my-application.applicationReader").toRole(roles));
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void illegalTenantName() {
+ GroupId.fromRole(new Roles(SystemName.main).tenantAdmin(TenantName.from("my.tenant")));
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void illegalApplicationName() {
+ GroupId.fromRole(new Roles(SystemName.main).applicationOperator(TenantName.from("my-tenant"), ApplicationName.from("my.app")));
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void illegalRole() {
+ GroupId.fromRole(new Roles(SystemName.main).tenantPipeline(TenantName.from("my-tenant"), ApplicationName.from("my-app")));
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void illegalRoleValue() {
+ GroupId.fromValue("my-tenant.awesomePerson").toRole(new Roles(SystemName.cd));
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void illegalCombination() {
+ GroupId.fromValue("my-tenant.my-application.tenantOwner").toRole(new Roles(SystemName.cd));
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void illegalValue() {
+ GroupId.fromValue("hostedOperator").toRole(new Roles(SystemName.Public));
+ }
+
+}