Esempio n. 1
0
 @Test
 public void testMultipleSecrets() throws Exception {
   TestSignerSecretProvider secretProvider = new TestSignerSecretProvider();
   Signer signer = new Signer(secretProvider);
   secretProvider.setCurrentSecret("secretB");
   String t1 = "test";
   String s1 = signer.sign(t1);
   String e1 = signer.verifyAndExtract(s1);
   Assert.assertEquals(t1, e1);
   secretProvider.setPreviousSecret("secretA");
   String t2 = "test";
   String s2 = signer.sign(t2);
   String e2 = signer.verifyAndExtract(s2);
   Assert.assertEquals(t2, e2);
   Assert.assertEquals(s1, s2); // check is using current secret for signing
   secretProvider.setCurrentSecret("secretC");
   secretProvider.setPreviousSecret("secretB");
   String t3 = "test";
   String s3 = signer.sign(t3);
   String e3 = signer.verifyAndExtract(s3);
   Assert.assertEquals(t3, e3);
   Assert.assertNotEquals(s1, s3); // check not using current secret for signing
   String e1b = signer.verifyAndExtract(s1);
   Assert.assertEquals(t1, e1b); // previous secret still valid
   secretProvider.setCurrentSecret("secretD");
   secretProvider.setPreviousSecret("secretC");
   try {
     signer.verifyAndExtract(s1); // previous secret no longer valid
     Assert.fail();
   } catch (SignerException ex) {
     // Expected
   }
 }
Esempio n. 2
0
 @Test
 public void testVerify() throws Exception {
   Signer signer = new Signer(createStringSignerSecretProvider());
   String t = "test";
   String s = signer.sign(t);
   String e = signer.verifyAndExtract(s);
   Assert.assertEquals(t, e);
 }
Esempio n. 3
0
 @Test
 public void testInvalidSignedText() throws Exception {
   Signer signer = new Signer(createStringSignerSecretProvider());
   try {
     signer.verifyAndExtract("test");
     Assert.fail();
   } catch (SignerException ex) {
     // Expected
   } catch (Throwable ex) {
     Assert.fail();
   }
 }
Esempio n. 4
0
 @Test
 public void testTampering() throws Exception {
   Signer signer = new Signer(createStringSignerSecretProvider());
   String t = "test";
   String s = signer.sign(t);
   s += "x";
   try {
     signer.verifyAndExtract(s);
     Assert.fail();
   } catch (SignerException ex) {
     // Expected
   } catch (Throwable ex) {
     Assert.fail();
   }
 }