Search in sources :

Example 1 with ControllerTester

use of com.yahoo.vespa.hosted.controller.ControllerTester in project vespa by vespa-engine.

the class ControllerAuthorizationFilterTest method white_listed_operations_are_allowed.

@Test
public void white_listed_operations_are_allowed() {
    ControllerAuthorizationFilter filter = createFilter(new ControllerTester());
    assertIsAllowed(invokeFilter(filter, createRequest(PUT, "/application/v4/user", USER)));
    assertIsAllowed(invokeFilter(filter, createRequest(POST, "/application/v4/tenant/john", USER)));
}
Also used : ControllerTester(com.yahoo.vespa.hosted.controller.ControllerTester) Test(org.junit.Test)

Example 2 with ControllerTester

use of com.yahoo.vespa.hosted.controller.ControllerTester in project vespa by vespa-engine.

the class ControllerAuthorizationFilterTest method only_hosted_operator_and_screwdriver_project_with_deploy_role_can_access_tenant_pipeline_apis.

@Test
public void only_hosted_operator_and_screwdriver_project_with_deploy_role_can_access_tenant_pipeline_apis() {
    ControllerTester controllerTester = new ControllerTester();
    controllerTester.athenzDb().hostedOperators.add(HOSTED_OPERATOR);
    controllerTester.createTenant(TENANT.id(), TENANT_DOMAIN.getName(), null);
    controllerTester.createApplication(TENANT, APPLICATION.id(), "default", 12345);
    AthenzDbMock.Domain domainMock = controllerTester.athenzDb().domains.get(TENANT_DOMAIN);
    domainMock.admins.add(TENANT_ADMIN);
    domainMock.applications.get(APPLICATION).addRoleMember(ApplicationAction.deploy, TENANT_PIPELINE);
    ControllerAuthorizationFilter filter = createFilter(controllerTester);
    List<AthenzIdentity> allowed = asList(HOSTED_OPERATOR, TENANT_PIPELINE);
    List<AthenzIdentity> forbidden = asList(TENANT_ADMIN, USER);
    testApiAccess(POST, "/application/v4/tenant/mytenant/application/myapp/environment/prod/region/myregion/instance/default/deploy", allowed, forbidden, filter);
    testApiAccess(POST, "/application/v4/tenant/mytenant/application/myapp/jobreport", allowed, forbidden, filter);
    testApiAccess(POST, "/application/v4/tenant/mytenant/application/myapp/promote", allowed, forbidden, filter);
}
Also used : AthenzIdentity(com.yahoo.vespa.athenz.api.AthenzIdentity) AthenzDbMock(com.yahoo.vespa.hosted.controller.athenz.mock.AthenzDbMock) ControllerTester(com.yahoo.vespa.hosted.controller.ControllerTester) Test(org.junit.Test)

Example 3 with ControllerTester

use of com.yahoo.vespa.hosted.controller.ControllerTester in project vespa by vespa-engine.

the class ControllerAuthorizationFilterTest method only_hosted_operator_can_access_operator_apis.

@Test
public void only_hosted_operator_can_access_operator_apis() {
    ControllerTester controllerTester = new ControllerTester();
    controllerTester.athenzDb().hostedOperators.add(HOSTED_OPERATOR);
    ControllerAuthorizationFilter filter = createFilter(controllerTester);
    List<AthenzIdentity> allowed = singletonList(HOSTED_OPERATOR);
    List<AthenzIdentity> forbidden = singletonList(USER);
    testApiAccess(PUT, "/application/v4/tenant/mytenant/application/myapp/deploying", allowed, forbidden, filter);
    testApiAccess(POST, "/screwdriver/v1/trigger/tenant/mytenant/application/myapp/", allowed, forbidden, filter);
    testApiAccess(DELETE, "/provision/v2/provision/enqueue", allowed, forbidden, filter);
}
Also used : AthenzIdentity(com.yahoo.vespa.athenz.api.AthenzIdentity) ControllerTester(com.yahoo.vespa.hosted.controller.ControllerTester) Test(org.junit.Test)

Example 4 with ControllerTester

use of com.yahoo.vespa.hosted.controller.ControllerTester in project vespa by vespa-engine.

the class MetricsReporterTest method test_chef_metrics.

@Test
public void test_chef_metrics() {
    Clock clock = Clock.fixed(Instant.ofEpochSecond(1475497913), ZoneId.systemDefault());
    ;
    ControllerTester tester = new ControllerTester();
    MetricsReporter metricsReporter = createReporter(clock, tester.controller(), metrics, SystemName.cd);
    metricsReporter.maintain();
    assertEquals(2, metrics.getMetrics().size());
    Map<MapContext, Map<String, Number>> hostMetrics = getMetricsByHost("fake-node.test");
    assertEquals(1, hostMetrics.size());
    Map.Entry<MapContext, Map<String, Number>> metricEntry = hostMetrics.entrySet().iterator().next();
    MapContext metricContext = metricEntry.getKey();
    assertDimension(metricContext, "tenantName", "ciintegrationtests");
    assertDimension(metricContext, "app", "restart.default");
    assertDimension(metricContext, "zone", "prod.cd-us-east-1");
    assertEquals(727, metricEntry.getValue().get(MetricsReporter.convergeMetric).longValue());
}
Also used : MapContext(com.yahoo.vespa.hosted.controller.MetricsMock.MapContext) Clock(java.time.Clock) Map(java.util.Map) ControllerTester(com.yahoo.vespa.hosted.controller.ControllerTester) JobType.systemTest(com.yahoo.vespa.hosted.controller.application.DeploymentJobs.JobType.systemTest) Test(org.junit.Test) JobType.stagingTest(com.yahoo.vespa.hosted.controller.application.DeploymentJobs.JobType.stagingTest)

Example 5 with ControllerTester

use of com.yahoo.vespa.hosted.controller.ControllerTester in project vespa by vespa-engine.

the class MetricsReporterTest method it_omits_zone_when_unknown.

@Test
public void it_omits_zone_when_unknown() {
    ControllerTester tester = new ControllerTester();
    String hostname = "fake-node2.test";
    MapContext metricContext = getMetricContextByHost(tester.controller(), hostname);
    assertNull(metricContext.getDimensions().get("zone"));
}
Also used : Matchers.anyString(org.mockito.Matchers.anyString) MapContext(com.yahoo.vespa.hosted.controller.MetricsMock.MapContext) ControllerTester(com.yahoo.vespa.hosted.controller.ControllerTester) JobType.systemTest(com.yahoo.vespa.hosted.controller.application.DeploymentJobs.JobType.systemTest) Test(org.junit.Test) JobType.stagingTest(com.yahoo.vespa.hosted.controller.application.DeploymentJobs.JobType.stagingTest)

Aggregations

ControllerTester (com.yahoo.vespa.hosted.controller.ControllerTester)20 Test (org.junit.Test)19 JobType.stagingTest (com.yahoo.vespa.hosted.controller.application.DeploymentJobs.JobType.stagingTest)8 JobType.systemTest (com.yahoo.vespa.hosted.controller.application.DeploymentJobs.JobType.systemTest)8 Application (com.yahoo.vespa.hosted.controller.Application)7 Version (com.yahoo.component.Version)6 Deployment (com.yahoo.vespa.hosted.controller.application.Deployment)5 DeploymentTester (com.yahoo.vespa.hosted.controller.deployment.DeploymentTester)5 MockCuratorDb (com.yahoo.vespa.hosted.controller.persistence.MockCuratorDb)5 ManualClock (com.yahoo.test.ManualClock)4 ApplicationPackage (com.yahoo.vespa.hosted.controller.application.ApplicationPackage)4 ApplicationId (com.yahoo.config.provision.ApplicationId)3 AthenzIdentity (com.yahoo.vespa.athenz.api.AthenzIdentity)3 ApplicationPackageBuilder (com.yahoo.vespa.hosted.controller.deployment.ApplicationPackageBuilder)3 VespaVersion (com.yahoo.vespa.hosted.controller.versions.VespaVersion)3 MapContext (com.yahoo.vespa.hosted.controller.MetricsMock.MapContext)2 ApplicationVersion (com.yahoo.vespa.hosted.controller.application.ApplicationVersion)2 SourceRevision (com.yahoo.vespa.hosted.controller.application.SourceRevision)2 DeploymentSpec (com.yahoo.config.application.api.DeploymentSpec)1 ValidationOverrides (com.yahoo.config.application.api.ValidationOverrides)1