Search in sources :

Example 1 with DomainMetaStore

use of com.yahoo.athenz.common.server.metastore.DomainMetaStore in project athenz by yahoo.

the class ZMSImplTest method testPutDomainSystemMetaInvalidDomainMetaStoreValues.

@Test
public void testPutDomainSystemMetaInvalidDomainMetaStoreValues() {
    final String domainName = "athenz-domain-system-meta-with-invalid-details";
    DomainMetaStore savedMetaStore = zmsTestInitializer.getZms().domainMetaStore;
    zmsTestInitializer.getZms().domainMetaStore = new TestDomainMetaStore();
    TopLevelDomain dom1 = zmsTestInitializer.createTopLevelDomainObject(domainName, "Test Domain1", "testOrg", zmsTestInitializer.getAdminUser());
    zmsTestInitializer.getZms().postTopLevelDomain(zmsTestInitializer.getMockDomRsrcCtx(), zmsTestInitializer.getAuditRef(), dom1);
    // first aws account
    DomainMeta meta = new DomainMeta().setAccount("invalid-aws-account");
    try {
        zmsTestInitializer.getZms().putDomainSystemMeta(zmsTestInitializer.getMockDomRsrcCtx(), domainName, ZMSConsts.SYSTEM_META_ACCOUNT, zmsTestInitializer.getAuditRef(), meta);
        fail();
    } catch (ResourceException ex) {
        assertTrue(ex.getMessage().contains("invalid aws account"));
    }
    meta.setAccount("valid-aws-account");
    zmsTestInitializer.getZms().putDomainSystemMeta(zmsTestInitializer.getMockDomRsrcCtx(), domainName, ZMSConsts.SYSTEM_META_ACCOUNT, zmsTestInitializer.getAuditRef(), meta);
    Domain domain = zmsTestInitializer.getZms().getDomain(zmsTestInitializer.getMockDomRsrcCtx(), domainName);
    assertNotNull(domain);
    assertEquals(domain.getAccount(), "valid-aws-account");
    // second time no-op since nothing has changed
    zmsTestInitializer.getZms().putDomainSystemMeta(zmsTestInitializer.getMockDomRsrcCtx(), domainName, ZMSConsts.SYSTEM_META_ACCOUNT, zmsTestInitializer.getAuditRef(), meta);
    try {
        meta.setAzureSubscription("invalid-azure-subscription");
        zmsTestInitializer.getZms().putDomainSystemMeta(zmsTestInitializer.getMockDomRsrcCtx(), domainName, ZMSConsts.SYSTEM_META_AZURE_SUBSCRIPTION, zmsTestInitializer.getAuditRef(), meta);
        fail();
    } catch (ResourceException ex) {
        assertTrue(ex.getMessage().contains("invalid azure subscription"));
    }
    meta.setAzureSubscription("valid-azure-subscription");
    zmsTestInitializer.getZms().putDomainSystemMeta(zmsTestInitializer.getMockDomRsrcCtx(), domainName, ZMSConsts.SYSTEM_META_AZURE_SUBSCRIPTION, zmsTestInitializer.getAuditRef(), meta);
    domain = zmsTestInitializer.getZms().getDomain(zmsTestInitializer.getMockDomRsrcCtx(), domainName);
    assertNotNull(domain);
    assertEquals(domain.getAzureSubscription(), "valid-azure-subscription");
    // second time no-op since nothing has changed
    zmsTestInitializer.getZms().putDomainSystemMeta(zmsTestInitializer.getMockDomRsrcCtx(), domainName, ZMSConsts.SYSTEM_META_AZURE_SUBSCRIPTION, zmsTestInitializer.getAuditRef(), meta);
    // next product id
    zmsTestInitializer.getZms().productIdSupport = true;
    try {
        meta.setYpmId(100);
        zmsTestInitializer.getZms().putDomainSystemMeta(zmsTestInitializer.getMockDomRsrcCtx(), domainName, ZMSConsts.SYSTEM_META_PRODUCT_ID, zmsTestInitializer.getAuditRef(), meta);
        fail();
    } catch (ResourceException ex) {
        assertTrue(ex.getMessage().contains("invalid product id"));
    }
    meta.setYpmId(101);
    zmsTestInitializer.getZms().putDomainSystemMeta(zmsTestInitializer.getMockDomRsrcCtx(), domainName, ZMSConsts.SYSTEM_META_PRODUCT_ID, zmsTestInitializer.getAuditRef(), meta);
    domain = zmsTestInitializer.getZms().getDomain(zmsTestInitializer.getMockDomRsrcCtx(), domainName);
    assertNotNull(domain);
    assertEquals(domain.getYpmId().intValue(), 101);
    try {
        meta.setBusinessService("invalid-business-service");
        zmsTestInitializer.getZms().putDomainSystemMeta(zmsTestInitializer.getMockDomRsrcCtx(), domainName, ZMSConsts.SYSTEM_META_BUSINESS_SERVICE, zmsTestInitializer.getAuditRef(), meta);
        fail();
    } catch (ResourceException ex) {
        assertTrue(ex.getMessage().contains("invalid business service"));
    }
    meta.setBusinessService("valid-business-service");
    zmsTestInitializer.getZms().putDomainSystemMeta(zmsTestInitializer.getMockDomRsrcCtx(), domainName, ZMSConsts.SYSTEM_META_BUSINESS_SERVICE, zmsTestInitializer.getAuditRef(), meta);
    domain = zmsTestInitializer.getZms().getDomain(zmsTestInitializer.getMockDomRsrcCtx(), domainName);
    assertNotNull(domain);
    assertEquals(domain.getBusinessService(), "valid-business-service");
    // second time no-op since nothing has changed
    zmsTestInitializer.getZms().putDomainSystemMeta(zmsTestInitializer.getMockDomRsrcCtx(), domainName, ZMSConsts.SYSTEM_META_BUSINESS_SERVICE, zmsTestInitializer.getAuditRef(), meta);
    zmsTestInitializer.getZms().deleteTopLevelDomain(zmsTestInitializer.getMockDomRsrcCtx(), domainName, zmsTestInitializer.getAuditRef());
    zmsTestInitializer.getZms().domainMetaStore = savedMetaStore;
    zmsTestInitializer.getZms().productIdSupport = false;
}
Also used : AthenzDomain(com.yahoo.athenz.zms.store.AthenzDomain) DomainMetaStore(com.yahoo.athenz.common.server.metastore.DomainMetaStore)

Example 2 with DomainMetaStore

use of com.yahoo.athenz.common.server.metastore.DomainMetaStore in project athenz by yahoo.

the class ZMSImplTest method testPutDomainMetaInvalidDomainMetaStoreValues.

@Test
public void testPutDomainMetaInvalidDomainMetaStoreValues() {
    final String domainName = "athenz-domain-meta-with-invalid-details";
    DomainMetaStore savedMetaStore = zmsTestInitializer.getZms().domainMetaStore;
    zmsTestInitializer.getZms().domainMetaStore = new TestDomainMetaStore();
    TopLevelDomain dom1 = zmsTestInitializer.createTopLevelDomainObject(domainName, "Test Domain1", "testOrg", zmsTestInitializer.getAdminUser());
    zmsTestInitializer.getZms().postTopLevelDomain(zmsTestInitializer.getMockDomRsrcCtx(), zmsTestInitializer.getAuditRef(), dom1);
    DomainMeta meta = new DomainMeta().setBusinessService("invalid-business-service");
    try {
        zmsTestInitializer.getZms().putDomainMeta(zmsTestInitializer.getMockDomRsrcCtx(), domainName, zmsTestInitializer.getAuditRef(), meta);
        fail();
    } catch (ResourceException ex) {
        assertTrue(ex.getMessage().contains("invalid business service name"));
    }
    meta.setBusinessService("valid-business-service");
    zmsTestInitializer.getZms().putDomainMeta(zmsTestInitializer.getMockDomRsrcCtx(), domainName, zmsTestInitializer.getAuditRef(), meta);
    // second time no-op since value not changed
    zmsTestInitializer.getZms().putDomainMeta(zmsTestInitializer.getMockDomRsrcCtx(), domainName, zmsTestInitializer.getAuditRef(), meta);
    Domain domain = zmsTestInitializer.getZms().getDomain(zmsTestInitializer.getMockDomRsrcCtx(), domainName);
    assertNotNull(domain);
    assertEquals(domain.getBusinessService(), "valid-business-service");
    zmsTestInitializer.getZms().deleteTopLevelDomain(zmsTestInitializer.getMockDomRsrcCtx(), domainName, zmsTestInitializer.getAuditRef());
    zmsTestInitializer.getZms().domainMetaStore = savedMetaStore;
}
Also used : AthenzDomain(com.yahoo.athenz.zms.store.AthenzDomain) DomainMetaStore(com.yahoo.athenz.common.server.metastore.DomainMetaStore)

Example 3 with DomainMetaStore

use of com.yahoo.athenz.common.server.metastore.DomainMetaStore in project athenz by yahoo.

the class ZMSImplTest method testGetDomainMetaStoreValidValuesUsernameLowered.

@Test
public void testGetDomainMetaStoreValidValuesUsernameLowered() {
    DomainMetaStore savedMetaStore = zmsTestInitializer.getZms().domainMetaStore;
    DomainMetaStore mockDomainMetaStore = Mockito.mock(DomainMetaStore.class);
    List<String> businessServicesList = Collections.singletonList("bservice");
    when(mockDomainMetaStore.getValidBusinessServices(anyString())).thenReturn(businessServicesList);
    zmsTestInitializer.getZms().domainMetaStore = mockDomainMetaStore;
    ArgumentCaptor<String> userCapture = ArgumentCaptor.forClass(String.class);
    zmsTestInitializer.getZms().getDomainMetaStoreValidValuesList(zmsTestInitializer.getMockDomRsrcCtx(), "businessService", "TestUser");
    verify(mockDomainMetaStore, times(1)).getValidBusinessServices(userCapture.capture());
    assertEquals(userCapture.getValue(), "testuser");
    zmsTestInitializer.getZms().domainMetaStore = savedMetaStore;
}
Also used : DomainMetaStore(com.yahoo.athenz.common.server.metastore.DomainMetaStore)

Example 4 with DomainMetaStore

use of com.yahoo.athenz.common.server.metastore.DomainMetaStore in project athenz by yahoo.

the class ZMSImplTest method testGetDomainMetaStoreValidValuesListMissingAttribute.

@Test
public void testGetDomainMetaStoreValidValuesListMissingAttribute() {
    DomainMetaStore savedMetaStore = zmsTestInitializer.getZms().domainMetaStore;
    zmsTestInitializer.getZms().domainMetaStore = new TestDomainMetaStore();
    try {
        zmsTestInitializer.getZms().getDomainMetaStoreValidValuesList(zmsTestInitializer.getMockDomRsrcCtx(), null, null);
        fail();
    } catch (ResourceException ex) {
        assertEquals(ex.getMessage(), "ResourceException (400): {code: 400, message: \"attributeName is mandatory\"}");
    } finally {
        zmsTestInitializer.getZms().domainMetaStore = savedMetaStore;
    }
}
Also used : DomainMetaStore(com.yahoo.athenz.common.server.metastore.DomainMetaStore)

Example 5 with DomainMetaStore

use of com.yahoo.athenz.common.server.metastore.DomainMetaStore in project athenz by yahoo.

the class ZMSImplTest method testPostDomainInvalidDomainMetaStoreValues.

@Test
public void testPostDomainInvalidDomainMetaStoreValues() {
    final String domainName = "athenz-domain-with-invalid-details";
    DomainMetaStore savedMetaStore = zmsTestInitializer.getZms().domainMetaStore;
    zmsTestInitializer.getZms().domainMetaStore = new TestDomainMetaStore();
    TopLevelDomain dom1 = zmsTestInitializer.createTopLevelDomainObject(domainName, "Test Domain1", "testOrg", zmsTestInitializer.getAdminUser());
    try {
        dom1.setBusinessService("invalid-business-service");
        zmsTestInitializer.getZms().postTopLevelDomain(zmsTestInitializer.getMockDomRsrcCtx(), zmsTestInitializer.getAuditRef(), dom1);
        fail();
    } catch (ResourceException ex) {
        assertTrue(ex.getMessage().contains("invalid business service name"));
    }
    try {
        dom1.setBusinessService("valid-business-service");
        dom1.setAccount("invalid-aws-account");
        zmsTestInitializer.getZms().postTopLevelDomain(zmsTestInitializer.getMockDomRsrcCtx(), zmsTestInitializer.getAuditRef(), dom1);
        fail();
    } catch (ResourceException ex) {
        assertTrue(ex.getMessage().contains("invalid aws account"));
    }
    try {
        dom1.setAccount("valid-aws-account");
        dom1.setAzureSubscription("invalid-azure-subscription");
        zmsTestInitializer.getZms().postTopLevelDomain(zmsTestInitializer.getMockDomRsrcCtx(), zmsTestInitializer.getAuditRef(), dom1);
        fail();
    } catch (ResourceException ex) {
        assertTrue(ex.getMessage().contains("invalid azure subscription"));
    }
    zmsTestInitializer.getZms().productIdSupport = true;
    try {
        dom1.setAzureSubscription("valid-azure-subscription");
        dom1.setYpmId(100);
        zmsTestInitializer.getZms().postTopLevelDomain(zmsTestInitializer.getMockDomRsrcCtx(), zmsTestInitializer.getAuditRef(), dom1);
        fail();
    } catch (ResourceException ex) {
        assertTrue(ex.getMessage().contains("invalid product id"));
    }
    dom1.setYpmId(101);
    zmsTestInitializer.getZms().postTopLevelDomain(zmsTestInitializer.getMockDomRsrcCtx(), zmsTestInitializer.getAuditRef(), dom1);
    Domain domain = zmsTestInitializer.getZms().getDomain(zmsTestInitializer.getMockDomRsrcCtx(), domainName);
    assertNotNull(domain);
    assertEquals(domain.getBusinessService(), "valid-business-service");
    assertEquals(domain.getAccount(), "valid-aws-account");
    assertEquals(domain.getAzureSubscription(), "valid-azure-subscription");
    assertEquals(domain.getYpmId().intValue(), 101);
    zmsTestInitializer.getZms().deleteTopLevelDomain(zmsTestInitializer.getMockDomRsrcCtx(), domainName, zmsTestInitializer.getAuditRef());
    zmsTestInitializer.getZms().domainMetaStore = savedMetaStore;
    zmsTestInitializer.getZms().productIdSupport = false;
}
Also used : AthenzDomain(com.yahoo.athenz.zms.store.AthenzDomain) DomainMetaStore(com.yahoo.athenz.common.server.metastore.DomainMetaStore)

Aggregations

DomainMetaStore (com.yahoo.athenz.common.server.metastore.DomainMetaStore)9 AthenzDomain (com.yahoo.athenz.zms.store.AthenzDomain)4