use of javax.ws.rs.core.EntityTag in project athenz by yahoo.
the class ZTSImplTest method testPostSignedPolicyRequestNoChanges.
@Test
public void testPostSignedPolicyRequestNoChanges() {
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.serverHostName = "localhost";
SignedDomain signedDomain = createSignedDomain("coretech", "weather", "storage", true);
store.processSignedDomain(signedDomain, false);
Principal principal = SimplePrincipal.create("user_domain", "user", "v=U1;d=user_domain;n=user;s=signature", 0, null);
ResourceContext context = createResourceContext(principal);
Timestamp modified = signedDomain.getDomain().getModified();
EntityTag eTag = new EntityTag(modified.toString());
SignedPolicyRequest signedPolicyRequest = new SignedPolicyRequest();
signedPolicyRequest.setPolicyVersions(Collections.emptyMap());
Response response = ztsImpl.postSignedPolicyRequest(context, "coretech", signedPolicyRequest, eTag.toString());
assertEquals(response.getStatus(), 304);
}
use of javax.ws.rs.core.EntityTag in project athenz by yahoo.
the class ETagFilterTest method testFilterContainerETagSet.
@Test
public void testFilterContainerETagSet() {
ContainerResponseContext containerResponse = getContext("etag");
ETagFilter eTagFilter = new ETagFilter();
eTagFilter.filter(null, containerResponse);
EntityTag eTag = (EntityTag) containerResponse.getHeaders().getFirst(HttpHeaders.ETAG);
assertNotNull(eTag);
assertEquals(eTag.getValue(), "etag");
}
use of javax.ws.rs.core.EntityTag in project athenz by yahoo.
the class ETagFilterTest method testFilterContainerETagNotSet.
@Test
public void testFilterContainerETagNotSet() {
ContainerResponseContext containerResponse = getContext(null);
ETagFilter eTagFilter = new ETagFilter();
eTagFilter.filter(null, containerResponse);
EntityTag eTag = (EntityTag) containerResponse.getHeaders().getFirst(HttpHeaders.ETAG);
assertNull(eTag);
}
use of javax.ws.rs.core.EntityTag in project athenz by yahoo.
the class ZMSImpl method getSignedDomains.
@Override
public Response getSignedDomains(ResourceContext ctx, String domainName, String metaOnly, String metaAttr, Boolean master, Boolean conditions, String matchingTag) {
final String caller = ctx.getApiName();
logPrincipal(ctx);
validateRequest(ctx.request(), caller);
if (domainName != null) {
domainName = domainName.toLowerCase();
validate(domainName, TYPE_DOMAIN_NAME, caller);
setRequestDomain(ctx, domainName);
}
if (metaAttr != null) {
metaAttr = metaAttr.toLowerCase();
validate(metaAttr, TYPE_SIMPLE_NAME, caller);
}
boolean setMetaDataOnly = ZMSUtils.parseBoolean(metaOnly, false);
boolean includeConditions = Boolean.TRUE == conditions;
long timestamp = getModTimestamp(matchingTag);
// if this is one of our system principals then we're going
// to use the master copy instead of read-only replicas
// unless we're configured to always use read-only replicas
// for all signed domain operations
Principal principal = ((RsrcCtxWrapper) ctx).principal();
boolean masterCopy = (useMasterCopyForSignedDomains || master == Boolean.TRUE) && principal.getFullName().startsWith("sys.");
// if we're given a specific domain then we don't need to
// retrieve the list of modified domains
List<SignedDomain> sdList = new ArrayList<>();
Long youngestDomMod = -1L;
if (domainName != null && !domainName.isEmpty()) {
Domain domain = null;
try {
domain = dbService.getDomain(domainName, masterCopy);
} catch (ResourceException ex) {
if (ex.getCode() != ResourceException.NOT_FOUND) {
throw ex;
}
}
if (domain != null) {
youngestDomMod = domain.getModified().millis();
if (timestamp != 0 && youngestDomMod <= timestamp) {
EntityTag eTag = new EntityTag(domain.getModified().toString());
return Response.status(ResourceException.NOT_MODIFIED).header("ETag", eTag.toString()).build();
}
// generate our signed domain object
SignedDomain signedDomain = retrieveSignedDomain(domain, metaAttr, setMetaDataOnly, masterCopy, includeConditions);
if (signedDomain != null) {
sdList.add(signedDomain);
}
} else {
youngestDomMod = System.currentTimeMillis();
}
} else {
if (!setMetaDataOnly && !masterCopy) {
return Response.status(ResourceException.BAD_REQUEST).build();
}
if (matchingTag == null) {
EntityTag eTag = new EntityTag(Timestamp.fromMillis(0).toString());
matchingTag = eTag.toString();
}
DomainMetaList dmlist = dbService.listModifiedDomains(timestamp);
List<Domain> modlist = dmlist.getDomains();
if (modlist == null || modlist.size() == 0) {
return Response.status(ResourceException.NOT_MODIFIED).header("ETag", matchingTag).build();
}
for (Domain dmod : modlist) {
Long domModMillis = dmod.getModified().millis();
if (domModMillis.compareTo(youngestDomMod) > 0) {
youngestDomMod = domModMillis;
}
// generate our signed domain object
SignedDomain signedDomain = retrieveSignedDomain(dmod, metaAttr, setMetaDataOnly, masterCopy, includeConditions);
if (signedDomain == null) {
continue;
}
// we have a valid domain so we'll add it to our return list
sdList.add(signedDomain);
}
}
SignedDomains sdoms = new SignedDomains();
sdoms.setDomains(sdList);
Timestamp youngest = Timestamp.fromMillis(youngestDomMod);
EntityTag eTag = new EntityTag(youngest.toString());
return Response.status(ResourceException.OK).entity(sdoms).header("ETag", eTag.toString()).build();
}
use of javax.ws.rs.core.EntityTag in project athenz by yahoo.
the class ZMSImplTest method testGetSignedDomainsNotModified.
@Test
public void testGetSignedDomainsNotModified() {
TopLevelDomain dom1 = zmsTestInitializer.createTopLevelDomainObject("SignedDom1", "Test Domain1", "testOrg", zmsTestInitializer.getAdminUser());
zmsTestInitializer.getZms().postTopLevelDomain(zmsTestInitializer.getMockDomRsrcCtx(), zmsTestInitializer.getAuditRef(), dom1);
// set the meta attributes for domain
DomainMeta meta = zmsTestInitializer.createDomainMetaObject("Tenant Domain1", null, true, false, "12345", 0);
zmsTestInitializer.getZms().putDomainMeta(zmsTestInitializer.getMockDomRsrcCtx(), "signeddom1", zmsTestInitializer.getAuditRef(), meta);
zmsTestInitializer.getZms().privateKey = new ServerPrivateKey(Crypto.loadPrivateKey(Crypto.ybase64DecodeString(zmsTestInitializer.getPrivKey())), "0");
Authority principalAuthority = new com.yahoo.athenz.common.server.debug.DebugPrincipalAuthority();
Principal sysPrincipal = principalAuthority.authenticate("v=U1;d=sys;n=zts;s=signature", "10.11.12.13", "GET", null);
ResourceContext rsrcCtx = zmsTestInitializer.createResourceContext(sysPrincipal);
EntityTag eTag = new EntityTag(Timestamp.fromCurrentTime().toString());
Response response = zmsTestInitializer.getZms().getSignedDomains(rsrcCtx, "signeddom1", null, null, Boolean.TRUE, false, eTag.toString());
assertEquals(response.getStatus(), 304);
zmsTestInitializer.getZms().deleteTopLevelDomain(zmsTestInitializer.getMockDomRsrcCtx(), "SignedDom1", zmsTestInitializer.getAuditRef());
}
Aggregations