-
Notifications
You must be signed in to change notification settings - Fork 6
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
Conversation
|
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
- Understand the implications of revoking this secret by investigating where it is used in your code.
- Replace and store your secrets safely. Learn here the best practices.
- Revoke and rotate these secrets.
- 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
- following these best practices for managing and storing secrets including API keys and other credentials
- install secret detection on pre-commit to catch secret before it leaves your machine and ease remediation.
🦉 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!
@PrawiraGenestonlia thanks for the thoughtful review! left some of the comments open for discussion |
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:
openid-client
and check that we are interacting with it correctlyI 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 ofopenid-client
and mocking whatever HTTP library they use (the native NodeJS HTTP API), as this allows us to stay agnostic toopenid-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 newtsconfig.build.json
which excludes tests and used it innpm run build
.New dev dependencies:
jest
,ts-jest
,msw
: for test framework in TypeScriptjsonwebtoken
: for generating testing data (sign ID token)eslint-plugin-jest
: to write test nice nice