fix to JwtTest unit test

pull/59/head
nemonik 2012-03-29 12:54:03 -04:00
parent f215cfc50c
commit 1209e9a83f
1 changed files with 53 additions and 44 deletions

View File

@ -6,6 +6,7 @@ import static org.junit.Assert.assertThat;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.math.BigInteger; import java.math.BigInteger;
import java.security.KeyFactory; import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey; import java.security.PrivateKey;
import java.security.PublicKey; import java.security.PublicKey;
import java.security.cert.X509Certificate; import java.security.cert.X509Certificate;
@ -46,17 +47,14 @@ public class JwtTest {
jwt.getClaims().setIssuer("joe"); jwt.getClaims().setIssuer("joe");
jwt.getClaims().setClaim("http://example.com/is_root", Boolean.TRUE); jwt.getClaims().setClaim("http://example.com/is_root", Boolean.TRUE);
// sign it
byte[] key = null; byte[] key = null;
JwtSigner signer;
// sign it
try { try {
key = "secret".getBytes("UTF-8"); key = "secret".getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
JwtSigner signer = new HmacSigner(key);
signer = new HmacSigner(key);
signer.sign(jwt); signer.sign(jwt);
/* /*
@ -77,6 +75,11 @@ public class JwtTest {
assertThat(actual, equalTo(expected)); assertThat(actual, equalTo(expected));
assertThat(jwt.getSignature(), equalTo(signature)); assertThat(jwt.getSignature(), equalTo(signature));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
} }
/** /**
@ -214,16 +217,15 @@ public class JwtTest {
@Test @Test
public void testValidateHmacSignature() { public void testValidateHmacSignature() {
// sign it
byte[] key = null; byte[] key = null;
JwtSigner signer;
// sign it
try { try {
key = "secret".getBytes("UTF-8"); key = "secret".getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
JwtSigner signer = new HmacSigner(key); signer = new HmacSigner(key);
/* /*
* Token string based on the following strucutres, serialized exactly as * Token string based on the following strucutres, serialized exactly as
@ -240,6 +242,13 @@ public class JwtTest {
assertThat(valid, equalTo(Boolean.TRUE)); assertThat(valid, equalTo(Boolean.TRUE));
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} }
@Test @Test