Skip to content

Commit

Permalink
fix: Proxy-Authorization token expired issue for cached destination (
Browse files Browse the repository at this point in the history
…#5563)

* feat: use existing proxy authorization header if not expired

* fix: lint

* chore: add changeset

* fix: remove expiration check

* fix: lint

* fix: lint

* revert
  • Loading branch information
ZhongpinWang authored Feb 27, 2025
1 parent 592de1d commit 438ebd8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/salty-teams-follow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sap-cloud-sdk/connectivity': patch
---

[Fixed Issue] Add `proxyConfiguration` on the fly to avoid expired proxy authorization token in cached destination if it lives shorter than the token for destination service.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('connectivity-service', () => {

it('adds a proxy configuration containing at least the host, the port, and the "Proxy-Authorization" header to a destination', async () => {
mockServiceBindings();
mockServiceToken();
const serviceTokenSpy = mockServiceToken();

const input: Destination = {
url: 'https://example.com',
Expand All @@ -50,6 +50,7 @@ describe('connectivity-service', () => {

const withProxy = await addProxyConfigurationOnPrem(input);
expect(withProxy).toEqual(expected);
expect(serviceTokenSpy).toHaveBeenCalledTimes(1);
});

it('also contains the "SAP-Connectivity-Authentication" header if a JWT is present', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export class DestinationFromServiceRetriever {
setForwardedAuthTokenIfNeeded(destination, options.jwt);

if (destinationResult.fromCache) {
return destination;
return da.addProxyConfiguration(destination);
}

if (!destination.forwardAuthToken) {
Expand Down Expand Up @@ -153,13 +153,13 @@ export class DestinationFromServiceRetriever {
}
}

const withProxySetting = await da.addProxyConfiguration(destination);
const withTrustStore = await da.addTrustStoreConfiguration(
withProxySetting,
destination,
destinationResult.origin
);
await da.updateDestinationCache(withTrustStore, destinationResult.origin);
return withTrustStore;

return da.addProxyConfiguration(withTrustStore);
}

private static throwUserTokenMissing(destination) {
Expand Down

0 comments on commit 438ebd8

Please sign in to comment.