-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# This is a combination of 5 commits.
# This is the 1st commit message: pcq-1760 adding return to service path # This is the commit message #2: PCQ-1760 end page test # This is the commit message #3: PCQ-1760 end page test # This is the commit message #4: PCQ-1760 test and lint # This is the commit message #5: PCQ-1760 config semi
- Loading branch information
1 parent
f68539e
commit 1f783e3
Showing
10 changed files
with
131 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
'use strict'; | ||
|
||
const validateUrl = require('app/middleware/validateUrl'); | ||
const appInsights = require('app/components/app-insights'); | ||
|
||
const returnToService = (req, res) => { | ||
appInsights.trackTrace({message: 'Returning to primary service', properties: {['ServiceId']:req.session.form.serviceId}}); | ||
res.redirect(validateUrl(req)); | ||
}; | ||
|
||
module.exports = returnToService; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
'use strict'; | ||
|
||
const validateUrl = (req) => { | ||
const redirect = req.session.returnUrl || '/offline'; | ||
let givenUrl ; | ||
try { | ||
givenUrl = new URL (redirect); | ||
} catch (error) { | ||
req.log.error(error); | ||
givenUrl = '/offline'; | ||
} | ||
return givenUrl; | ||
}; | ||
|
||
module.exports = validateUrl; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,43 @@ | ||
import js from "@eslint/js"; | ||
import globals from "globals"; | ||
import js from '@eslint/js'; | ||
import globals from 'globals'; | ||
|
||
const config = { | ||
|
||
languageOptions: { | ||
ecmaVersion: 2020, | ||
sourceType: 'module', | ||
globals: { | ||
...globals.browser, | ||
...globals.mocha, | ||
...globals.node, | ||
'actor': true, | ||
'Feature': true, | ||
'Scenario': true, | ||
'codecept_helper': true | ||
} | ||
languageOptions: { | ||
ecmaVersion: 2020, | ||
sourceType: 'module', | ||
globals: { | ||
...globals.browser, | ||
...globals.mocha, | ||
...globals.node, | ||
'actor': true, | ||
'Feature': true, | ||
'Scenario': true, | ||
'codecept_helper': true, | ||
}, | ||
}, | ||
|
||
rules: { | ||
...js.configs.recommended.rules, | ||
'linebreak-style': ['error', 'unix'], | ||
quotes: ['error', 'single'], | ||
semi: ['error', 'always'], | ||
'no-unused-vars': 0, | ||
}, | ||
}; | ||
|
||
export default [ | ||
js.configs.recommended, | ||
config, | ||
{ | ||
ignores: [ | ||
'govuk/*', | ||
'public/*', | ||
'app/assets/javascripts/*.js', | ||
'coverage', | ||
'functional-output/*', | ||
'.pnp.cjs', | ||
'.pnp.loader.mjs', | ||
'.stryker-tmp' | ||
] | ||
} | ||
config, | ||
{ | ||
ignores: [ | ||
'govuk/*', | ||
'public/*', | ||
'app/assets/javascripts/*.js', | ||
'coverage', | ||
'functional-output/*', | ||
'.pnp.cjs', | ||
'.pnp.loader.mjs', | ||
'.stryker-tmp', | ||
], | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
'use strict'; | ||
|
||
const expect = require('chai').expect; | ||
const nock = require('nock'); | ||
const sinon = require('sinon'); | ||
const returnToService = require('app/middleware/returnToService'); | ||
|
||
describe('returnToService', () => { | ||
let req = {}; | ||
let res = {}; | ||
|
||
describe('redirect', () => { | ||
|
||
beforeEach(() => { | ||
req = { | ||
session: { | ||
form: { | ||
serviceId: 'test' | ||
} | ||
} | ||
}; | ||
res = {redirect: sinon.spy()}; | ||
}); | ||
|
||
it('should redirect to the given return URL', () => { | ||
nock('http://localhost:4550') | ||
.get('/return-to-service') | ||
.reply( | ||
200, | ||
{status: ':thumbs_up:'} | ||
); | ||
|
||
req.session.returnUrl = 'http://test.com'; | ||
returnToService(req,res); | ||
|
||
expect(res.redirect.calledOnce).to.equal(true); | ||
expect(res.redirect.args[0][0].href).to.equal('http://test.com/'); | ||
nock.cleanAll(); | ||
|
||
}); | ||
|
||
it('should redirect to offline if URL not valid', () => { | ||
nock('http://localhost:4550') | ||
.get('/return-to-service') | ||
.reply( | ||
200, | ||
{status: ':thumbs_up:'} | ||
); | ||
|
||
req.session.returnUrl = 'http:/[/]test.com'; | ||
req.log = sinon.spy(); | ||
req.log.error = sinon.spy(); | ||
|
||
returnToService(req, res); | ||
expect(res.redirect.calledOnce).to.equal(true); | ||
expect(res.redirect.args[0][0]).to.equal('/offline'); | ||
nock.cleanAll(); | ||
}); | ||
}); | ||
}); |