Search in sources :

Example 1 with MockCloudStore

use of com.yahoo.athenz.zts.store.MockCloudStore in project athenz by yahoo.

the class ZTSImplTest method testGetAWSTemporaryCredentials.

@Test
public void testGetAWSTemporaryCredentials() {
    Principal principal = SimplePrincipal.create("user_domain", "user101", "v=U1;d=user_domain;n=user101;s=signature", 0, null);
    CloudStore cloudStore = new MockCloudStore();
    ((MockCloudStore) cloudStore).setMockFields("1234", "aws_role_name", "user_domain.user101");
    store.setCloudStore(cloudStore);
    zts.cloudStore = cloudStore;
    SignedDomain signedDomain = createAwsSignedDomain("athenz.product", "1234");
    store.processDomain(signedDomain, false);
    AWSTemporaryCredentials creds = zts.getAWSTemporaryCredentials(createResourceContext(principal), "athenz.product", "aws_role_name");
    assertNotNull(creds);
    try {
        ((MockCloudStore) cloudStore).setMockFields("1234", "aws_role2_name", "user_domain.user101");
        zts.getAWSTemporaryCredentials(createResourceContext(principal), "athenz.product", "aws_role_name");
        fail();
    } catch (ResourceException ex) {
        assertEquals(ex.getCode(), 400);
    }
}
Also used : MockCloudStore(com.yahoo.athenz.zts.store.MockCloudStore) CloudStore(com.yahoo.athenz.zts.store.CloudStore) MockCloudStore(com.yahoo.athenz.zts.store.MockCloudStore) SignedDomain(com.yahoo.athenz.zms.SignedDomain) SimplePrincipal(com.yahoo.athenz.auth.impl.SimplePrincipal) Principal(com.yahoo.athenz.auth.Principal) Test(org.testng.annotations.Test)

Example 2 with MockCloudStore

use of com.yahoo.athenz.zts.store.MockCloudStore in project athenz by yahoo.

the class ZTSImplTest method testGetAWSTemporaryCredentialsNoAwsAccount.

@Test
public void testGetAWSTemporaryCredentialsNoAwsAccount() {
    Principal principal = SimplePrincipal.create("user_domain", "user101", "v=U1;d=user_domain;n=user101;s=signature", 0, null);
    CloudStore cloudStore = new MockCloudStore();
    store.setCloudStore(cloudStore);
    zts.cloudStore = cloudStore;
    SignedDomain signedDomain = createAwsSignedDomain("athenz.product", null);
    store.processDomain(signedDomain, false);
    try {
        zts.getAWSTemporaryCredentials(createResourceContext(principal), "athenz.product", "aws_role_name");
        fail();
    } catch (ResourceException ex) {
        assertEquals(ex.getCode(), 400);
    }
}
Also used : MockCloudStore(com.yahoo.athenz.zts.store.MockCloudStore) CloudStore(com.yahoo.athenz.zts.store.CloudStore) MockCloudStore(com.yahoo.athenz.zts.store.MockCloudStore) SignedDomain(com.yahoo.athenz.zms.SignedDomain) SimplePrincipal(com.yahoo.athenz.auth.impl.SimplePrincipal) Principal(com.yahoo.athenz.auth.Principal) Test(org.testng.annotations.Test)

Example 3 with MockCloudStore

use of com.yahoo.athenz.zts.store.MockCloudStore in project athenz by yahoo.

the class ZTSImplTest method testGetRoleTokenCert.

@Test
public void testGetRoleTokenCert() throws Exception {
    // this csr is for sports:role.readers role
    RoleCertificateRequest req = new RoleCertificateRequest().setCsr(ROLE_CERT_CORETECH_REQUEST).setExpiryTime(Long.valueOf(3600));
    SignedDomain signedDomain = createSignedDomain("coretech", "weather", "storage", true);
    store.processDomain(signedDomain, false);
    File caCert = new File("src/test/resources/valid_cn_x509.cert");
    X509Certificate caCertificate = Crypto.loadX509Certificate(caCert);
    File caKey = new File("src/test/resources/private_encrypted.key");
    PrivateKey caPrivateKey = Crypto.loadPrivateKey(caKey, "athenz");
    CertSigner certSigner = new SelfCertSigner(caPrivateKey, caCertificate);
    CloudStore cloudStore = new MockCloudStore(certSigner);
    store.setCloudStore(cloudStore);
    zts.cloudStore = cloudStore;
    Principal principal = SimplePrincipal.create("user_domain", "user1", "v=U1;d=user_domain;n=user;s=signature", 0, null);
    ResourceContext context = createResourceContext(principal);
    RoleToken roleToken = zts.postRoleCertificateRequest(context, "coretech", "readers", req);
    assertNotNull(roleToken);
    assertEquals(roleToken.getExpiryTime(), TimeUnit.SECONDS.convert(30, TimeUnit.DAYS));
}
Also used : PrivateKey(java.security.PrivateKey) MockCloudStore(com.yahoo.athenz.zts.store.MockCloudStore) CloudStore(com.yahoo.athenz.zts.store.CloudStore) CertSigner(com.yahoo.athenz.common.server.cert.CertSigner) SelfCertSigner(com.yahoo.athenz.zts.cert.impl.SelfCertSigner) SignedDomain(com.yahoo.athenz.zms.SignedDomain) MockCloudStore(com.yahoo.athenz.zts.store.MockCloudStore) SelfCertSigner(com.yahoo.athenz.zts.cert.impl.SelfCertSigner) File(java.io.File) X509Certificate(java.security.cert.X509Certificate) SimplePrincipal(com.yahoo.athenz.auth.impl.SimplePrincipal) Principal(com.yahoo.athenz.auth.Principal) Test(org.testng.annotations.Test)

Aggregations

Principal (com.yahoo.athenz.auth.Principal)3 SimplePrincipal (com.yahoo.athenz.auth.impl.SimplePrincipal)3 SignedDomain (com.yahoo.athenz.zms.SignedDomain)3 CloudStore (com.yahoo.athenz.zts.store.CloudStore)3 MockCloudStore (com.yahoo.athenz.zts.store.MockCloudStore)3 Test (org.testng.annotations.Test)3 CertSigner (com.yahoo.athenz.common.server.cert.CertSigner)1 SelfCertSigner (com.yahoo.athenz.zts.cert.impl.SelfCertSigner)1 File (java.io.File)1 PrivateKey (java.security.PrivateKey)1 X509Certificate (java.security.cert.X509Certificate)1