Skip to content

Plat 638 adjust login cookies test fix #1182

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
d00df3b
Fix all the tests with new way of authentication
nour-borgi Feb 8, 2023
2c8687d
Merge branch 'PLAT-638-adjust-login-cookies' of https://github.com/je…
nour-borgi Feb 8, 2023
6c9ad38
Fix setup of tests
nour-borgi Feb 8, 2023
307bb2c
Adjust default config and set 1s for cookies expiry in tests
nour-borgi Feb 8, 2023
b65f099
Add tests and fix others
nour-borgi Feb 8, 2023
b6e6c3a
Merge branch 'PLAT-638-adjust-login-cookies' of https://github.com/je…
nour-borgi Feb 8, 2023
9809ba0
Fix package-lock.json with node v 14
nour-borgi Feb 9, 2023
ec1a782
Merge branch 'PLAT-638-adjust-login-cookies' of https://github.com/je…
nour-borgi Feb 20, 2023
ad55d3d
Merge branch 'PLAT-638-adjust-login-cookies' of https://github.com/je…
nour-borgi Feb 22, 2023
c15b5cf
Merge branch 'PLAT-638-adjust-login-cookies' of https://github.com/je…
nour-borgi Feb 22, 2023
a65c99c
Add token tests
nour-borgi Feb 23, 2023
bd50f7b
Merge branch 'PLAT-638-adjust-login-cookies' of https://github.com/je…
nour-borgi Feb 23, 2023
fcb3017
Apply eslint
nour-borgi Feb 23, 2023
1372b80
Update test/integration/auditAPITests.js
nour-borgi Mar 16, 2023
1364746
Update test/unit/passportTest.js
nour-borgi Mar 16, 2023
ddb95ad
Update test/unit/passportTest.js
nour-borgi Mar 16, 2023
8358ead
Update test/unit/passportTest.js
nour-borgi Mar 16, 2023
825e799
Update test/unit/passportTest.js
nour-borgi Mar 16, 2023
b497230
Update test/unit/usersTest.js
nour-borgi Mar 16, 2023
d7f4abc
Update test/unit/usersTest.js
nour-borgi Mar 16, 2023
ef2f2dd
Update test/unit/usersTest.js
nour-borgi Mar 16, 2023
0100068
Update test/unit/utilsTest.js
nour-borgi Mar 16, 2023
7f6d37e
Update test/integration/generalAPITests.js
nour-borgi Mar 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/test.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"maxPayloadSizeMB": 50,
"truncateSize": 10,
"truncateAppend": "\n[truncated ...]",
"authenticationTypes": ["token", "basic"]
"authenticationTypes": ["token", "basic", "local"]
},
"caching": {
"enabled": false
Expand Down
26 changes: 13 additions & 13 deletions test/integration/aboutAPITests.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,9 @@ import {BASE_URL, SERVER_PORTS} from '../constants'

describe('API Integration Tests', () =>
describe('About Information REST Api Testing', () => {
let authDetails = {}

before(async () => {
await testUtils.setupTestUsers()
await promisify(server.start)({apiPort: SERVER_PORTS.apiPort})

authDetails = testUtils.getAuthDetails()
await testUtils.setupTestUsers()
})

after(async () => {
Expand All @@ -28,25 +24,29 @@ describe('API Integration Tests', () =>
})

describe('*getAboutInformation', () => {
it('should return status 401 when being unauthenticated', async () => {
await request(BASE_URL).get('/about').expect(401)
})

it('should fetch core version and return status 200', async () => {
const user = testUtils.rootUser
const cookie = await testUtils.authenticate(request, BASE_URL, user)

const res = await request(BASE_URL)
.get('/about')
.set('auth-username', testUtils.rootUser.email)
.set('auth-ts', authDetails.authTS)
.set('auth-salt', authDetails.authSalt)
.set('auth-token', authDetails.authToken)
.set('Cookie', cookie)
.expect(200)

res.body.should.have.property('currentCoreVersion')
})

it('should return 404 if not found', async () => {
const user = testUtils.rootUser
const cookie = await testUtils.authenticate(request, BASE_URL, user)

await request(BASE_URL)
.get('/about/bleh')
.set('auth-username', testUtils.rootUser.email)
.set('auth-ts', authDetails.authTS)
.set('auth-salt', authDetails.authSalt)
.set('auth-token', authDetails.authToken)
.set('Cookie', cookie)
.expect(404)
})
})
Expand Down
110 changes: 46 additions & 64 deletions test/integration/auditAPITests.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,32 @@ import {config} from '../../src/config'
describe('API Integration Tests', () => {
const router = config.get('router')
const api = config.get('api')
let authDetails

let rootCookie = '',
nonRootCookie = ''

before(async () => {
await testUtils.setupTestUsers()
await promisify(server.start)({apiPort: SERVER_PORTS.apiPort})

authDetails = testUtils.getAuthDetails()
await testUtils.setupTestUsers()
})

after(async () => {
await Promise.all([promisify(server.stop)(), testUtils.cleanupTestUsers()])
})

beforeEach(async () => {
rootCookie = await testUtils.authenticate(
request,
BASE_URL,
testUtils.rootUser
)
nonRootCookie = await testUtils.authenticate(
request,
BASE_URL,
testUtils.nonRootUser
)
})

afterEach(async () => {
await Promise.all([
AuditModel.deleteMany({}),
Expand Down Expand Up @@ -118,10 +132,7 @@ describe('API Integration Tests', () => {
it('should add a audit and return status 201 - audit created', async () => {
await request(BASE_URL)
.post('/audits')
.set('auth-username', testUtils.rootUser.email)
.set('auth-ts', authDetails.authTS)
.set('auth-salt', authDetails.authSalt)
.set('auth-token', authDetails.authToken)
.set('Cookie', rootCookie)
.send(auditData)
.expect(201)

Expand Down Expand Up @@ -158,13 +169,14 @@ describe('API Integration Tests', () => {
it('should only allow admin users to add audits', async () => {
await request(BASE_URL)
.post('/audits')
.set('auth-username', testUtils.nonRootUser.email)
.set('auth-ts', authDetails.authTS)
.set('auth-salt', authDetails.authSalt)
.set('auth-token', authDetails.authToken)
.set('Cookie', nonRootCookie)
.send(auditData)
.expect(403)
})

it('should allow only authenticated users to add audits and return 401 status', async () => {
await request(BASE_URL).post('/audits').send(auditData).expect(401)
})
})

describe('*getAudits()', () => {
Expand All @@ -173,10 +185,7 @@ describe('API Integration Tests', () => {
await new AuditModel(auditData).save()
const res = await request(BASE_URL)
.get('/audits?filterPage=0&filterLimit=10&filters={}')
.set('auth-username', testUtils.rootUser.email)
.set('auth-ts', authDetails.authTS)
.set('auth-salt', authDetails.authSalt)
.set('auth-token', authDetails.authToken)
.set('Cookie', rootCookie)
.expect(200)

res.body.length.should.equal(countBefore + 1)
Expand All @@ -195,10 +204,7 @@ describe('API Integration Tests', () => {
filters
)}`
)
.set('auth-username', testUtils.rootUser.email)
.set('auth-ts', authDetails.authTS)
.set('auth-salt', authDetails.authSalt)
.set('auth-token', authDetails.authToken)
.set('Cookie', rootCookie)
.expect(200)

res.body.length.should.equal(countBefore + 1)
Expand All @@ -216,10 +222,7 @@ describe('API Integration Tests', () => {
filters
)}`
)
.set('auth-username', testUtils.rootUser.email)
.set('auth-ts', authDetails.authTS)
.set('auth-salt', authDetails.authSalt)
.set('auth-token', authDetails.authToken)
.set('Cookie', rootCookie)
.expect(400)

res.statusCode.should.be.exactly(400)
Expand All @@ -240,10 +243,7 @@ describe('API Integration Tests', () => {
filters
)}`
)
.set('auth-username', testUtils.rootUser.email)
.set('auth-ts', authDetails.authTS)
.set('auth-salt', authDetails.authSalt)
.set('auth-token', authDetails.authToken)
.set('Cookie', rootCookie)
.expect(200)

res.statusCode.should.be.exactly(200)
Expand All @@ -264,10 +264,7 @@ describe('API Integration Tests', () => {
filters
)}`
)
.set('auth-username', testUtils.rootUser.email)
.set('auth-ts', authDetails.authTS)
.set('auth-salt', authDetails.authSalt)
.set('auth-token', authDetails.authToken)
.set('Cookie', rootCookie)
.expect(400)

res.statusCode.should.be.exactly(400)
Expand All @@ -278,10 +275,7 @@ describe('API Integration Tests', () => {

await request(BASE_URL)
.get('/audits?filterRepresentation=full')
.set('auth-username', testUtils.rootUser.email)
.set('auth-ts', authDetails.authTS)
.set('auth-salt', authDetails.authSalt)
.set('auth-token', authDetails.authToken)
.set('Cookie', rootCookie)
.expect(200)

await testUtils.pollCondition(() =>
Expand Down Expand Up @@ -317,15 +311,16 @@ describe('API Integration Tests', () => {
await new AuditModel(auditData).save()
await request(BASE_URL)
.get('/audits')
.set('auth-username', testUtils.rootUser.email)
.set('auth-ts', authDetails.authTS)
.set('auth-salt', authDetails.authSalt)
.set('auth-token', authDetails.authToken)
.set('Cookie', rootCookie)
.expect(200)

const auditCount = await AuditModel.countDocuments()
auditCount.should.eql(1)
})

it('should allow only authenticated users to get audits and return 401 status', async () => {
await request(BASE_URL).get('/audits').send(auditData).expect(401)
})
})

describe('*getAuditById (auditId)', () => {
Expand All @@ -334,10 +329,7 @@ describe('API Integration Tests', () => {
const auditId = audit._id
const res = await request(BASE_URL)
.get(`/audits/${auditId}`)
.set('auth-username', testUtils.rootUser.email)
.set('auth-ts', authDetails.authTS)
.set('auth-salt', authDetails.authSalt)
.set('auth-token', authDetails.authToken)
.set('Cookie', rootCookie)
.expect(200)

res.body.eventIdentification.eventDateTime.should.equal(
Expand Down Expand Up @@ -373,10 +365,7 @@ describe('API Integration Tests', () => {
const auditId = audit._id
await request(BASE_URL)
.get(`/audits/${auditId}`)
.set('auth-username', testUtils.nonRootUser.email)
.set('auth-ts', authDetails.authTS)
.set('auth-salt', authDetails.authSalt)
.set('auth-token', authDetails.authToken)
.set('Cookie', nonRootCookie)
.expect(403)
})

Expand All @@ -385,10 +374,7 @@ describe('API Integration Tests', () => {
const auditId = audit._id
await request(BASE_URL)
.get(`/audits/${auditId}`)
.set('auth-username', testUtils.rootUser.email)
.set('auth-ts', authDetails.authTS)
.set('auth-salt', authDetails.authSalt)
.set('auth-token', authDetails.authToken)
.set('Cookie', rootCookie)
.expect(200)

await testUtils.pollCondition(() =>
Expand Down Expand Up @@ -425,19 +411,13 @@ describe('API Integration Tests', () => {
it('should fetch dropdown filter options - admin user', async () => {
await request(BASE_URL)
.post('/audits')
.set('auth-username', testUtils.rootUser.email)
.set('auth-ts', authDetails.authTS)
.set('auth-salt', authDetails.authSalt)
.set('auth-token', authDetails.authToken)
.send(auditData)
.set('Cookie', rootCookie)
.expect(201)

const res = await request(BASE_URL)
.get('/audits-filter-options')
.set('auth-username', testUtils.rootUser.email)
.set('auth-ts', authDetails.authTS)
.set('auth-salt', authDetails.authSalt)
.set('auth-token', authDetails.authToken)
.set('Cookie', rootCookie)
.expect(200)

res.body.eventType.length.should.equal(1)
Expand All @@ -450,12 +430,14 @@ describe('API Integration Tests', () => {
await new AuditModel(auditData).save()
await request(BASE_URL)
.get('/audits-filter-options')
.set('auth-username', testUtils.nonRootUser.email)
.set('auth-ts', authDetails.authTS)
.set('auth-salt', authDetails.authSalt)
.set('auth-token', authDetails.authToken)
.set('Cookie', nonRootCookie)
.expect(403)
})

it('should return 401 when user is not authenticated', async () => {
await new AuditModel(auditData).save()
await request(BASE_URL).get('/audits-filter-options').expect(401)
})
})
})
})
Loading