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

Refactor Jira OnPrem OAuth to add unit tests #622

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

jaller94
Copy link
Contributor

@jaller94 jaller94 commented Jan 12, 2023

  • Add unit tests for many functions of OnPremOAuth.ts.
  • Add some tests that mock HTTP server responses from Jira for an access token.
  • Refactor OnPremOAuth.ts to be simpler, safer and more testable.

Tip for reviewing: Pretend that this is new code – comparing it to the old code has become increasingly difficult. Test it with a Jira instance.

@jaller94 jaller94 requested a review from a team as a code owner January 12, 2023 00:08
return parameter.startsWith("oauth_");
}

export const makeArrayOfArgumentsHash = (argumentsHash: Map<string, string | string[]>): [string, string][] => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure why this is Map<string, string | string[]> instead of Map<string, string>.
Issue #621

This was an issue before and I didn't remove the support for string[].
Please let's not make that a blocker for this PR.

Comment on lines +215 to +219
mockServerResponse = {
oauth_token: "abc",
oauth_token_secret: "def",
};
const actual = await jiraOAuth.exchangeRequestForToken("foo", "bar");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If mocha runs the tests in parallel, this is a race condition with the other tests.

redirect_uri: "https://redirect",
};
// This private key is ONLY used for testing. It's safe to be published.
const privateKey = `-----BEGIN PRIVATE KEY-----
Copy link
Contributor Author

Choose a reason for hiding this comment

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

GitHub key scanner report coming in 10... 9... 8... 7...

As mentioned in the comment, I generated this key just for testing.

@jaller94 jaller94 changed the title Refactor Jira OAuth to add unit tests Refactor Jira OnPrem OAuth to add unit tests Jan 12, 2023
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.

None yet

1 participant