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.math.BigInteger;
import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.cert.X509Certificate;
@ -46,17 +47,14 @@ public class JwtTest {
jwt.getClaims().setIssuer("joe");
jwt.getClaims().setClaim("http://example.com/is_root", Boolean.TRUE);
// sign it
byte[] key = null;
JwtSigner signer;
// sign it
try {
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);
/*
@ -77,6 +75,11 @@ public class JwtTest {
assertThat(actual, equalTo(expected));
assertThat(jwt.getSignature(), equalTo(signature));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
}
/**
@ -214,16 +217,15 @@ public class JwtTest {
@Test
public void testValidateHmacSignature() {
// sign it
byte[] key = null;
JwtSigner signer;
// sign it
try {
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
@ -240,6 +242,13 @@ public class JwtTest {
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