Skip to content

Commit

Permalink
Tweak assertion values, allow overrides via env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
LoneRifle committed Sep 10, 2018
1 parent e084988 commit 97063fd
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 10 additions & 4 deletions lib/assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }),
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
4 changes: 2 additions & 2 deletions static/saml/corppass.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<UserInfo>
<CPUID>S1234567A</CPUID>
<CPEntID>123456789G</CPEntID>
<CPUID>{{ NRIC }}</CPUID>
<CPEntID>{{ UEN }}</CPEntID>
</UserInfo>
<AuthAccess>
<Result_Set>
Expand Down

0 comments on commit 97063fd

Please sign in to comment.