Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI: Test business logic for oidc callback params #19727

Merged
merged 7 commits into from
Mar 27, 2023

Conversation

hashishaw
Copy link
Contributor

@hashishaw hashishaw commented Mar 23, 2023

This PR moves the logic that happens in beforeModel for the oidc callback route into an easily-testable method.

Co-authored-by: claire bontempo <[email protected]>
@hashishaw hashishaw changed the title Strip out business logic of oidc-callback into testable method UI: Test business logic for oidc callback params Mar 23, 2023
@hashishaw hashishaw added this to the 1.14 milestone Mar 23, 2023
@hashishaw hashishaw marked this pull request as ready for review March 23, 2023 21:09
Copy link
Contributor

@hellobontempo hellobontempo left a comment

Choose a reason for hiding this comment

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

Thank you so much for working on this! 🙏

Just some questions, nothing blocking

path: 'oidc-path',
namespace: 'my-namespace',
};
const results = getParamsForCallback(params, '?code=my-code&state=my-state&namespace=my-namespace');
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if the namespace in the search string should be different from the namespace in the params so we are testing it's correctly preferring the namespace from the query string? But I see below there's a test for that so I'm not exactly sure what we're testing for here 🤔 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The string is basically the expected URL, and the namespace in the params is what the Ember route parses from the URL. So we're not testing differences here, just trying to match the real world scenario :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah - so many params! I got mixed up because I thought the queryString passed to getParamsForCallback was always whatever was from window.location.search and I never saw namespace= as part of that search string

test('it parses params correctly with regular inputs and namespace in state (unencoded)', function (assert) {
const searchString = '?code=my-code&state=my-state,ns=foo/bar';
const params = {
state: 'my-state,ns', // Ember parses the QP incorrectly if unencoded
Copy link
Contributor

Choose a reason for hiding this comment

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

🤩

});
});

test('namespace in state takes precedence over namespace in route (unencoded)', function (assert) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I haven't seen the namespace sent in the route like this! When does this happen?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When the URL includes the namespace parameter that's the "in route" version. It might not be an actual case in the wild, but behaviorally the method overwrites the route namespace param with the one in state so I wanted to capture that behavior as expected

Copy link
Contributor

Choose a reason for hiding this comment

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

Gotcha! Thanks for explaining 😄

@hashishaw hashishaw enabled auto-merge (squash) March 24, 2023 16:45
@hashishaw hashishaw disabled auto-merge March 27, 2023 17:41
@hashishaw hashishaw enabled auto-merge (squash) March 27, 2023 17:56
@hashishaw hashishaw disabled auto-merge March 27, 2023 17:56
@hashishaw hashishaw merged commit 61b152c into main Mar 27, 2023
@hashishaw hashishaw deleted the ui/oidc-callback-fn-tests branch March 27, 2023 20:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants