use of org.jboss.resteasy.security.doseta.Verification in project resteasy by resteasy.
the class LocalTest method testBadAttributes.
@Test
public void testBadAttributes() throws Exception {
DKIMSignature signed = new DKIMSignature();
signed.setAttribute("path", "/hello/world");
signed.setTimestamp();
signed.addHeader("Visa");
signed.addHeader("Visa");
MultivaluedMapImpl<String, String> headers = new MultivaluedMapImpl<String, String>();
headers.add("Visa", "v1");
headers.add("Visa", "v2");
headers.add("Visa", "v3");
signed.sign(headers, null, keys.getPrivate());
String signedHeader = signed.toString();
logger.info(signedHeader);
DKIMSignature verified = new DKIMSignature(signedHeader);
HashMap<String, String> requiredAttributes = new HashMap<String, String>();
requiredAttributes.put("path", "/hello/world");
Verification verification = new Verification();
verification.getRequiredAttributes().put("path", "/hello");
try {
verification.verify(verified, headers, null, keys.getPublic());
Assert.fail("Verification was successful, but it shoudn't be");
} catch (SignatureException e) {
}
}
use of org.jboss.resteasy.security.doseta.Verification in project resteasy by resteasy.
the class LocalTest method testAttributes.
@Test
public void testAttributes() throws Exception {
DKIMSignature signed = new DKIMSignature();
signed.setAttribute("path", "/hello/world");
signed.setTimestamp();
signed.addHeader("Visa");
signed.addHeader("Visa");
MultivaluedMapImpl<String, String> headers = new MultivaluedMapImpl<String, String>();
headers.add("Visa", "v1");
headers.add("Visa", "v2");
headers.add("Visa", "v3");
signed.sign(headers, null, keys.getPrivate());
String signedHeader = signed.toString();
logger.info(signedHeader);
DKIMSignature verified = new DKIMSignature(signedHeader);
HashMap<String, String> requiredAttributes = new HashMap<String, String>();
requiredAttributes.put("path", "/hello/world");
Verification verification = new Verification();
verification.getRequiredAttributes().put("path", "/hello/world");
MultivaluedMap<String, String> verifiedHeaders = verification.verify(verified, headers, null, keys.getPublic());
Assert.assertEquals(verifiedHeaders.size(), 1);
List<String> visas = verifiedHeaders.get("Visa");
Assert.assertNotNull(ERROR_MSG, visas);
Assert.assertEquals(ERROR_MSG, visas.size(), 2);
logger.info(visas);
Assert.assertEquals(ERROR_MSG, visas.get(0), "v3");
Assert.assertEquals(ERROR_MSG, visas.get(1), "v2");
}
use of org.jboss.resteasy.security.doseta.Verification in project resteasy by resteasy.
the class SigningTest method testExpiresHour.
@Test
public void testExpiresHour() throws Exception {
Verifier verifier = new Verifier();
Verification verification = verifier.addNew();
verification.setRepository(repository);
// ResteasyClientImpl client = new ResteasyClientImpl();
WebTarget target = client.target(TestPortProvider.generateURL("/signed/expires-hour"));
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());
String output = response.readEntity(String.class);
response.close();
}
use of org.jboss.resteasy.security.doseta.Verification in project resteasy by resteasy.
the class SigningTest method testManual.
@Test
public void testManual() throws Exception {
Verifier verifier = new Verifier();
Verification verification = verifier.addNew();
verification.setRepository(repository);
// ResteasyClientImpl client = new ResteasyClientImpl();
WebTarget target = client.target(TestPortProvider.generateURL("/signed/manual"));
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", output);
response.close();
}
use of org.jboss.resteasy.security.doseta.Verification in project resteasy by resteasy.
the class SigningTest method testExpiresMinutes.
@Test
public void testExpiresMinutes() throws Exception {
Verifier verifier = new Verifier();
Verification verification = verifier.addNew();
verification.setRepository(repository);
// ResteasyClientImpl client = new ResteasyClientImpl();
WebTarget target = client.target(TestPortProvider.generateURL("/signed/expires-minute"));
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());
String output = response.readEntity(String.class);
response.close();
}
Aggregations