use of org.jboss.resteasy.security.doseta.Verification in project resteasy by resteasy.
the class SigningTest method testManualWithHeader.
@Test
public void testManualWithHeader() throws Exception {
Verifier verifier = new Verifier();
Verification verification = verifier.addNew();
verification.setRepository(repository);
// ResteasyClientImpl client = new ResteasyClientImpl();
WebTarget target = client.target(TestPortProvider.generateURL("/signed/header"));
Invocation.Builder request = target.request();
request.property(Verifier.class.getName(), verifier);
Response response = request.get();
// System.out.println(response.getHeaderString(DKIMSignature.DKIM_SIGNATURE));
Assert.assertNotNull(response.getHeaderString(DKIMSignature.DKIM_SIGNATURE));
Assert.assertEquals(200, response.getStatus());
String output = response.readEntity(String.class);
Assert.assertEquals("hello world", output);
response.close();
}
use of org.jboss.resteasy.security.doseta.Verification in project resteasy by resteasy.
the class SigningTest method testRequestOnly.
@Test
public void testRequestOnly() throws Exception {
// ResteasyClientImpl client = new ResteasyClientImpl();
WebTarget target = client.target(TestPortProvider.generateURL("/signed/request-only"));
DKIMSignature contentSignature = new DKIMSignature();
contentSignature.setDomain("samplezone.org");
contentSignature.setSelector("test");
contentSignature.setPrivateKey(keys.getPrivate());
contentSignature.setBodyHashRequired(false);
contentSignature.setAttribute("method", "GET");
contentSignature.setAttribute("uri", "/signed/request-only");
contentSignature.setAttribute("token", "1122");
Response response = target.request().header(DKIMSignature.DKIM_SIGNATURE, contentSignature).delete();
Assert.assertEquals(200, response.getStatus());
String signatureHeader = (String) response.getHeaderString(DKIMSignature.DKIM_SIGNATURE);
contentSignature = new DKIMSignature(signatureHeader);
Verification verification = new Verification(keys.getPublic());
verification.setBodyHashRequired(false);
verification.getRequiredAttributes().put("token", "1122");
verification.verify(contentSignature, response.getStringHeaders(), null, keys.getPublic());
response.close();
}
use of org.jboss.resteasy.security.doseta.Verification in project resteasy by resteasy.
the class SigningTest method testTimestamp.
@Test
public void testTimestamp() throws Exception {
Verifier verifier = new Verifier();
Verification verification = verifier.addNew();
verification.setRepository(repository);
verification.setStaleCheck(true);
verification.setStaleSeconds(100);
// ResteasyClientImpl client = new ResteasyClientImpl();
WebTarget target = client.target(TestPortProvider.generateURL("/signed/stamped"));
Invocation.Builder request = target.request();
request.property(Verifier.class.getName(), verifier);
Response response = request.get();
// System.out.println(response.getHeaderString(DKIMSignature.DKIM_SIGNATURE));
Assert.assertEquals(200, response.getStatus());
try {
String output = response.readEntity(String.class);
} catch (Exception e) {
throw e;
}
response.close();
}
use of org.jboss.resteasy.security.doseta.Verification in project resteasy by resteasy.
the class SigningTest method testStaleTimestamp.
/**
* @tpTestDetails Stale timestamp test
* @tpSince RESTEasy 3.0.16
*/
@Test
public void testStaleTimestamp() throws Exception {
Verifier verifier = new Verifier();
Verification verification = verifier.addNew();
verification.setRepository(repository);
verification.setStaleCheck(true);
verification.setStaleSeconds(1);
WebTarget target = client.target(generateURL("/signed/stamped"));
Invocation.Builder request = target.request();
request.property(Verifier.class.getName(), verifier);
Response response = request.get();
logger.info(response.getHeaderString(DKIMSignature.DKIM_SIGNATURE));
Assert.assertEquals(HttpResponseCodes.SC_OK, response.getStatus());
Thread.sleep(1500);
try {
response.readEntity(String.class);
Assert.fail("Validation error excepted.");
} catch (ProcessingException pe) {
UnauthorizedSignatureException e = (UnauthorizedSignatureException) pe.getCause();
MatcherAssert.assertThat("Unexcepted error", e.getMessage(), containsString("Failed to verify signatures:\r\n"));
MatcherAssert.assertThat("Unexcepted error", e.getMessage(), containsString("Signature is stale"));
}
response.close();
}
use of org.jboss.resteasy.security.doseta.Verification in project resteasy by resteasy.
the class SigningTest method testExpiresYears.
/**
* @tpTestDetails Year expiration test (expires attribute in Signed annotation in REST end-point is used).
* @tpSince RESTEasy 3.0.16
*/
@Test
public void testExpiresYears() throws Exception {
Verifier verifier = new Verifier();
Verification verification = verifier.addNew();
verification.setRepository(repository);
WebTarget target = client.target(generateURL("/signed/expires-year"));
Invocation.Builder request = target.request();
request.property(Verifier.class.getName(), verifier);
Response response = request.get();
logger.info(response.getHeaderString(DKIMSignature.DKIM_SIGNATURE));
Assert.assertEquals(HttpResponseCodes.SC_OK, response.getStatus());
response.readEntity(String.class);
response.close();
}
Aggregations