Skip to content

Commit

Permalink
feat: allow overriding showLoginPage config via request header (#336)
Browse files Browse the repository at this point in the history
Allow the showLoginPage config to be overridden via an HTTP header. This way, 
E2E tests can send `X-Show-Login-Page: false` in the request, while manual testing 
can still be done in the browser, all against the same running instance of Mockpass

Co-authored-by: LoneRifle <[email protected]>
  • Loading branch information
whipermr5 and LoneRifle authored Feb 3, 2022
1 parent 93c8a04 commit 1a327b6
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ $ export MOCKPASS_PORT=5156
$ export MOCKPASS_NRIC=S8979373D
$ export MOCKPASS_UEN=123456789A
$ export SHOW_LOGIN_PAGE=true # Optional, defaults to `false`
$ export SHOW_LOGIN_PAGE=true # Optional, defaults to `false`; can be overridden per request using `X-Show-Login-Page` HTTP header
# Disable signing/encryption (Optional, by default `true`)
$ export SIGN_ASSERTION=false
Expand Down
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ const options = {
assertEndpoint: process.env.CORPPASS_ASSERT_ENDPOINT,
},
},
showLoginPage: process.env.SHOW_LOGIN_PAGE === 'true',
showLoginPage: (req) => {
return process.env.SHOW_LOGIN_PAGE === 'true' || req.header('X-Show-Login-Page') === 'true'
},
encryptMyInfo: process.env.ENCRYPT_MYINFO === 'true',
cryptoConfig,
}
Expand Down
2 changes: 1 addition & 1 deletion lib/express/oidc.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function config(app, { showLoginPage, idpConfig, serviceProvider }) {
app.get(`/${idp.toLowerCase()}/authorize`, (req, res) => {
const redirectURI = req.query.redirect_uri
const state = encodeURIComponent(req.query.state)
if (showLoginPage) {
if (showLoginPage(req)) {
const oidc = assertions.oidc[idp]
const values = oidc.map((rawId, index) => {
const code = encodeURIComponent(
Expand Down
2 changes: 1 addition & 1 deletion lib/express/saml.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function config(
: idpConfig[idp].assertEndpoint || req.query.PartnerId
const relayState = req.query.Target
const partnerId = idpConfig[idp].id
if (showLoginPage) {
if (showLoginPage(req)) {
const saml = assertions.saml[idp]
const values = saml.map((rawId, index) => {
const samlArt = encodeURIComponent(samlArtifact(partnerId, index))
Expand Down
2 changes: 1 addition & 1 deletion lib/express/sgid.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function config(app, { showLoginPage, idpConfig, serviceProvider }) {
app.get(`${PATH_PREFIX}/authorize`, (req, res) => {
const redirectURI = req.query.redirect_uri
const state = encodeURIComponent(req.query.state)
if (showLoginPage) {
if (showLoginPage(req)) {
const oidc = assertions.oidc.singPass
const values = oidc
.filter((rawId) => assertions.myinfo.v3.personas[rawId])
Expand Down

0 comments on commit 1a327b6

Please sign in to comment.