From 97063fd8d13d110b4b39300e4c298d43fef4c96c Mon Sep 17 00:00:00 2001 From: LoneRifle Date: Mon, 10 Sep 2018 10:51:43 +0800 Subject: [PATCH] Tweak assertion values, allow overrides via env vars --- README.md | 6 +++++- lib/assertions.js | 14 ++++++++++---- package.json | 2 +- static/saml/corppass.xml | 4 ++-- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index fcd3ce0..33da6b6 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,11 @@ $ npm install @opengovsg/mockpass $ export SINGPASS_ASSERT_ENDPOINT=http://localhost:5000/singpass/assert $ export CORPPASS_ASSERT_ENDPOINT=http://localhost:5000/corppass/assert -$ export MOCKPASS_PORT=5156 # Defaults to 5156 +# All values shown here are defaults +$ export MOCKPASS_PORT=5156 +$ export MOCKPASS_NRIC=S8979373D +$ export MOCKPASS_UEN=123456789A + $ export SHOW_LOGIN_PAGE=true # Optional $ npx mockpass diff --git a/lib/assertions.js b/lib/assertions.js index 58410b5..e60d7d8 100644 --- a/lib/assertions.js +++ b/lib/assertions.js @@ -3,11 +3,17 @@ const fs = require('fs') const { render } = require('mustache') const path = require('path') -const TEMPLATE = fs.readFileSync(path.resolve(__dirname, '../static/saml/unsigned-assertion.xml'), 'utf8') +const readFrom = p => fs.readFileSync(path.resolve(__dirname, p), 'utf8') -const CORPPASS = base64.encode(fs.readFileSync(path.resolve(__dirname, '../static/saml/corppass.xml'), 'utf8')) +const TEMPLATE = readFrom('../static/saml/unsigned-assertion.xml') +const corpPassTemplate = readFrom('../static/saml/corppass.xml') + +const NRIC = process.env.MOCKPASS_NRIC || 'S8979373D' +const UEN = process.env.MOCKPASS_UEN || '123456789A' + +const CORPPASS = base64.encode(render(corpPassTemplate, { NRIC, UEN })) module.exports = { - singPass: render(TEMPLATE, { name: 'UserName', value: 'S1234567A' }), - corpPass: render(TEMPLATE, { name: '123456789A', value: CORPPASS }), + singPass: render(TEMPLATE, { name: 'UserName', value: NRIC }), + corpPass: render(TEMPLATE, { name: UEN, value: CORPPASS }), } diff --git a/package.json b/package.json index 5d33454..2663ef5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@opengovsg/mockpass", - "version": "1.0.1", + "version": "1.0.2", "description": "A mock SingPass/CorpPass server for dev purposes", "main": "index.js", "bin": { diff --git a/static/saml/corppass.xml b/static/saml/corppass.xml index e2549ba..8824c4b 100644 --- a/static/saml/corppass.xml +++ b/static/saml/corppass.xml @@ -1,6 +1,6 @@ - S1234567A - 123456789G + {{ NRIC }} + {{ UEN }}