use of com.yahoo.athenz.zms.DomainData in project athenz by yahoo.
the class DataStoreTest method testDeleteDomainFromCacheServices.
@Test
public void testDeleteDomainFromCacheServices() {
ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
DataStore store = new DataStore(clogStore, null);
SignedDomain signedDomain = new SignedDomain();
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);
DomainData domainData = new DomainData();
domainData.setName("coretech");
domainData.setRoles(roles);
signedDomain.setDomain(domainData);
signedDomain.setKeyId("0");
((MockZMSFileChangeLogStore) store.changeLogStore).put("coretech", JSON.bytes(signedDomain));
DataCache dataCache = new DataCache();
dataCache.setDomainData(domainData);
store.addDomainToCache("coretech", dataCache);
store.deleteDomainFromCache("coretech");
store.changeLogStore.removeLocalDomain("coretech");
assertNull(store.getCacheStore().getIfPresent("coretech"));
File file = new File("/tmp/zts_server_unit_tests/zts_root/coretech");
assertFalse(file.exists());
}
use of com.yahoo.athenz.zms.DomainData in project athenz by yahoo.
the class ZTSImpl method getDomainSignedPolicyData.
public void getDomainSignedPolicyData(ResourceContext ctx, String domainName, String matchingTag, GetDomainSignedPolicyDataResult signedPoliciesResult) {
final String caller = "getdomainsignedpolicydata";
final String callerTiming = "getdomainsignedpolicydata_timing";
metric.increment(HTTP_GET);
logPrincipal(ctx);
validateRequest(ctx.request(), caller);
validate(domainName, TYPE_DOMAIN_NAME, caller);
// for consistent handling of all requests, we're going to convert
// all incoming object values into lower case since ZMS Server
// saves all of its object names in lower case
domainName = domainName.toLowerCase();
Object timerMetric = metric.startTiming(callerTiming, domainName);
DomainData domainData = dataStore.getDomainData(domainName);
if (domainData == null) {
metric.increment(HTTP_REQUEST, ZTSConsts.ZTS_UNKNOWN_DOMAIN);
metric.increment(caller, ZTSConsts.ZTS_UNKNOWN_DOMAIN);
throw notFoundError("Domain not found: '" + domainName + "'", caller, ZTSConsts.ZTS_UNKNOWN_DOMAIN);
}
// update our metric with dimension. we're moving the metric here
// after the domain name has been confirmed as valid since with
// dimensions we get stuck with persistent indexes so we only want
// to create them for valid domain names
metric.increment(HTTP_REQUEST, domainName);
metric.increment(caller, domainName);
Timestamp modified = domainData.getModified();
EntityTag eTag = new EntityTag(modified.toString());
String tag = eTag.toString();
if (matchingTag != null && matchingTag.equals(tag)) {
signedPoliciesResult.done(ResourceException.NOT_MODIFIED, matchingTag);
}
// first get our PolicyData object
PolicyData policyData = new PolicyData().setDomain(domainName).setPolicies(getPolicyList(domainData));
// then get the signed policy data
Timestamp expires = Timestamp.fromMillis(System.currentTimeMillis() + signedPolicyTimeout);
SignedPolicyData signedPolicyData = new SignedPolicyData().setPolicyData(policyData).setExpires(expires).setModified(modified).setZmsKeyId(domainData.getPolicies().getKeyId()).setZmsSignature(domainData.getPolicies().getSignature());
String signature = Crypto.sign(SignUtils.asCanonicalString(signedPolicyData), privateKey);
DomainSignedPolicyData result = new DomainSignedPolicyData().setSignedPolicyData(signedPolicyData).setSignature(signature).setKeyId(privateKeyId);
metric.stopTiming(timerMetric);
signedPoliciesResult.done(ResourceException.OK, result, tag);
}
use of com.yahoo.athenz.zms.DomainData in project athenz by yahoo.
the class DataStoreTest method testValidateSignedDomainMissingRole.
@Test
public void testValidateSignedDomainMissingRole() {
ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
DataStore store = new DataStore(clogStore, null);
store.loadZMSPublicKeys();
SignedDomain signedDomain = new SignedDomain();
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);
DomainData domain = new DomainData();
domain.setRoles(roles);
signedDomain.setDomain(domain);
signedDomain.setSignature(Crypto.sign(SignUtils.asCanonicalString(domain), pkey));
signedDomain.setKeyId("0");
domain.setRoles(null);
signedDomain.setDomain(domain);
assertFalse(store.validateSignedDomain(signedDomain));
}
use of com.yahoo.athenz.zms.DomainData in project athenz by yahoo.
the class S3ChangeLogStoreTest method testGetSignedDomainException.
@Test
public void testGetSignedDomainException() 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);
// first call we return null, second call we return success
when(store.awsS3Client.getObject("athenz-domain-sys.auth", "iaas")).thenThrow(new AmazonServiceException("test")).thenReturn(object);
SignedDomain signedDomain = store.getSignedDomain("iaas");
assertNotNull(signedDomain);
DomainData domainData = signedDomain.getDomain();
assertNotNull(domainData);
assertEquals(domainData.getName(), "iaas");
is.close();
}
use of com.yahoo.athenz.zms.DomainData in project athenz by yahoo.
the class S3ChangeLogStoreTest method testGetSignedDomain.
@Test
public void testGetSignedDomain() 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("iaas");
assertNotNull(signedDomain);
DomainData domainData = signedDomain.getDomain();
assertNotNull(domainData);
assertEquals(domainData.getName(), "iaas");
is.close();
}
Aggregations