Created
December 16, 2016 14:19
-
-
Save darelf/b07d173126ee94fd1f0954b40c3be308 to your computer and use it in GitHub Desktop.
Sample unit test function for UserAuth.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void testJWT() throws Exception { | |
Calendar now = Calendar.getInstance(); | |
now.add(Calendar.SECOND, 20); | |
JsonObject obj = Json.object(); | |
obj.add("sub", "1234567890"); | |
obj.add("name", "John Doe"); | |
obj.add("admin", true); | |
obj.add("exp", now.getTimeInMillis()); | |
String user_data = obj.toString(); | |
String token = UserAuth.generateToken(user_data); | |
JsonObject result = UserAuth.validateToken(token); | |
assertTrue("Verify Token: ", result.getBoolean("verified", false)); | |
JsonObject payload = result.get("payload").asObject(); | |
assertEquals("Verify Name: ", payload.getString("name", ""), "John Doe"); | |
System.out.println("Expired? " + result.getBoolean("expired", false)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment