Skip to content

Commit

Permalink
Merge pull request #10 from companieshouse/feature/BI-3708
Browse files Browse the repository at this point in the history
BI-3708 - Navigate to companies house log-in
  • Loading branch information
mateuszc-kainos authored Jun 10, 2020
2 parents 68f9d31 + 2e0f65a commit f34fe34
Show file tree
Hide file tree
Showing 19 changed files with 353 additions and 15 deletions.
5 changes: 4 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,18 @@ services:
- chs-dev
working_dir: /app
environment:
- ACCOUNT_WEB_URL=http://chs-dev
- CDN_HOST=cdn.chs-dev
- CACHE_SERVER=redis
- CACHE_DB=0
- CACHE_PASSWORD=''
- COOKIE_NAME=SID
- COOKIE_NAME=__SID
- COOKIE_DOMAIN=chs-dev
- COOKIE_SECURE_ONLY=0
- COOKIE_SECRET=ChGovUk-XQrbf3sLj2abFxIY2TlapsJ
- DEFAULT_SESSION_EXPIRATION=3600
- LOG_LEVEL=info
- HUMAN_LOG=1
depends_on:
- mongo
- cdn-ch-gov-uk
Expand Down
142 changes: 142 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"nunjucks": "^3.2.1",
"reflect-metadata": "^0.1.13",
"tsconfig-paths": "^3.9.0",
"tslib": "^2.0.0"
"tslib": "^2.0.0",
"web-security-node": "git@github.com:companieshouse/web-security-node.git#e35f2199b35f729eec2445d38d2b40a588e85ece"
},
"devDependencies": {
"@types/body-parser": "^1.19.0",
Expand All @@ -50,6 +51,7 @@
"@types/mocha": "^7.0.2",
"@types/multer": "^1.4.3",
"@types/nunjucks": "^3.1.3",
"@types/sinon": "^9.0.4",
"@types/supertest": "^2.0.9",
"chai": "^4.2.0",
"del": "^5.1.0",
Expand All @@ -66,6 +68,7 @@
"node-sass": "^4.14.1",
"nyc": "^15.0.1",
"sass-lint": "^1.13.1",
"sinon": "^9.0.2",
"sonarqube-scanner": "^2.6.0",
"supertest": "^4.0.2",
"ts-mockito": "^2.5.0",
Expand Down
2 changes: 1 addition & 1 deletion src/constants/app.const.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const APP_NAME = 'example-ch-service-name'
export const APP_NAME = 'dissolution-web'
3 changes: 2 additions & 1 deletion src/controllers/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'app/controllers/form.controller'
import 'app/controllers/healthcheck.controller'
import 'app/controllers/landing.controller'
import 'app/controllers/landing.controller'
import 'app/controllers/searchCompany.controller'
14 changes: 14 additions & 0 deletions src/controllers/searchCompany.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { controller, httpGet } from 'inversify-express-utils'

import BaseController from 'app/controllers/base.controller'
import { SEARCH_COMPANY_URI } from 'app/paths'
import TYPES from 'app/types'

@controller(SEARCH_COMPANY_URI, TYPES.SessionMiddleware, TYPES.AuthMiddleware)
export class SearchCompanyController extends BaseController {

@httpGet('')
public async get(): Promise<string> {
return super.render('search-company')
}
}
13 changes: 11 additions & 2 deletions src/inversify.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ import { CookieConfig, SessionMiddleware, SessionStore } from 'ch-node-session-h
import { Container } from 'inversify'
import { buildProviderModule } from 'inversify-binding-decorators'
import IORedis from 'ioredis'
import Optional from './models/optional'
import { authMiddleware as commonAuthMiddleware } from 'web-security-node'

import { APP_NAME } from 'app/constants/app.const'
import AuthMiddleware from 'app/middleware/auth.middleware'
import Optional from 'app/models/optional'
import TYPES from 'app/types'
import { getEnv, getEnvOrDefault, getEnvOrThrow } from 'app/utils/env.util'
import UriFactory from 'app/utils/uri.factory'

export function initContainer(): Container {
const container: Container = new Container()
Expand All @@ -24,6 +27,7 @@ export function initContainer(): Container {

// Utils
container.bind<ApplicationLogger>(ApplicationLogger).toConstantValue(createLogger(APP_NAME))
container.bind<UriFactory>(UriFactory).toConstantValue(new UriFactory())

// Session
const config: CookieConfig = {
Expand All @@ -32,7 +36,12 @@ export function initContainer(): Container {
}
const sessionStore = new SessionStore(new IORedis(`${getEnvOrThrow('CACHE_SERVER')}`))
container.bind(SessionStore).toConstantValue(sessionStore)
container.bind(SessionMiddleware).toConstantValue(SessionMiddleware(config, sessionStore))
container.bind(TYPES.SessionMiddleware).toConstantValue(SessionMiddleware(config, sessionStore))
container.bind(TYPES.AuthMiddleware).toConstantValue(AuthMiddleware(
getEnvOrThrow('ACCOUNT_WEB_URL'),
new UriFactory(),
commonAuthMiddleware
))

container.load(buildProviderModule())

Expand Down
17 changes: 17 additions & 0 deletions src/middleware/auth.middleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { NextFunction, Request, RequestHandler, Response } from 'express'
import { AuthOptions } from 'web-security-node'

import { SEARCH_COMPANY_URI } from 'app/paths'
import UriFactory from 'app/utils/uri.factory'

export default function AuthMiddleware(accountWebUrl: string, uriFactory: UriFactory,
commonAuthMiddleware: (opts: AuthOptions) => RequestHandler): RequestHandler {
return (req: Request, res: Response, next: NextFunction) => {
const authOptions: AuthOptions = {
returnUrl: uriFactory.createAbsoluteUri(req, SEARCH_COMPANY_URI),
accountWebUrl
}

return commonAuthMiddleware(authOptions)(req, res, next)
}
}
2 changes: 2 additions & 0 deletions src/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ export const HEALTHCHECK_URI = `${ROOT_URI}/healthcheck`

// Pages
export const FORM_PAGE_URI = `${ROOT_URI}/form`
export const WHO_TO_TELL_URI = `${ROOT_URI}/who-to-tell`
export const SEARCH_COMPANY_URI = `${ROOT_URI}/search-company`
5 changes: 4 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ const TYPES = {
NODE_ENV: 'NODE_ENV',
CDN_HOST: 'CDN_HOST',
PIWIK_URL: 'PIWIK_URL',
PIWIK_SITE_ID: 'PIWIK_SITE_ID'
PIWIK_SITE_ID: 'PIWIK_SITE_ID',
ACCOUNT_WEB_URL: 'ACCOUNT_WEB_URL',
SessionMiddleware: 'SessionMiddleware',
AuthMiddleware: 'AuthMiddleware'
}

export default TYPES
9 changes: 9 additions & 0 deletions src/utils/uri.factory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Request } from 'express'
import { provide } from 'inversify-binding-decorators'

@provide(UriFactory)
export default class UriFactory {
public createAbsoluteUri(req: Request, path: string): string {
return new URL(path, `${req.protocol}://${req.headers.host}`).href
}
}
28 changes: 28 additions & 0 deletions src/views/search-company.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{% extends 'layout.njk' %}

{% from 'govuk/components/breadcrumbs/macro.njk' import govukBreadcrumbs %}
{% from 'govuk/components/button/macro.njk' import govukButton %}

{% block pageTitle %}
{{ serviceName }}
{% endblock %}

{% block beforeContent %}
{{
govukBreadcrumbs({
items: [
{ href: 'https://www.gov.uk/', text: 'Home' },
{ href: 'https://www.gov.uk/browse/business', text: 'Business and self-employed' },
{ href: 'https://www.gov.uk/browse/business/limited-company', text: 'Running a limited company' }
]
})
}}
{% endblock %}

{% block content %}
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<h1 class="govuk-heading-xl">Search Company Placeholder</h1>
</div>
</div>
{% endblock %}
Loading

0 comments on commit f34fe34

Please sign in to comment.