oscerd commented on code in PR #29822:
URL: https://github.com/apache/camel/pull/29822#discussion_r4588728007


##########
components/camel-spiffe/src/main/java/org/apache/camel/component/spiffe/SpiffeProducer.java:
##########
@@ -68,10 +80,21 @@ private void fetchX509Svid(WorkloadApiClient client, 
Exchange exchange) throws E
 
     private void fetchJwtSvid(WorkloadApiClient client, Exchange exchange) 
throws Exception {
         String[] audiences = resolveAudiences(exchange);
-        JwtSvid svid = audiences.length > 1

Review Comment:
   Reordered in (f1c15454b38e): the two headers are cleared before 
`resolveAudiences`, as on the X.509 path.
   
   _Claude Code on behalf of oscerd_



##########
components/camel-spiffe/src/test/java/org/apache/camel/component/spiffe/SpiffeProducerTest.java:
##########
@@ -137,6 +139,29 @@ void fetchJwtSvid() throws Exception {
         
assertThat(out.getMessage().getHeader(SpiffeConstants.EXPIRY)).isEqualTo(expiry);
     }
 
+    @Test
+    void fetchJwtSvidMintsTheTokenForTheConfiguredLocalIdentity() throws 
Exception {
+        SpiffeId billing = SpiffeId.parse("spiffe://example.org/billing");
+        SpiffeId id = spiffeId("spiffe://example.org/billing");
+        Date expiry = new Date();
+        JwtSvid svid = mock(JwtSvid.class);
+        when(svid.getToken()).thenReturn("the-billing-token");
+        when(svid.getSpiffeId()).thenReturn(id);
+        when(svid.getExpiry()).thenReturn(expiry);
+        when(client.fetchJwtSvid(billing, "my-audience")).thenReturn(svid);
+
+        Exchange out = template.request(
+                
"spiffe:test?workloadApiClient=#client&operation=fetchJwtSvid&audience=my-audience"
+                                        + 
"&localSpiffeId=spiffe://example.org/billing",
+                e -> e.getMessage().setHeader(SpiffeConstants.SPIFFE_ID, 
"stale-identity"));
+
+        
assertThat(out.getMessage().getBody(String.class)).isEqualTo("the-billing-token");
+        
assertThat(out.getMessage().getHeader(SpiffeConstants.SPIFFE_ID)).isEqualTo("spiffe://example.org/billing");
+        
assertThat(out.getMessage().getHeader(SpiffeConstants.EXPIRY)).isEqualTo(expiry);
+        // the default identity is never asked for
+        verify(client, never()).fetchJwtSvid("my-audience");
+    }
+

Review Comment:
   Added in (f1c15454b38e): `fetchJwtSvidClearsTheIdentityHeadersWhenItFails` 
covers a failing fetch and a missing audience, asserting both headers are null.
   
   _Claude Code on behalf of oscerd_



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to