Skip to content

Commit

Permalink
Modify the test of jwk and remove useless comments
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Liang <jiallian@amazon.com>
  • Loading branch information
RyanL1997 committed Oct 9, 2023
1 parent d404014 commit 7bf71ba
Showing 1 changed file with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ public class JwtVendorTest {
private Appender mockAppender;
private ArgumentCaptor<LogEvent> logEventCaptor;

@Test
public void testJsonWebKeyPropertiesSetFromJwkSettings() throws Exception {
Settings settings = Settings.builder().put("jwt.key.key1", "value1").put("jwt.key.key2", "value2").build();

JsonWebKey jwk = JwtVendor.createJwkFromSettings(settings);

Assert.assertEquals("value1", jwk.getProperty("key1"));
Assert.assertEquals("value2", jwk.getProperty("key2"));
}

@Test
public void testJsonWebKeyPropertiesSetFromSettings() {
Settings jwkSettings = Settings.builder().put("key1", "value1").put("key2", "value2").build();
Expand Down Expand Up @@ -258,21 +268,17 @@ public void testCreateJwtLogsCorrectly() throws Exception {
List<String> backendRoles = List.of("Sales", "Support");
int expirySeconds = 300;

// Create instance of JwtVendor
JwtVendor jwtVendor = new JwtVendor(settings, Optional.of(currentTime));

// Call the method under test
jwtVendor.createJwt(issuer, subject, audience, expirySeconds, roles, backendRoles, false);

// Verify the log was captured
verify(mockAppender, times(1)).append(logEventCaptor.capture());

// Check the log message
LogEvent logEvent = logEventCaptor.getValue();
String logMessage = logEvent.getMessage().getFormattedMessage();
Assert.assertTrue(logMessage.startsWith("Created JWT:"));

String[] parts = logMessage.split("\\.");
Assert.assertTrue(parts.length >= 3); // JWTs typically have 3 parts: Header.Payload.Signature
Assert.assertTrue(parts.length >= 3);
}
}

0 comments on commit 7bf71ba

Please sign in to comment.