Search in sources :

Example 81 with ZMSFileChangeLogStore

use of com.yahoo.athenz.common.server.store.impl.ZMSFileChangeLogStore in project athenz by yahoo.

the class ZTSImplTest method testConfigurationSettings.

@Test
public void testConfigurationSettings() {
    ChangeLogStore structStore = new ZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", privateKey, "0");
    DataStore store = new DataStore(structStore, null, ztsMetric);
    System.clearProperty(ZTSConsts.ZTS_PROP_AUTHORIZED_PROXY_USERS);
    System.clearProperty(ZTSConsts.ZTS_PROP_CERT_ALLOWED_O_VALUES);
    System.clearProperty(ZTSConsts.ZTS_PROP_NOAUTH_URI_LIST);
    System.setProperty(ZTSConsts.ZTS_PROP_USER_DOMAIN_ALIAS, "alias");
    ZTSImpl ztsImpl = new ZTSImpl(mockCloudStore, store);
    assertNull(ztsImpl.authorizedProxyUsers);
    assertNull(ztsImpl.authFreeUriList);
    assertNull(ztsImpl.authFreeUriSet);
    assertNull(ztsImpl.validCertSubjectOrgValues);
    assertEquals(ztsImpl.userDomainAliasPrefix, "alias.");
    // some more config values tests
    System.clearProperty(ZTSConsts.ZTS_PROP_USER_DOMAIN_ALIAS);
    System.setProperty(ZTSConsts.ZTS_PROP_NOAUTH_URI_LIST, "/uri1,/uri1+,/uri2");
    System.setProperty(ZTSConsts.ZTS_PROP_CERT_ALLOWED_OU_VALUES, "Athenz|Athens");
    ztsImpl = new ZTSImpl(mockCloudStore, store);
    assertEquals(ztsImpl.authFreeUriList.size(), 1);
    assertEquals(ztsImpl.authFreeUriSet.size(), 2);
    assertEquals(ztsImpl.validCertSubjectOrgUnitValues.size(), 2);
    assertTrue(ztsImpl.validCertSubjectOrgUnitValues.contains("Athenz"));
    assertTrue(ztsImpl.validCertSubjectOrgUnitValues.contains("Athens"));
    System.clearProperty(ZTSConsts.ZTS_PROP_USER_DOMAIN_ALIAS);
    System.clearProperty(ZTSConsts.ZTS_PROP_NOAUTH_URI_LIST);
    System.clearProperty(ZTSConsts.ZTS_PROP_CERT_ALLOWED_OU_VALUES);
}
Also used : ZMSFileChangeLogStore(com.yahoo.athenz.common.server.store.impl.ZMSFileChangeLogStore) ChangeLogStore(com.yahoo.athenz.common.server.store.ChangeLogStore) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.MockZMSFileChangeLogStore) ZMSFileChangeLogStore(com.yahoo.athenz.common.server.store.impl.ZMSFileChangeLogStore) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.MockZMSFileChangeLogStore) DataStore(com.yahoo.athenz.zts.store.DataStore) Test(org.testng.annotations.Test)

Example 82 with ZMSFileChangeLogStore

use of com.yahoo.athenz.common.server.store.impl.ZMSFileChangeLogStore in project athenz by yahoo.

the class ZTSImplTest method testReadOnlyMode.

@Test
public void testReadOnlyMode() {
    ChangeLogStore structStore = new ZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", privateKey, "0");
    DataStore store = new DataStore(structStore, null, ztsMetric);
    ZTSImpl ztsImpl = new ZTSImpl(mockCloudStore, store);
    DynamicConfigBoolean dynamicConfigBoolean = Mockito.mock(DynamicConfigBoolean.class);
    when(dynamicConfigBoolean.get()).thenReturn(true);
    ztsImpl.readOnlyMode = dynamicConfigBoolean;
    PrincipalAuthority authority = new PrincipalAuthority();
    SimplePrincipal principal = (SimplePrincipal) SimplePrincipal.create("athenz", "readonly", "v=S1;d=athenz;n=readonly;s=signature", 0, authority);
    ResourceContext ctx = createResourceContext(principal);
    try {
        ztsImpl.postRoleCertificateRequest(ctx, null, null, null);
        fail();
    } catch (ResourceException ex) {
        assertEquals(ex.getCode(), 400);
        assertTrue(ex.getMessage().contains("Read-Only mode"));
    }
    try {
        ztsImpl.postInstanceRegisterInformation(ctx, null);
        fail();
    } catch (ResourceException ex) {
        assertEquals(ex.getCode(), 400);
        assertTrue(ex.getMessage().contains("Read-Only mode"));
    }
    try {
        ztsImpl.postInstanceRefreshInformation(ctx, null, null, null, null, null);
        fail();
    } catch (ResourceException ex) {
        assertEquals(ex.getCode(), 400);
        assertTrue(ex.getMessage().contains("Read-Only mode"));
    }
    try {
        ztsImpl.deleteInstanceIdentity(ctx, null, null, null, null);
        fail();
    } catch (ResourceException ex) {
        assertEquals(ex.getCode(), 400);
        assertTrue(ex.getMessage().contains("Read-Only mode"));
    }
    try {
        ztsImpl.postInstanceRefreshRequest(ctx, null, null, null);
        fail();
    } catch (ResourceException ex) {
        assertEquals(ex.getCode(), 400);
        assertTrue(ex.getMessage().contains("Read-Only mode"));
    }
    try {
        ztsImpl.postSSHCertRequest(ctx, null);
        fail();
    } catch (ResourceException ex) {
        assertEquals(ex.getCode(), 400);
        assertTrue(ex.getMessage().contains("Read-Only mode"));
    }
    try {
        ztsImpl.postRoleCertificateRequestExt(ctx, null);
        fail();
    } catch (ResourceException ex) {
        assertEquals(ex.getCode(), 400);
        assertTrue(ex.getMessage().contains("Read-Only mode"));
    }
}
Also used : ZMSFileChangeLogStore(com.yahoo.athenz.common.server.store.impl.ZMSFileChangeLogStore) ChangeLogStore(com.yahoo.athenz.common.server.store.ChangeLogStore) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.MockZMSFileChangeLogStore) ZMSFileChangeLogStore(com.yahoo.athenz.common.server.store.impl.ZMSFileChangeLogStore) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.MockZMSFileChangeLogStore) DataStore(com.yahoo.athenz.zts.store.DataStore) DynamicConfigBoolean(com.yahoo.athenz.common.server.util.config.dynamic.DynamicConfigBoolean) Test(org.testng.annotations.Test)

Example 83 with ZMSFileChangeLogStore

use of com.yahoo.athenz.common.server.store.impl.ZMSFileChangeLogStore in project athenz by yahoo.

the class ZTSImplTest method testValidateRequestRegularRequestPort.

@Test
public void testValidateRequestRegularRequestPort() {
    ChangeLogStore structStore = new ZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", privateKey, "0");
    DataStore store = new DataStore(structStore, null, ztsMetric);
    ZTSImpl ztsImpl = new ZTSImpl(mockCloudStore, store);
    ztsImpl.secureRequestsOnly = true;
    ztsImpl.statusPort = 8443;
    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    Mockito.when(request.isSecure()).thenReturn(true);
    Mockito.when(request.getLocalPort()).thenReturn(8443);
    // status requests are allowed on port 8443
    ztsImpl.validateRequest(request, "test", "principal-domain", true);
    try {
        ztsImpl.validateRequest(request, "principal-domain", "test");
        fail();
    } catch (ResourceException ignored) {
    }
    try {
        ztsImpl.validateRequest(request, "principal-domain", "test", false);
        fail();
    } catch (ResourceException ignored) {
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ZMSFileChangeLogStore(com.yahoo.athenz.common.server.store.impl.ZMSFileChangeLogStore) ChangeLogStore(com.yahoo.athenz.common.server.store.ChangeLogStore) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.MockZMSFileChangeLogStore) ZMSFileChangeLogStore(com.yahoo.athenz.common.server.store.impl.ZMSFileChangeLogStore) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.MockZMSFileChangeLogStore) DataStore(com.yahoo.athenz.zts.store.DataStore) Test(org.testng.annotations.Test)

Example 84 with ZMSFileChangeLogStore

use of com.yahoo.athenz.common.server.store.impl.ZMSFileChangeLogStore in project athenz by yahoo.

the class ZTSImplTest method testDeleteInstanceIdentity.

@Test
public void testDeleteInstanceIdentity() {
    ChangeLogStore structStore = new ZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", privateKey, "0");
    DataStore store = new DataStore(structStore, null, ztsMetric);
    ZTSImpl ztsImpl = new ZTSImpl(mockCloudStore, store);
    InstanceCertManager instanceManager = Mockito.mock(InstanceCertManager.class);
    Mockito.when(instanceManager.deleteX509CertRecord("athenz.provider", "1001", "athenz.production")).thenReturn(true);
    Mockito.when(instanceManager.updateX509CertRecord(Mockito.any())).thenReturn(true);
    SimplePrincipal principal = (SimplePrincipal) SimplePrincipal.create("user", "doe", "v=U1,d=user;n=doe;s=sig", 0, new PrincipalAuthority());
    ZTSAuthorizer authorizer = Mockito.mock(ZTSAuthorizer.class);
    Mockito.when(authorizer.access("delete", "athenz:instance.1001", principal, null)).thenReturn(true);
    ztsImpl.authorizer = authorizer;
    ztsImpl.instanceCertManager = instanceManager;
    ResourceContext context = createResourceContext(principal);
    try {
        ztsImpl.deleteInstanceIdentity(context, "athenz.provider", "athenz", "production", "1001");
    } catch (Exception ex) {
        fail();
    }
}
Also used : InstanceCertManager(com.yahoo.athenz.zts.cert.InstanceCertManager) ZMSFileChangeLogStore(com.yahoo.athenz.common.server.store.impl.ZMSFileChangeLogStore) ChangeLogStore(com.yahoo.athenz.common.server.store.ChangeLogStore) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.MockZMSFileChangeLogStore) ZMSFileChangeLogStore(com.yahoo.athenz.common.server.store.impl.ZMSFileChangeLogStore) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.MockZMSFileChangeLogStore) DataStore(com.yahoo.athenz.zts.store.DataStore) JOSEException(com.nimbusds.jose.JOSEException) ParseException(java.text.ParseException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SignatureException(io.jsonwebtoken.security.SignatureException) MockStatusCheckerThrowException(com.yahoo.athenz.zts.status.MockStatusCheckerThrowException) MockStatusCheckerNoException(com.yahoo.athenz.zts.status.MockStatusCheckerNoException) IOException(java.io.IOException) Test(org.testng.annotations.Test)

Example 85 with ZMSFileChangeLogStore

use of com.yahoo.athenz.common.server.store.impl.ZMSFileChangeLogStore in project athenz by yahoo.

the class ZTSImplTest method testPostInstanceRefreshInformationInstanceIdMismatch.

@Test
public void testPostInstanceRefreshInformationInstanceIdMismatch() throws IOException {
    ChangeLogStore structStore = new ZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", privateKey, "0");
    DataStore store = new DataStore(structStore, null, ztsMetric);
    ZTSImpl ztsImpl = new ZTSImpl(mockCloudStore, store);
    SignedDomain providerDomain = signedAuthorizedProviderDomain();
    store.processSignedDomain(providerDomain, false);
    SignedDomain tenantDomain = signedBootstrapTenantDomain("athenz.provider", "athenz", "production");
    store.processSignedDomain(tenantDomain, false);
    Path path = Paths.get("src/test/resources/athenz.instanceid.csr");
    String certCsr = new String(Files.readAllBytes(path));
    InstanceProviderManager instanceProviderManager = Mockito.mock(InstanceProviderManager.class);
    InstanceProvider providerClient = Mockito.mock(InstanceProvider.class);
    InstanceConfirmation confirmation = new InstanceConfirmation().setDomain("athenz").setService("production").setProvider("athenz.provider");
    InstanceCertManager instanceManager = Mockito.spy(ztsImpl.instanceCertManager);
    X509CertRecord certRecord = new X509CertRecord();
    certRecord.setInstanceId("1001");
    certRecord.setProvider("athenz.provider");
    certRecord.setService("athenz.production");
    certRecord.setCurrentSerial("16503746516960996918");
    certRecord.setPrevSerial("16503746516960996918");
    Mockito.when(instanceManager.getX509CertRecord("athenz.provider", "1001", "athenz.production")).thenReturn(certRecord);
    Mockito.when(instanceProviderManager.getProvider(eq("athenz.provider"), Mockito.any())).thenReturn(providerClient);
    Mockito.when(providerClient.refreshInstance(Mockito.any())).thenReturn(confirmation);
    path = Paths.get("src/test/resources/valid_cn_x509.cert");
    String pem = new String(Files.readAllBytes(path));
    InstanceIdentity identity = new InstanceIdentity().setName("athenz.production").setX509Certificate(pem);
    Mockito.doReturn(identity).when(instanceManager).generateIdentity(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.anyInt(), Mockito.any());
    ztsImpl.instanceProviderManager = instanceProviderManager;
    ztsImpl.instanceCertManager = instanceManager;
    InstanceRefreshInformation info = new InstanceRefreshInformation().setCsr(certCsr);
    CertificateAuthority certAuthority = new CertificateAuthority();
    SimplePrincipal principal = (SimplePrincipal) SimplePrincipal.create("athenz", "production", "v=S1;d=athenz;n=production;s=signature", 0, certAuthority);
    assertNotNull(principal);
    X509Certificate cert = Crypto.loadX509Certificate(pem);
    principal.setX509Certificate(cert);
    ResourceContext context = createResourceContext(principal);
    try {
        ztsImpl.postInstanceRefreshInformation(context, "athenz.provider", "athenz", "production", "1001", info);
        fail();
    } catch (ResourceException ex) {
        assertEquals(ex.getCode(), 400, ex.getMessage());
        assertTrue(ex.getMessage().contains("instance id mismatch"));
    }
}
Also used : Path(java.nio.file.Path) InstanceConfirmation(com.yahoo.athenz.instance.provider.InstanceConfirmation) InstanceCertManager(com.yahoo.athenz.zts.cert.InstanceCertManager) X509CertRecord(com.yahoo.athenz.common.server.cert.X509CertRecord) X509Certificate(java.security.cert.X509Certificate) ZMSFileChangeLogStore(com.yahoo.athenz.common.server.store.impl.ZMSFileChangeLogStore) ChangeLogStore(com.yahoo.athenz.common.server.store.ChangeLogStore) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.MockZMSFileChangeLogStore) ZMSFileChangeLogStore(com.yahoo.athenz.common.server.store.impl.ZMSFileChangeLogStore) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.MockZMSFileChangeLogStore) DataStore(com.yahoo.athenz.zts.store.DataStore) InstanceProvider(com.yahoo.athenz.instance.provider.InstanceProvider) Test(org.testng.annotations.Test)

Aggregations

ChangeLogStore (com.yahoo.athenz.common.server.store.ChangeLogStore)104 ZMSFileChangeLogStore (com.yahoo.athenz.common.server.store.impl.ZMSFileChangeLogStore)104 DataStore (com.yahoo.athenz.zts.store.DataStore)104 MockZMSFileChangeLogStore (com.yahoo.athenz.zts.store.MockZMSFileChangeLogStore)104 Test (org.testng.annotations.Test)103 Path (java.nio.file.Path)69 InstanceCertManager (com.yahoo.athenz.zts.cert.InstanceCertManager)57 InstanceProvider (com.yahoo.athenz.instance.provider.InstanceProvider)40 X509Certificate (java.security.cert.X509Certificate)35 InstanceConfirmation (com.yahoo.athenz.instance.provider.InstanceConfirmation)34 X509CertRecord (com.yahoo.athenz.common.server.cert.X509CertRecord)23 HttpServletRequest (javax.servlet.http.HttpServletRequest)21 HttpServletResponse (javax.servlet.http.HttpServletResponse)17 Response (javax.ws.rs.core.Response)17 Principal (com.yahoo.athenz.auth.Principal)16 MockStatusCheckerNoException (com.yahoo.athenz.zts.status.MockStatusCheckerNoException)12 JOSEException (com.nimbusds.jose.JOSEException)11 MockStatusCheckerThrowException (com.yahoo.athenz.zts.status.MockStatusCheckerThrowException)11 SignatureException (io.jsonwebtoken.security.SignatureException)11 IOException (java.io.IOException)11