aboutsummaryrefslogtreecommitdiffstats
path: root/controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/integration/user/RolesTest.java
blob: 9e128a17c13768108f154c9c51d1e3515d3c803d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.controller.api.integration.user;

import com.yahoo.config.provision.ApplicationName;
import com.yahoo.config.provision.TenantName;
import com.yahoo.vespa.hosted.controller.api.role.ApplicationRole;
import com.yahoo.vespa.hosted.controller.api.role.Role;
import com.yahoo.vespa.hosted.controller.api.role.TenantRole;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

/**
 * @author jonmv
 */
public class RolesTest {

    @Test
    public void testSerialization() {
        TenantName tenant = TenantName.from("my-tenant");
        for (TenantRole role : Roles.tenantRoles(tenant))
            assertEquals(role, Roles.toRole(Roles.valueOf(role)));

        ApplicationName application = ApplicationName.from("my-application");
        for (ApplicationRole role : Roles.applicationRoles(tenant, application))
            assertEquals(role, Roles.toRole(Roles.valueOf(role)));

        assertEquals(Role.hostedOperator(),
                     Roles.toRole("hostedOperator"));
        assertEquals(Role.hostedSupporter(),
                     Roles.toRole("hostedSupporter"));
        assertEquals(Role.administrator(tenant), Roles.toRole("my-tenant.administrator"));
        assertEquals(Role.developer(tenant), Roles.toRole("my-tenant.developer"));
        assertEquals(Role.reader(tenant), Roles.toRole("my-tenant.reader"));
        assertEquals(Role.headless(tenant, application), Roles.toRole("my-tenant.my-application.headless"));
    }

    @Test(expected = IllegalArgumentException.class)
    public void illegalTenantName() {
        Roles.valueOf(Role.developer(TenantName.from("my.tenant")));
    }

    @Test(expected = IllegalArgumentException.class)
    public void illegalApplicationName() {
        Roles.valueOf(Role.headless(TenantName.from("my-tenant"), ApplicationName.from("my.app")));
    }

    @Test(expected = IllegalArgumentException.class)
    public void illegalRoleValue() {
        Roles.toRole("my-tenant.awesomePerson");
    }

    @Test(expected = IllegalArgumentException.class)
    public void illegalCombination() {
        Roles.toRole("my-tenant.my-application.tenantOwner");
    }

    @Test(expected = IllegalArgumentException.class)
    public void illegalValue() {
        Roles.toRole("everyone");
    }

}