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

test: set up test suite with Jest and MSW #24

Merged
merged 9 commits into from
Apr 10, 2023
Merged

test: set up test suite with Jest and MSW #24

merged 9 commits into from
Apr 10, 2023

Conversation

mantariksh
Copy link
Contributor

@mantariksh mantariksh commented Mar 30, 2023

Problem

Tests are good but we don't have them. Also, as we develop new SDKs, it will be useful to have consistent test cases as a reference point for implementation.

Solution

I considered two possible approaches:

  1. Mock openid-client and check that we are interacting with it correctly
  2. Mock network requests and ensure that the SDK returns the correct outputs

I went with approach 2 because 1 doesn't test for the possibility that openid-client introduces a bug or change in behaviour.

I chose msw to mock network requests instead of digging into the internals of openid-client and mocking whatever HTTP library they use (the native NodeJS HTTP API), as this allows us to stay agnostic to openid-client's internal implementation and just mock API responses.

Also, tests are now part of CI pipeline. See "Test" GitHub action.

Build changes
To include the test directory in the TS project but exclude it from the build pipeline, I set tsconfig.json to include tests, but created a new tsconfig.build.json which excludes tests and used it in npm run build.

New dev dependencies:

  • jest, ts-jest, msw: for test framework in TypeScript
  • jsonwebtoken: for generating testing data (sign ID token)
  • eslint-plugin-jest: to write test nice nice

@mantariksh mantariksh requested a review from kwajiehao March 30, 2023 01:51
@gitguardian
Copy link

gitguardian bot commented Mar 30, 2023

⚠️ GitGuardian has uncovered 3 secrets following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

🔎 Detected hardcoded secrets in your pull request
GitGuardian id Secret Commit Filename
6175562 Generic Private Key 0cd6f8d test/mocks/mockClientKeys.json View secret
6175563 RSA Private Key 0cd6f8d test/mocks/mockPrivateKey.pem View secret
6175564 Generic Private Key 0cd6f8d test/mocks/mockPrivateKeyPkcs8.pem View secret
🛠 Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secrets safely. Learn here the best practices.
  3. Revoke and rotate these secrets.
  4. If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.

To avoid such incidents in the future consider


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

Our GitHub checks need improvements? Share your feedbacks!

@mantariksh mantariksh requested a review from kschiew March 30, 2023 02:00
@mantariksh mantariksh requested review from PrawiraGenestonlia and removed request for kschiew March 30, 2023 10:44
@kwajiehao kwajiehao removed their request for review April 5, 2023 02:26
@mantariksh
Copy link
Contributor Author

@PrawiraGenestonlia thanks for the thoughtful review! left some of the comments open for discussion

@mantariksh mantariksh merged commit b471577 into develop Apr 10, 2023
@mantariksh mantariksh deleted the test/setup branch April 25, 2023 03:04
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