Skip to content

Commit 2a428d4

Browse files
Merge pull request #30 from bcgov/SSOTEAM-2795
chore: document local env
2 parents f1162a0 + 3b248ec commit 2a428d4

9 files changed

Lines changed: 394 additions & 7 deletions

File tree

.bin/db-setup.sh

100644100755
File mode changed.

.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ NODE_ENV=development
88
APP_URL=http://localhost:8080
99
LOG_LEVEL=info
1010
COOKIE_SECRETS="s3cr3t1,s3cr3t1,s3cr3t2"
11-
JWKS=
11+
JWKS={"json string generated by the jwks-generator"}
1212
CORS_ORIGINS=*
1313
HASH_SALT=
1414
AWS_REGION=ca-central-1

Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
SHELL := /usr/bin/env bash
2+
3+
.PHONY: test_db
4+
test_db:
5+
pg_ctl start
6+
createdb -U postgres runner || true
7+
@cd .bin; chmod +x ./db-setup.sh
8+
psql -U postgres -c 'drop database if exists otp_test';
9+
@cd .bin; ./db-setup.sh otp_test
10+
11+
.PHONY: unit_test
12+
unit_test:
13+
yarn test

README.md

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,13 @@ OTP Provider -> Authenticates user via email-based OTP and returns identity asse
5959
### Steps
6060

6161
1. Create `.env` from `.env.example` and update all the values
62-
2. Run `yarn` to install all the dependencies
63-
3. Run `yarn dev` to start a local server
64-
4. Run `yarn build` to create a javascript bundle for production deployment
65-
5. Run `yarn start` to run the javascript bundle
66-
6. Run `yarn tailwind` to compile the css (will hot reload)
62+
2. Generate a local `JWKS={}` env variable for the `.env` file using the the script in the [./jwks-generator](./jwks-generator/) folder.
63+
3. Run `yarn` to install all the dependencies
64+
4. Run `yarn tailwind` on first build of project otherwise yarn build will fail due to missing css files.
65+
5. Run `yarn dev` to start a local server
66+
6. Run `yarn build` to create a javascript bundle for production deployment
67+
7. Run `yarn start` to run the javascript bundle
68+
8. Run `yarn tailwind` to compile the css (will hot reload)
6769

6870
## AWS Simple Email Service
6971

@@ -84,6 +86,16 @@ OTP Provider -> Authenticates user via email-based OTP and returns identity asse
8486

8587
The app runs locally using tsup to compile the server and client files into the `build` directory. To recompile the css on the fly, run `yarn tailwind` in another terminal.
8688

89+
## Local Unit tests
90+
91+
The local tests are built and run using:
92+
93+
`make test_db`
94+
95+
and
96+
97+
`make unit_test`
98+
8799
## Test Data
88100

89101
- Given the application and database are up and database migration is successfully complete, run below SQL to add a client for testing purposes.
@@ -141,7 +153,7 @@ End to end testing is done with playwright. As prerequisite the end-to-end tests
141153

142154
- `psql -c 'create database otp_test'`;
143155
- `yarn build && DB_NAME=otp_test node build/migrate.js`
144-
- `psql -d otp_test -f e2e/seed.sql`
156+
- `psql -U postgres -d otp_test -f e2e/seed.sql`
145157

146158
This is only needed the first time to initialize the db. To run the tests run `yarn test:e2e`
147159

jwks-generator/Readme.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
This javascript snippet allows a user to generate the JWKS json environment variable.
2+
3+
Run two commands
4+
5+
`yarn install`
6+
7+
and
8+
9+
`node jwks-generator.js `
10+
11+
To generate the JWKS env variable for a local otp server. This environment variable is not wrapped in quotes in the .en file. **Note: the local server requires the private keys to run**

jwks-generator/jwks-generator.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const jose = require('node-jose');
2+
3+
async function createKeystore() {
4+
const keystore = jose.JWK.createKeyStore();
5+
6+
// Generate a new RSA key
7+
await keystore.generate('RSA', 2048, { alg: 'RS256', use: 'sig' });
8+
9+
// Export the public key set (pass 'false' to exclude private keys)
10+
const jwks = keystore.toJSON(true);
11+
console.log(JSON.stringify(jwks, null, 2).replace(/[\r\n]+/g, ' '));
12+
}
13+
14+
createKeystore();

jwks-generator/package-lock.json

Lines changed: 240 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jwks-generator/package.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "otp-stuff",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "jwks-generator.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"keywords": [],
10+
"author": "",
11+
"license": "ISC",
12+
"dependencies": {
13+
"jose": "^6.2.2",
14+
"node-jose": "^2.2.0"
15+
}
16+
}

0 commit comments

Comments
 (0)