aboutsummaryrefslogtreecommitdiffstats
path: root/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/athenz/AthenzApiTest.java
blob: 3a53998744315a1cb542f12020e75c3c17ce97e8 (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.controller.restapi.athenz;

import com.yahoo.application.container.handler.Request;
import com.yahoo.config.provision.ApplicationId;
import com.yahoo.vespa.athenz.api.AthenzDomain;
import com.yahoo.vespa.hosted.controller.ControllerTester;
import com.yahoo.vespa.hosted.controller.restapi.ContainerTester;
import com.yahoo.vespa.hosted.controller.restapi.ControllerContainerTest;
import org.junit.jupiter.api.Test;

import java.io.File;

/**
 * @author jonmv
 */
public class AthenzApiTest extends ControllerContainerTest {

    private static final String responseFiles = "src/test/java/com/yahoo/vespa/hosted/controller/restapi/athenz/responses/";

    @Test
    void testAthenzApi() {
        ContainerTester tester = new ContainerTester(container, responseFiles);
        ControllerTester controllerTester = new ControllerTester(tester);

        controllerTester.createTenant("sandbox", AthenzApiHandler.sandboxDomainIn(tester.controller().system()), 123L);
        controllerTester.createApplication("sandbox", "app", "default");
        tester.controller().applications().createInstance(ApplicationId.from("sandbox", "app", hostedOperator.getName()));
        tester.controller().applications().createInstance(ApplicationId.from("sandbox", "app", defaultUser.getName()));
        controllerTester.createApplication("sandbox", "opp", "default");

        controllerTester.createTenant("tenant1", "domain1", 123L);
        controllerTester.createApplication("tenant1", "app", "default");
        tester.athenzClientFactory().getSetup().getOrCreateDomain(new AthenzDomain("domain1")).admin(defaultUser);

        controllerTester.createTenant("tenant2", "domain2", 123L);
        controllerTester.createApplication("tenant2", "app", "default");

        // GET root
        tester.assertResponse(authenticatedRequest("http://localhost:8080/athenz/v1/"),
                new File("root.json"));

        // GET Athenz domains
        tester.assertResponse(authenticatedRequest("http://localhost:8080/athenz/v1/domains"),
                new File("athensDomain-list.json"));

        // GET properties
        tester.assertResponse(authenticatedRequest("http://localhost:8080/athenz/v1/properties/"),
                new File("property-list.json"));

        // POST user signup
        tester.assertResponse(authenticatedRequest("http://localhost:8080/athenz/v1/user", "", Request.Method.POST),
                "{\"message\":\"User 'bob' added to admin role of 'vespa.vespa.tenants.sandbox'\"}");
    }

}