Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable and config authentication as default #466

Merged
merged 10 commits into from
Oct 19, 2023
3 changes: 3 additions & 0 deletions app/plugins/auth.plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ const AuthPlugin = {
return AuthService.go(session.userId)
}
})
// NOTE: This defaults Hapi to authenticate all routes. If a route, for example `/status`, does not require
// authentication `options.auth: false` should be set in the route's config.
server.auth.default('session')
}
}

Expand Down
12 changes: 12 additions & 0 deletions app/routes/assets.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ const routes = [
path: '/assets/all.js',
handler: {
file: 'node_modules/govuk-frontend/govuk/all.js'
},
options: {
app: {
plainOutput: true
},
auth: false
}
}, {
method: 'GET',
Expand All @@ -18,6 +24,12 @@ const routes = [
'node_modules/govuk-frontend/govuk/assets'
]
}
},
options: {
app: {
plainOutput: true
},
auth: false
}
}
]
Expand Down
9 changes: 7 additions & 2 deletions app/routes/bill-runs.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@ const routes = [
path: '/bill-runs',
handler: BillRunsController.create,
options: {
description: 'Used to create a bill run',
app: {
plainOutput: true
}
},
auth: {
access: {
scope: ['billing']
}
},
description: 'Used to create a bill run'
}
}
]
Expand Down
9 changes: 7 additions & 2 deletions app/routes/billing-accounts.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@ const routes = [
path: '/billing-accounts/{invoiceAccountId}/change-address',
handler: BillingAccountsController.changeAddress,
options: {
description: 'Used updating a billing account with a new address',
app: {
plainOutput: true
}
},
auth: {
access: {
scope: ['manage_billing_accounts']
}
},
description: 'Used updating a billing account with a new address'
}
}
]
Expand Down
5 changes: 3 additions & 2 deletions app/routes/charge-elements.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ const routes = [
path: '/charge-elements/time-limited',
handler: ChargeElementsController.timeLimited,
options: {
description: 'Puts a licence into workflow when a charge element has a `timeLimitedEndDate` which is < 50 days away',
app: {
plainOutput: true
}
},
auth: false,
description: 'Puts a licence into workflow when a charge element has a `timeLimitedEndDate` which is < 50 days away'
}
}
]
Expand Down
5 changes: 3 additions & 2 deletions app/routes/check.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ const routes = [
path: '/check/two-part/{naldRegionId}/{format?}',
handler: CheckController.twoPart,
options: {
description: 'Used by the delivery team to check the SROC 2PT billing logic',
app: {
excludeFromProd: true,
plainOutput: true
}
},
auth: false,
description: 'Used by the delivery team to check the SROC 2PT billing logic'
}
}
]
Expand Down
23 changes: 15 additions & 8 deletions app/routes/data.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,51 @@ const routes = [
path: '/data/export',
handler: DataController.exportDb,
options: {
description: 'Used to export the database and upload the file to our AWS S3 bucket',
app: {
excludeFromProd: true,
plainOutput: true
}
},
auth: false,
description: 'Used to export the database and upload the file to our AWS S3 bucket'
}
},
{
method: 'GET',
path: '/data/mock/{type}/{id}',
handler: DataController.mockData,
options: {
description: 'Used to generate mock data',
app: { excludeFromProd: true }
app: {
excludeFromProd: true,
plainOutput: true
},
auth: false,
description: 'Used to generate mock data'
}
},
{
method: 'POST',
path: '/data/seed',
handler: DataController.seed,
options: {
description: 'Used to seed test data in the database',
app: {
excludeFromProd: true,
plainOutput: true
}
},
auth: false,
description: 'Used to seed test data in the database'
}
},
{
method: 'POST',
path: '/data/tear-down',
handler: DataController.tearDown,
options: {
description: 'Used to remove the acceptance test data from the database',
app: {
excludeFromProd: true,
plainOutput: true
}
},
auth: false,
description: 'Used to remove the acceptance test data from the database'
}
}
]
Expand Down
9 changes: 9 additions & 0 deletions app/routes/health.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ const routes = [
path: '/health/airbrake',
handler: HealthController.airbrake,
options: {
app: {
plainOutput: true
},
auth: false,
description: 'Used by the delivery team to confirm error logging is working correctly in an environment. ' +
'NOTE. We expect this endpoint to return a 500'
}
Expand All @@ -17,6 +21,10 @@ const routes = [
path: '/health/database',
handler: HealthController.database,
options: {
app: {
plainOutput: true
},
auth: false,
description: 'Used by the delivery team to confirm we can connect to the database. It also returns us some ' +
'useful stats about each table.'
}
Expand All @@ -26,6 +34,7 @@ const routes = [
path: '/health/info',
handler: HealthController.info,
options: {
auth: false,
description: 'Used by the delivery team to confirm we can connect to our other apps and services. It also ' +
'returns us the version and commit hash for each one.'
}
Expand Down
16 changes: 12 additions & 4 deletions app/routes/root.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,34 @@ const routes = [
path: '/',
handler: RootController.index,
options: {
auth: false
app: {
plainOutput: true
},
auth: false,
description: 'Returns the same response as /status'
}
},
{
method: 'GET',
path: '/robots.txt',
handler: {
file: 'app/public/static/robots.txt'
},
options: {
auth: false,
description: 'Needed to support requests proxied from the legacy UI through to this app'
}
},
{
method: 'GET',
path: '/status',
handler: RootController.index,
options: {
auth: false,
description: 'Used by the AWS load balancers to confirm the service is running',
app: {
plainOutput: true
}
},
auth: false,
description: 'Used by the AWS load balancers to confirm the service is running'
}
}
]
Expand Down
4 changes: 4 additions & 0 deletions test/controllers/bill-runs.controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ describe('Bill Runs controller', () => {
scheme,
region: '07ae7f3a-2677-4102-b352-cc006828948c',
user: 'test.user@defra.gov.uk'
},
auth: {
strategy: 'session',
credentials: { scope: ['billing'] }
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion test/controllers/billing-accounts.controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ describe('Billing Accounts controller', () => {
beforeEach(() => {
options = {
method: 'POST',
url: '/billing-accounts/7fa2f044-b29e-483a-99b6-e16db0db0f58/change-address'
url: '/billing-accounts/7fa2f044-b29e-483a-99b6-e16db0db0f58/change-address',
auth: {
strategy: 'session',
credentials: { scope: ['manage_billing_accounts'] }
}
}
})

Expand Down
10 changes: 8 additions & 2 deletions test/plugins/error-pages.plugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ describe('Error Pages plugin', () => {
path: '/error-pages',
handler: function (_request, _h) {
return Boom.badRequest('Things go boom')
},
options: {
auth: false
}
}
})
Expand All @@ -66,7 +69,7 @@ describe('Error Pages plugin', () => {

describe('and the route is configured for plain output (do not redirect to error page)', () => {
beforeEach(async () => {
testRoute.options = { app: { plainOutput: true } }
testRoute.options.app = { plainOutput: true }
server.route(testRoute)

Sinon.stub(ErrorPagesService, 'go').returns({ stopResponse: false, statusCode: 400 })
Expand Down Expand Up @@ -106,6 +109,9 @@ describe('Error Pages plugin', () => {
path: '/error-pages',
handler: function (_request, h) {
return h.response({ hello: 'world' }).code(200)
},
options: {
auth: false
}
}
})
Expand All @@ -127,7 +133,7 @@ describe('Error Pages plugin', () => {

describe('and the route is configured for plain output (do not redirect to error page)', () => {
beforeEach(async () => {
testRoute.options = { app: { plainOutput: true } }
testRoute.options.app = { plainOutput: true }
server.route(testRoute)

Sinon.stub(ErrorPagesService, 'go').returns({ stopResponse: false, statusCode: 200 })
Expand Down