Skip to content

Commit

Permalink
Fix timestamp interval of tests. Add tests for PublicKeyAuthenticator
Browse files Browse the repository at this point in the history
  • Loading branch information
Timon Hackenjos committed Feb 18, 2017
1 parent 1c516ff commit 7c99f7a
Showing 1 changed file with 44 additions and 4 deletions.
48 changes: 44 additions & 4 deletions src/test/java/edu/kit/tm/ptp/auth/PublicKeyAuthenticatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,20 @@ public void testWrongSource() throws IOException, GeneralSecurityException {
assertEquals(false, auth2.authenticationMessageValid(authMessage));
}

@Test
public void testChangeSource() throws IOException, GeneralSecurityException {
auth.own = new Identifier("aaaaaaaaaaaaaaaa.onion");
auth.other = ptp2.getIdentifier();
AuthenticationMessage authMessage = auth.createAuthenticationMessage();

authMessage.source = ptp1.getIdentifier();

auth2.own = ptp2.getIdentifier();
auth2.other = ptp1.getIdentifier();

assertEquals(false, auth2.authenticationMessageValid(authMessage));
}

@Test
public void testInvalidSourceIdentifier() throws IOException, GeneralSecurityException {
auth.own = new Identifier("xyz");
Expand Down Expand Up @@ -163,14 +177,27 @@ public void testWrongDestination() throws IOException, GeneralSecurityException
assertEquals(false, auth2.authenticationMessageValid(authMessage));
}

@Test
public void testChangeDestination() throws GeneralSecurityException, UnsupportedEncodingException {
auth.own = ptp1.getIdentifier();
auth.other = new Identifier("aaaaaaaaaaaaaaaa.onion");
AuthenticationMessage authMessage = auth.createAuthenticationMessage();

authMessage.destination = ptp2.getIdentifier();

auth2.own = ptp2.getIdentifier();

assertEquals(false, auth2.authenticationMessageValid(authMessage));
}

@Test
public void testOldTimestamp() throws IOException, GeneralSecurityException {
auth.own = ptp1.getIdentifier();
auth.other = ptp2.getIdentifier();

// 2 minutes old authenticator
// 4 minutes old authenticator
AuthenticationMessage authMessage =
auth.createAuthenticationMessage(System.currentTimeMillis() - 120 * 1000);
auth.createAuthenticationMessage(System.currentTimeMillis() - 4 * 60 * 1000);

auth2.own = ptp2.getIdentifier();

Expand All @@ -182,9 +209,9 @@ public void testFutureTimestamp() throws IOException, GeneralSecurityException {
auth.own = ptp1.getIdentifier();
auth.other = ptp2.getIdentifier();

// timestamp 2 minutes in the future
// timestamp 4 minutes in the future
AuthenticationMessage authMessage =
auth.createAuthenticationMessage(System.currentTimeMillis() + 120 * 1000);
auth.createAuthenticationMessage(System.currentTimeMillis() + 4 * 60 * 1000);

auth2.own = ptp2.getIdentifier();

Expand Down Expand Up @@ -227,4 +254,17 @@ public void testGetBytes() throws UnsupportedEncodingException {
assertArrayEquals(pubKey, pubKeyEncoded);
assertEquals(timestamp, timestampEncoded);
}

@Test
public void testChangePublicKey() throws GeneralSecurityException, UnsupportedEncodingException {
auth.own = ptp1.getIdentifier();
auth.other = ptp2.getIdentifier();
AuthenticationMessage authMessage = auth.createAuthenticationMessage();

authMessage.pubKey = cryptHelper2.getPublicKeyBytes();

auth2.own = ptp2.getIdentifier();

assertEquals(false, auth2.authenticationMessageValid(authMessage));
}
}

0 comments on commit 7c99f7a

Please sign in to comment.