Move LoginRoutes from /app to /api
This commit is contained in:
parent
491012a815
commit
0c7af3538c
@ -12,7 +12,7 @@ import {ILogger} from '../logger/ILogger'
|
|||||||
import {IRoutes} from '@rondo/common'
|
import {IRoutes} from '@rondo/common'
|
||||||
import {ITransactionManager} from '../database/ITransactionManager'
|
import {ITransactionManager} from '../database/ITransactionManager'
|
||||||
import {loggerFactory, LoggerFactory} from '../logger/LoggerFactory'
|
import {loggerFactory, LoggerFactory} from '../logger/LoggerFactory'
|
||||||
import {urlencoded, json} from 'body-parser'
|
import {json} from 'body-parser'
|
||||||
|
|
||||||
export class Application implements IApplication {
|
export class Application implements IApplication {
|
||||||
readonly transactionManager: ITransactionManager
|
readonly transactionManager: ITransactionManager
|
||||||
@ -63,32 +63,29 @@ export class Application implements IApplication {
|
|||||||
const {transactionManager} = this
|
const {transactionManager} = this
|
||||||
const apiLogger = this.getApiLogger()
|
const apiLogger = this.getApiLogger()
|
||||||
|
|
||||||
router.use('/app', urlencoded({ extended: false }))
|
|
||||||
|
|
||||||
router.use(new middleware.SessionMiddleware({
|
router.use(new middleware.SessionMiddleware({
|
||||||
transactionManager,
|
transactionManager,
|
||||||
baseUrl: this.config.app.baseUrl,
|
baseUrl: this.config.app.baseUrl,
|
||||||
sessionName: this.config.app.session.name,
|
sessionName: this.config.app.session.name,
|
||||||
sessionSecret: this.config.app.session.secret,
|
sessionSecret: this.config.app.session.secret,
|
||||||
}).handle)
|
}).handle)
|
||||||
|
router.use(new middleware.RequestLogger(apiLogger).handle)
|
||||||
|
router.use(json())
|
||||||
router.use(middleware.csrf)
|
router.use(middleware.csrf)
|
||||||
router.use(new middleware.Transaction(this.database.namespace).handle)
|
router.use(new middleware.Transaction(this.database.namespace).handle)
|
||||||
router.use(new middleware.RequestLogger(apiLogger).handle)
|
|
||||||
|
|
||||||
router.use(this.authenticator.handle)
|
router.use(this.authenticator.handle)
|
||||||
}
|
}
|
||||||
|
|
||||||
protected configureRouter(router: express.Router) {
|
protected configureRouter(router: express.Router) {
|
||||||
// TODO use /api for LoginRoutes
|
// TODO use /api for LoginRoutes
|
||||||
router.use('/app', new routes.LoginRoutes(
|
router.use('/app', routes.application)
|
||||||
|
|
||||||
|
router.use('/api', new routes.LoginRoutes(
|
||||||
this.userService,
|
this.userService,
|
||||||
this.authenticator,
|
this.authenticator,
|
||||||
this.createTransactionalRouter(),
|
this.createTransactionalRouter(),
|
||||||
).handle)
|
).handle)
|
||||||
router.use('/app', routes.application)
|
|
||||||
|
|
||||||
router.use('/api', json())
|
|
||||||
|
|
||||||
router.use('/api', new routes.UserRoutes(
|
router.use('/api', new routes.UserRoutes(
|
||||||
this.userService,
|
this.userService,
|
||||||
this.createTransactionalRouter(),
|
this.createTransactionalRouter(),
|
||||||
|
|||||||
@ -30,11 +30,11 @@ describe('login', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('should log out the user', async () => {
|
it('should log out the user', async () => {
|
||||||
await test.request('/app')
|
await test.request('/api')
|
||||||
.get('/auth/logout')
|
.get('/auth/logout')
|
||||||
.set('cookie', cookie)
|
.set('cookie', cookie)
|
||||||
.expect(302)
|
.expect(302)
|
||||||
.expect('location', `${test.context}/app/auth/login`)
|
.expect('location', `${test.context}/api/auth/login`)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@ -91,7 +91,7 @@ export class TestUtils<T extends IRoutes> {
|
|||||||
|
|
||||||
getLoginBody(csrfToken: string) {
|
getLoginBody(csrfToken: string) {
|
||||||
const {username, password} = this
|
const {username, password} = this
|
||||||
return `username=${username}&password=${password}&_csrf=${csrfToken}`
|
return {username, password, _csrf: csrfToken}
|
||||||
}
|
}
|
||||||
|
|
||||||
async registerAccount() {
|
async registerAccount() {
|
||||||
@ -99,7 +99,7 @@ export class TestUtils<T extends IRoutes> {
|
|||||||
const {cookie, token} = await this.getCsrf()
|
const {cookie, token} = await this.getCsrf()
|
||||||
|
|
||||||
const response = await supertest(this.app)
|
const response = await supertest(this.app)
|
||||||
.post(`${context}/app/auth/register`)
|
.post(`${context}/api/auth/register`)
|
||||||
.set('cookie', cookie)
|
.set('cookie', cookie)
|
||||||
.send(this.getLoginBody(token))
|
.send(this.getLoginBody(token))
|
||||||
.expect(200)
|
.expect(200)
|
||||||
@ -111,14 +111,14 @@ export class TestUtils<T extends IRoutes> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async login(_username = this.username, _password = this.password) {
|
async login(username = this.username, password = this.password) {
|
||||||
const {context} = this
|
const {context} = this
|
||||||
const {cookie, token} = await this.getCsrf()
|
const {cookie, token} = await this.getCsrf()
|
||||||
|
|
||||||
const response = await supertest(this.app)
|
const response = await supertest(this.app)
|
||||||
.post(`${context}/app/auth/login`)
|
.post(`${context}/api/auth/login`)
|
||||||
.set('cookie', cookie)
|
.set('cookie', cookie)
|
||||||
.send(`username=${_username}&password=${_password}&_csrf=${token}`)
|
.send({username, password, _csrf: token})
|
||||||
.expect(200)
|
.expect(200)
|
||||||
|
|
||||||
return {cookie: response.header['set-cookie'] as string, token}
|
return {cookie: response.header['set-cookie'] as string, token}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user