Search in sources :

Example 56 with DomainData

use of com.yahoo.athenz.zms.DomainData in project athenz by yahoo.

the class S3ChangeLogStoreTest method testGetSignedDomainInternal.

@Test
public void testGetSignedDomainInternal() throws IOException {
    MockS3ChangeLogStore store = new MockS3ChangeLogStore(null);
    InputStream is = new FileInputStream("src/test/resources/iaas.json");
    MockS3ObjectInputStream s3Is = new MockS3ObjectInputStream(is, null);
    S3Object object = mock(S3Object.class);
    when(object.getObjectContent()).thenReturn(s3Is);
    when(store.awsS3Client.getObject("athenz-domain-sys.auth", "iaas")).thenReturn(object);
    SignedDomain signedDomain = store.getSignedDomain(store.awsS3Client, "iaas");
    assertNotNull(signedDomain);
    DomainData domainData = signedDomain.getDomain();
    assertNotNull(domainData);
    assertEquals(domainData.getName(), "iaas");
    is.close();
}
Also used : FileInputStream(java.io.FileInputStream) S3ObjectInputStream(com.amazonaws.services.s3.model.S3ObjectInputStream) InputStream(java.io.InputStream) SignedDomain(com.yahoo.athenz.zms.SignedDomain) DomainData(com.yahoo.athenz.zms.DomainData) S3Object(com.amazonaws.services.s3.model.S3Object) FileInputStream(java.io.FileInputStream) Test(org.testng.annotations.Test)

Example 57 with DomainData

use of com.yahoo.athenz.zms.DomainData in project athenz by yahoo.

the class DataStoreTest method testProcessDomainPolicies.

@Test
public void testProcessDomainPolicies() {
    ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
    DataStore store = new DataStore(clogStore, null);
    List<com.yahoo.athenz.zms.Policy> policies = new ArrayList<>();
    com.yahoo.athenz.zms.Policy policy = new com.yahoo.athenz.zms.Policy();
    com.yahoo.athenz.zms.Assertion assertion = new com.yahoo.athenz.zms.Assertion();
    assertion.setResource("sports:role.readers");
    assertion.setAction("assume_role");
    assertion.setRole("coretech:role.readers");
    List<com.yahoo.athenz.zms.Assertion> assertions = new ArrayList<>();
    assertions.add(assertion);
    policy.setAssertions(assertions);
    policies.add(policy);
    List<Role> roles = new ArrayList<>();
    Role role = new Role();
    role.setName("coretech:role.admin");
    List<RoleMember> members = new ArrayList<>();
    members.add(new RoleMember().setMemberName("user_domain.user"));
    role.setRoleMembers(members);
    roles.add(role);
    role = new Role();
    role.setName("coretech:role.readers");
    members = new ArrayList<>();
    members.add(new RoleMember().setMemberName("user_domain.user"));
    role.setRoleMembers(members);
    roles.add(role);
    com.yahoo.athenz.zms.DomainPolicies domainPolicies = new com.yahoo.athenz.zms.DomainPolicies();
    domainPolicies.setDomain("coretech");
    domainPolicies.setPolicies(policies);
    com.yahoo.athenz.zms.SignedPolicies signedPolicies = new com.yahoo.athenz.zms.SignedPolicies();
    signedPolicies.setContents(domainPolicies);
    signedPolicies.setSignature(Crypto.sign(SignUtils.asCanonicalString(domainPolicies), pkey));
    signedPolicies.setKeyId("0");
    DomainData domainData = new DomainData();
    domainData.setName("coretech");
    domainData.setPolicies(signedPolicies);
    domainData.setRoles(roles);
    DataCache dataCache = new DataCache();
    dataCache.setDomainData(domainData);
    store.processDomainRoles(domainData, dataCache);
    assertEquals(dataCache.getMemberRoleSet("user_domain.user").size(), 2);
    assertTrue(dataCache.getMemberRoleSet("user_domain.user").contains(new MemberRole("coretech:role.admin", 0)));
    assertTrue(dataCache.getMemberRoleSet("user_domain.user").contains(new MemberRole("coretech:role.readers", 0)));
}
Also used : ArrayList(java.util.ArrayList) DomainData(com.yahoo.athenz.zms.DomainData) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore) DataCache(com.yahoo.athenz.zts.cache.DataCache) Role(com.yahoo.athenz.zms.Role) MemberRole(com.yahoo.athenz.zts.cache.MemberRole) MemberRole(com.yahoo.athenz.zts.cache.MemberRole) ZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.ZMSFileChangeLogStore) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore) RoleMember(com.yahoo.athenz.zms.RoleMember) Test(org.testng.annotations.Test)

Example 58 with DomainData

use of com.yahoo.athenz.zms.DomainData in project athenz by yahoo.

the class DataStoreTest method testDeleteDomainFromCacheHosts.

@Test
public void testDeleteDomainFromCacheHosts() {
    ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
    DataStore store = new DataStore(clogStore, null);
    DataCache dataCache = new DataCache();
    ServiceIdentity service = new ServiceIdentity();
    service.setName("coretech.storage");
    List<String> hosts = new ArrayList<>();
    hosts.add("host1");
    service.setHosts(hosts);
    List<ServiceIdentity> services = new ArrayList<>();
    dataCache.processServiceIdentity(service);
    services.add(service);
    DomainData domainData = new DomainData();
    domainData.setServices(services);
    dataCache.setDomainData(domainData);
    store.addDomainToCache("coretech", dataCache);
    store.deleteDomainFromCache("coretech");
    HostServices hostServices = store.getHostServices("host1");
    hosts = hostServices.getNames();
    assertEquals(hosts.size(), 0);
}
Also used : ZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.ZMSFileChangeLogStore) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore) ServiceIdentity(com.yahoo.athenz.zms.ServiceIdentity) ArrayList(java.util.ArrayList) DomainData(com.yahoo.athenz.zms.DomainData) HostServices(com.yahoo.athenz.zts.HostServices) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore) DataCache(com.yahoo.athenz.zts.cache.DataCache) Test(org.testng.annotations.Test)

Example 59 with DomainData

use of com.yahoo.athenz.zms.DomainData in project athenz by yahoo.

the class DataStoreTest method createDataCacheWildCard.

private DataCache createDataCacheWildCard(String domainName) {
    DataCache dataCache = new DataCache();
    List<Role> roles = new ArrayList<>();
    Role role = new Role();
    role.setName(domainName + ":role.admin");
    List<RoleMember> members = new ArrayList<>();
    members.add(new RoleMember().setMemberName("user_domain.user*"));
    role.setRoleMembers(members);
    roles.add(role);
    dataCache.processRole(role);
    role = new Role();
    role.setName(domainName + ":role.readers");
    members = new ArrayList<>();
    members.add(new RoleMember().setMemberName("user_domain.user1"));
    members.add(new RoleMember().setMemberName("user_domain.joe"));
    role.setRoleMembers(members);
    roles.add(role);
    dataCache.processRole(role);
    role = new Role();
    role.setName(domainName + ":role.editors");
    members = new ArrayList<>();
    members.add(new RoleMember().setMemberName("*"));
    role.setRoleMembers(members);
    roles.add(role);
    dataCache.processRole(role);
    role = new Role();
    role.setName(domainName + ":role.writers");
    role.setTrust(domainName + "Trust");
    roles.add(role);
    dataCache.processRole(role);
    DomainData domainData = new DomainData();
    domainData.setName(domainName);
    domainData.setRoles(roles);
    dataCache.setDomainData(domainData);
    return dataCache;
}
Also used : Role(com.yahoo.athenz.zms.Role) MemberRole(com.yahoo.athenz.zts.cache.MemberRole) ArrayList(java.util.ArrayList) DomainData(com.yahoo.athenz.zms.DomainData) DataCache(com.yahoo.athenz.zts.cache.DataCache) RoleMember(com.yahoo.athenz.zms.RoleMember)

Example 60 with DomainData

use of com.yahoo.athenz.zms.DomainData in project athenz by yahoo.

the class DataStoreTest method testAddDomainToCacheSameHosts.

@Test
public void testAddDomainToCacheSameHosts() {
    ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
    DataStore store = new DataStore(clogStore, null);
    DataCache dataCache = new DataCache();
    ServiceIdentity service = new ServiceIdentity();
    service.setName("coretech.storage");
    List<String> hosts = new ArrayList<>();
    hosts.add("host1");
    service.setHosts(hosts);
    List<ServiceIdentity> services = new ArrayList<>();
    services.add(service);
    dataCache.processServiceIdentity(service);
    DomainData domainData = new DomainData();
    domainData.setServices(services);
    dataCache.setDomainData(domainData);
    store.addDomainToCache("coretech", dataCache);
    /* same hosts - no changes */
    dataCache = new DataCache();
    service = new ServiceIdentity();
    service.setName("coretech.storage");
    hosts = new ArrayList<>();
    hosts.add("host1");
    service.setHosts(hosts);
    services = new ArrayList<>();
    services.add(service);
    dataCache.processServiceIdentity(service);
    domainData = new DomainData();
    domainData.setServices(services);
    dataCache.setDomainData(domainData);
    store.addDomainToCache("coretech", dataCache);
    HostServices hostServices = store.getHostServices("host1");
    hosts = hostServices.getNames();
    assertEquals(hosts.size(), 1);
    assertTrue(hosts.contains("coretech.storage"));
}
Also used : ZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.ZMSFileChangeLogStore) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore) ServiceIdentity(com.yahoo.athenz.zms.ServiceIdentity) ArrayList(java.util.ArrayList) DomainData(com.yahoo.athenz.zms.DomainData) HostServices(com.yahoo.athenz.zts.HostServices) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore) DataCache(com.yahoo.athenz.zts.cache.DataCache) Test(org.testng.annotations.Test)

Aggregations

DomainData (com.yahoo.athenz.zms.DomainData)64 ArrayList (java.util.ArrayList)44 Test (org.testng.annotations.Test)43 Role (com.yahoo.athenz.zms.Role)32 DataCache (com.yahoo.athenz.zts.cache.DataCache)32 RoleMember (com.yahoo.athenz.zms.RoleMember)25 SignedDomain (com.yahoo.athenz.zms.SignedDomain)25 ZMSFileChangeLogStore (com.yahoo.athenz.zts.store.impl.ZMSFileChangeLogStore)25 MockZMSFileChangeLogStore (com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore)24 ServiceIdentity (com.yahoo.athenz.zms.ServiceIdentity)21 Policy (com.yahoo.athenz.zms.Policy)18 MemberRole (com.yahoo.athenz.zts.cache.MemberRole)15 Assertion (com.yahoo.athenz.zms.Assertion)11 HostServices (com.yahoo.athenz.zts.HostServices)6 S3Object (com.amazonaws.services.s3.model.S3Object)4 S3ObjectInputStream (com.amazonaws.services.s3.model.S3ObjectInputStream)4 FileInputStream (java.io.FileInputStream)4 InputStream (java.io.InputStream)4 Principal (com.yahoo.athenz.auth.Principal)3 SimplePrincipal (com.yahoo.athenz.auth.impl.SimplePrincipal)3