Address PR review comments · grpc/grpc-java@9f2a2e9 · GitHub
Skip to content

Commit 9f2a2e9

Browse files
khush2520AI
authored andcommitted
Address PR review comments
1 parent c9803c2 commit 9f2a2e9

3 files changed

Lines changed: 134 additions & 15 deletions

File tree

‎auth/src/main/java/io/grpc/auth/JwtTokenFileCallCredentials.java‎

Lines changed: 26 additions & 14 deletions

‎auth/src/test/java/io/grpc/auth/JwtTokenFileCallCredentialsTest.java‎

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ public void applyMetadata_fileReadError_backoff() throws Exception {
284284
assertEquals(0, executor.runnables.size());
285285

286286
// 3. Move time past backoff limit (t=11001)
287-
timeProvider.set(11001);
287+
timeProvider.set(15000);
288288
MetadataApplier applier3 = Mockito.mock(MetadataApplier.class);
289289
credentials.applyRequestMetadata(requestInfo, executor, applier3);
290290
// Should NOT fail fast. Instead, it should trigger a new attempt.
@@ -604,4 +604,49 @@ public void applyMetadata_fileContentTooLarge_failsUnavailable() throws Exceptio
604604
assertTrue(status.getDescription().contains("Failed to read token file"));
605605
assertTrue(status.getCause().getMessage().contains("File size exceeds 1 MB limit"));
606606
}
607+
608+
@Test
609+
public void emptyTokenFileThrowsIllegalArgumentException() throws Exception {
610+
File emptyFile = File.createTempFile("emptyToken", ".jwt", tempFolder.getRoot());
611+
emptyFile.deleteOnExit();
612+
613+
JwtTokenFileCallCredentials credentials =
614+
new JwtTokenFileCallCredentials(emptyFile.getAbsolutePath(), timeProvider);
615+
616+
RequestInfoImpl requestInfo = new RequestInfoImpl(SecurityLevel.PRIVACY_AND_INTEGRITY);
617+
credentials.applyRequestMetadata(requestInfo, executor, applier1);
618+
assertEquals(1, executor.runnables.size());
619+
executor.runNext();
620+
621+
verify(applier1).fail(statusCaptor.capture());
622+
Status status = statusCaptor.getValue();
623+
assertEquals(Status.Code.UNAUTHENTICATED, status.getCode());
624+
assertTrue(status.getCause() instanceof IllegalArgumentException);
625+
}
626+
627+
@Test
628+
public void largeExpClaimClampsToLongMaxValue() throws Exception {
629+
String header = "eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0"; // {"alg":"none","typ":"JWT"}
630+
String payload = "eyJleHAiOjk5OTk5OTk5OTk5OTk5OTl9"; // {"exp":9999999999999999}
631+
String token = header + "." + payload + ".";
632+
633+
File tokenFile = File.createTempFile("largeExpToken", ".jwt", tempFolder.getRoot());
634+
tokenFile.deleteOnExit();
635+
java.nio.file.Files.write(tokenFile.toPath(),
636+
token.getBytes(java.nio.charset.StandardCharsets.UTF_8));
637+
638+
timeProvider.currentTimeMillis = 0;
639+
JwtTokenFileCallCredentials credentials =
640+
new JwtTokenFileCallCredentials(tokenFile.getAbsolutePath(), timeProvider);
641+
642+
RequestInfoImpl requestInfo = new RequestInfoImpl(SecurityLevel.PRIVACY_AND_INTEGRITY);
643+
credentials.applyRequestMetadata(requestInfo, executor, applier1);
644+
assertEquals(1, executor.runnables.size());
645+
executor.runNext();
646+
647+
verify(applier1).apply(any(io.grpc.Metadata.class));
648+
// The credentials logic doesn't easily expose the clamped value directly to this test without
649+
// waiting or mocking, but it prevents overflow crash
650+
// and parses successfully instead of returning an error.
651+
}
607652
}

‎xds/src/test/java/io/grpc/xds/GrpcBootstrapperImplTest.java‎

Lines changed: 62 additions & 0 deletions

0 commit comments

Comments
 (0)