use of com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore in project athenz by yahoo.
the class DataStoreTest method testProcessTrustedDomainRoleValidWildCard.
@Test
public void testProcessTrustedDomainRoleValidWildCard() {
ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
DataStore store = new DataStore(clogStore, null);
DataCache dataCache = createDataCacheWildCard("coretech");
// first we're going tor process user1
// which should match all three roles including
// both wildcard roles
Set<String> accessibleRoles = new HashSet<>();
String prefix = "coretech" + ROLE_POSTFIX;
String identity = "user_domain.user1";
Set<String> trustedResources = new HashSet<>();
trustedResources.add("coretech:role.admin");
trustedResources.add("coretech:role.readers");
trustedResources.add("coretech:role.editors");
store.processTrustedDomain(dataCache, identity, prefix, null, trustedResources, accessibleRoles, false);
assertEquals(accessibleRoles.size(), 3);
assertTrue(accessibleRoles.contains("admin"));
assertTrue(accessibleRoles.contains("editors"));
assertTrue(accessibleRoles.contains("readers"));
// user_domain.joe should match readers and editors
accessibleRoles.clear();
identity = "user_domain.joe";
store.processTrustedDomain(dataCache, identity, prefix, null, trustedResources, accessibleRoles, false);
assertEquals(accessibleRoles.size(), 2);
assertTrue(accessibleRoles.contains("readers"));
assertTrue(accessibleRoles.contains("editors"));
// random service should only match editors
accessibleRoles.clear();
identity = "athenz.service";
store.processTrustedDomain(dataCache, identity, prefix, null, trustedResources, accessibleRoles, false);
assertEquals(accessibleRoles.size(), 1);
assertTrue(accessibleRoles.contains("editors"));
}
use of com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore in project athenz by yahoo.
the class DataStoreTest method testProcessSingleTrustedDomainRoleAddRoleTrue.
@Test
public void testProcessSingleTrustedDomainRoleAddRoleTrue() {
ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
DataStore store = new DataStore(clogStore, null);
Set<String> accessibleRoles = new HashSet<>();
String prefix = "coretech" + ROLE_POSTFIX;
String role = "coretech:role.readers";
/* invalid role causing no match */
Set<MemberRole> memberRoles = new HashSet<>();
memberRoles.add(new MemberRole("coretech:role.admin", 0));
memberRoles.add(new MemberRole("coretech:role.readers", 0));
store.processSingleTrustedDomainRole(role, prefix, null, memberRoles, accessibleRoles, false);
assertTrue(accessibleRoles.contains("readers"));
}
use of com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore in project athenz by yahoo.
the class DataStoreTest method testStoreInitNoLocalDomains.
@Test
public void testStoreInitNoLocalDomains() {
ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
DataStore store = new DataStore(clogStore, null);
((MockZMSFileChangeLogStore) store.changeLogStore).setTagHeader("2014-01-01T12:00:00");
((MockZMSFileChangeLogStore) store.changeLogStore).setLastModificationTimestamp(null);
List<SignedDomain> domains = new ArrayList<>();
/* we're going to create a new domain */
SignedDomain signedDomain = createSignedDomain("coretech", "weather");
domains.add(signedDomain);
/* we're going to update the coretech domain and set new roles */
signedDomain = createSignedDomain("sports", "weather");
domains.add(signedDomain);
SignedDomains signedDomains = new SignedDomains();
signedDomains.setDomains(domains);
((MockZMSFileChangeLogStore) store.changeLogStore).setSignedDomains(signedDomains);
boolean result = store.init();
assertTrue(result);
Set<String> accessibleRoles = new HashSet<>();
DataCache data = store.getDataCache("coretech");
store.getAccessibleRoles(data, "coretech", "user_domain.user", null, accessibleRoles, false);
assertEquals(accessibleRoles.size(), 2);
assertTrue(accessibleRoles.contains("admin"));
assertTrue(accessibleRoles.contains("writers"));
accessibleRoles = new HashSet<>();
data = store.getDataCache("sports");
store.getAccessibleRoles(data, "sports", "user_domain.user", null, accessibleRoles, false);
assertEquals(accessibleRoles.size(), 2);
assertTrue(accessibleRoles.contains("admin"));
assertTrue(accessibleRoles.contains("writers"));
}
use of com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore in project athenz by yahoo.
the class DataStoreTest method testRemovePublicKeysInvalid.
@Test
public void testRemovePublicKeysInvalid() {
ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
DataStore store = new DataStore(clogStore, null);
store.publicKeyCache.put("coretech.storage_0", "PublicKey0");
store.publicKeyCache.put("sports.storage_0", "PublicKey0");
store.publicKeyCache.put("sports.storage_1", "PublicKey1");
Map<String, String> remKeys = new HashMap<>();
remKeys.put("sports.storage_2", "PublicKey2");
store.removePublicKeys(remKeys);
assertEquals(store.publicKeyCache.size(), 3);
assertTrue(store.publicKeyCache.containsKey("coretech.storage_0"));
assertTrue(store.publicKeyCache.containsKey("sports.storage_0"));
assertTrue(store.publicKeyCache.containsKey("sports.storage_1"));
}
use of com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore in project athenz by yahoo.
the class DataStoreTest method testAddRoleToList.
@Test
public void testAddRoleToList() {
ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
DataStore store = new DataStore(clogStore, null);
Set<String> accessibleRoles = new HashSet<>();
store.addRoleToList("coretech:role.admin", "coretech:role.", null, accessibleRoles, false);
assertEquals(accessibleRoles.size(), 1);
assertTrue(accessibleRoles.contains("admin"));
}
Aggregations