Skip to content

Pass optional tenant override to internal silent call#886

Merged
Avery-Dunn merged 6 commits intodevfrom
avdunn/tenant-override-fix
Dec 19, 2024
Merged

Pass optional tenant override to internal silent call#886
Avery-Dunn merged 6 commits intodevfrom
avdunn/tenant-override-fix

Conversation

@Avery-Dunn
Copy link
Copy Markdown
Contributor

Fixes an issue described in #881. Essentially, there is an API at the request level which overrides the tenant set at the application level.

However, in some confidential flows we internally make a silent call with a new SilentParameters object which did not receive the tenant that may have been set with that API.

This PR fixes the two places where that API wasn't getting properly passed to that internal silent call, adds a new test for that behavior, and makes a few unrelated fixes/improvements to some integration tests.

assertResultNotNull(resultOrganizations);
assertResultNotNull(resultOrganizationsCached);

assertNotEquals(resultNoOverride.accessToken(), resultOrganizations.accessToken());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: you really should get that improvement of exposing a fromCache flag in the auth result going. This string comparison is not great. ESTS-R for example caches tokens.

Copy link
Copy Markdown
Member

@bgavrilMS bgavrilMS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs a unit test

class OnBehalfOfTests {

private String getSuccessfulResponse(String accessToken) {
return "{\"access_token\":\""+accessToken+"\",\"expires_in\": \""+ 60*60*1000 +"\",\"token_type\":" +
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You also need to add a client_info, that is part of all user token protocols.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the latest commit this has been moved to TestHelper, and now has client_info, access/id/refresh tokens, etc.

SilentParameters parameters = SilentParameters
.builder(this.clientCredentialRequest.parameters.scopes())
.claims(this.clientCredentialRequest.parameters.claims())
.tenant(this.clientCredentialRequest.parameters.tenant())
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not tested.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added tests in the latest commit, essentially just a copy/paste of the OBO tests but use the type of Parameters that would go through this code.

Copy link
Copy Markdown
Member

@bgavrilMS bgavrilMS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More testing is needed.

.httpClient(httpClientMock)
.build();

when(httpClientMock.send(any(HttpRequest.class))).thenReturn(expectedResponse(200, getSuccessfulResponse("appTenantToken")));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should only return that response once, not all the time, i.e. assert that only 1 call to the token endpoint is made.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be more clear in the latest commit since I refactored some of the code, but the verify(httpClientMock, times(1)).send(any()); later on was verifying exactly that.

The 'send' method is essentially the final step which sends the request to the endpoint, and 'httpClientMock' was passed into the confidential client app so that mocked HTTP client is getting used for all HTTP calls in the test. So, verifying the number of times 'send' was called is just a quick way of counting the number of calls to the token endpoint.

//Signed JWT which should be enough to pass the parsing/validation in the library, useful if a unit test needs an
// assertion but that is not the focus of the test
static String signedAssertion = generateToken();
private static final String successfulResponseFormat = "{\"access_token\":\"%s\",\"id_token\":\"%s\",\"refresh_token\":\"%s\"," +
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: successfulUserTokenResponseFormat

Copy link
Copy Markdown
Member

@bgavrilMS bgavrilMS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still requires a test for client_credentials.

@Avery-Dunn Avery-Dunn requested a review from bgavrilMS December 18, 2024 21:45
@Avery-Dunn Avery-Dunn deleted the avdunn/tenant-override-fix branch January 21, 2025 21:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants