@@ -34,11 +34,11 @@
I've checked the link. Skip ahead
-

+
diff --git a/test/end-to-end/LinkAudit.test.ts b/test/end-to-end/LinkAudit.test.ts
index b345902e6..6cfd69002 100644
--- a/test/end-to-end/LinkAudit.test.ts
+++ b/test/end-to-end/LinkAudit.test.ts
@@ -93,8 +93,6 @@ test('Changing the link owner should update the link history with Link Owner upd
.pressKey('ctrl+a delete')
.typeText(linkTransferField, `${transferEmail}`)
.click(transferButton)
- // Close drawer
- await t.click(closeButtonSnackBar)
// Sign out
await t.click(signOutButton)
// Login using the new link owner
diff --git a/test/end-to-end/UrlCreation.test.ts b/test/end-to-end/UrlCreation.test.ts
index 8d7622060..be5aa87f2 100644
--- a/test/end-to-end/UrlCreation.test.ts
+++ b/test/end-to-end/UrlCreation.test.ts
@@ -325,7 +325,7 @@ test('The update file test', async (t) => {
const generatedfileUrl = await shortUrlTextField.value
const fileRow = Selector(`h6[title="${generatedfileUrl}"]`)
- const directoryPath = `${process.env.HOME}/Downloads/${generatedfileUrl}.pdf`
+ const directoryPath = `${process.env.HOME}/Downloads/${generatedfileUrl}.csv`
// Generate 1mb file
await createEmptyFileOfSize(dummyFilePath, smallFileSize)
diff --git a/test/end-to-end/util/config.ts b/test/end-to-end/util/config.ts
index 9fa3fbb7e..69b8c9634 100644
--- a/test/end-to-end/util/config.ts
+++ b/test/end-to-end/util/config.ts
@@ -16,8 +16,8 @@ export const dummyMaliciousFilePath = './test/end-to-end/eicar.com.txt'
export const dummyMaliciousRelativePath = './eicar.com.txt'
export const dummyFilePath = './test/end-to-end/anotherDummy.txt'
export const dummyRelativePath = './anotherDummy.txt'
-export const dummyChangedFilePath = './test/end-to-end/changedDummy.pdf'
-export const dummyRelativeChangedFilePath = './changedDummy.pdf'
+export const dummyChangedFilePath = './test/end-to-end/changedDummy.csv'
+export const dummyRelativeChangedFilePath = './changedDummy.csv'
export const dummyBulkCsv = './test/end-to-end/bulkCsv.csv'
export const dummyBulkCsvRelativePath = './bulkCsv.csv'
export const smallFileSize = 1024 * 1024 * 1
diff --git a/test/integration/util/db.ts b/test/integration/util/db.ts
index a7b94da4e..822a2e2a9 100644
--- a/test/integration/util/db.ts
+++ b/test/integration/util/db.ts
@@ -21,7 +21,9 @@ export const createDbUser = async (
)
} catch (e) {
throw new Error(
- `Failed to create user with email ${email} for integration tests: ${e.message}`,
+ `Failed to create user with email ${email} for integration tests: ${
+ (e as Error).message
+ }`,
)
}
}
@@ -49,7 +51,9 @@ export const deleteDbUser = async (email: string): Promise
=> {
)
} catch (e) {
throw new Error(
- `Failed to delete user with email ${email} for integration tests: ${e.message}`,
+ `Failed to delete user with email ${email} for integration tests: ${
+ (e as Error).message
+ }`,
)
}
}
diff --git a/test/server/api/LoginRoute.test.ts b/test/server/api/LoginRoute.test.ts
index 337e11738..4efe97c9b 100644
--- a/test/server/api/LoginRoute.test.ts
+++ b/test/server/api/LoginRoute.test.ts
@@ -56,7 +56,7 @@ describe('POST /api/login/otp', () => {
describe('POST /api/login/verify', () => {
test('verify the OTP', async (done) => {
// Prime cache
- getOtpCache().setOtpForEmail('otpgo.gov@open.test.sg', {
+ getOtpCache().setOtpForEmail('otpgo.gov@open.test.sg', '127.0.0.1', {
hashedOtp: '1',
retries: 100,
})
diff --git a/test/server/api/StatisticsRoute.test.ts b/test/server/api/StatisticsRoute.test.ts
deleted file mode 100644
index 704db2f68..000000000
--- a/test/server/api/StatisticsRoute.test.ts
+++ /dev/null
@@ -1,31 +0,0 @@
-import request from 'supertest'
-import { container } from '../../../src/server/util/inversify'
-import { DependencyIds } from '../../../src/server/constants'
-import { StatisticsRepository } from '../../../src/server/modules/statistics/interfaces'
-
-const getGlobalStatistics = jest.fn()
-getGlobalStatistics.mockResolvedValue({
- linkCount: 1,
- userCount: 2,
- clickCount: 3,
-})
-// Binds mockups before binding default
-container
- .bind(DependencyIds.statisticsRepository)
- .toConstantValue({ getGlobalStatistics })
-
-// Importing setup app
-// eslint-disable-next-line import/first
-import app from './setup'
-
-describe('GET /api/stats', () => {
- test('get statistics', async (done) => {
- const res = await request(app).get('/api/stats')
- expect(res.status).toBe(200)
- expect(res.ok).toBe(true)
- expect(Object.keys(res.body).sort()).toEqual(
- ['linkCount', 'clickCount', 'userCount'].sort(),
- )
- done()
- })
-})
diff --git a/test/server/api/util.ts b/test/server/api/util.ts
index 6e7f1b44c..0e52a44d9 100644
--- a/test/server/api/util.ts
+++ b/test/server/api/util.ts
@@ -87,13 +87,18 @@ export function createRequestWithEmail(email: any): Request {
* @param {any} user
* @returns A mock Request with the input email and otp.
*/
-export function createRequestWithEmailAndOtp(email: any, otp: any): Request {
+export function createRequestWithEmailAndIpAndOtp(
+ email: any,
+ ip: string,
+ otp: any,
+): Request {
return httpMocks.createRequest({
session: {},
body: {
email,
otp,
},
+ ip,
})
}
diff --git a/test/server/config.ts b/test/server/config.ts
index 9f7d69c9d..c53beeec2 100644
--- a/test/server/config.ts
+++ b/test/server/config.ts
@@ -54,4 +54,7 @@ jest.mock('../../src/server/config', () => ({
gaTrackingId: 'UA-000000-2',
otpRateLimit: 5,
ogHostname: 'go.gov.sg',
+ userCount: 1,
+ clickCount: 2,
+ linkCount: 3,
}))
diff --git a/test/server/mocks/repositories/OtpRepository.ts b/test/server/mocks/repositories/OtpRepository.ts
index 8a137ac7b..f6ebaee4e 100644
--- a/test/server/mocks/repositories/OtpRepository.ts
+++ b/test/server/mocks/repositories/OtpRepository.ts
@@ -7,41 +7,56 @@ import { OtpRepository } from '../../../../src/server/modules/auth/interfaces/Ot
export class OtpRepositoryMock implements OtpRepository {
cache = new Map()
- deleteOtpByEmail = (email: string) => {
- this.cache.delete(email)
+ private getCacheKey(email: string, ip: string): string {
+ return `${email}:${ip}`
+ }
+
+ getRedisKey(email: string, ip: string): string {
+ return this.getCacheKey(email, ip)
+ }
+
+ deleteOtpByEmail = (email: string, ip: string) => {
+ const key = this.getCacheKey(email, ip)
+ this.cache.delete(key)
return Promise.resolve()
}
- setOtpForEmail = (email: string, otp: StorableOtp) => {
- this.cache.set(email, otp)
+ setOtpForEmail = (email: string, ip: string, otp: StorableOtp) => {
+ const key = this.getCacheKey(email, ip)
+ this.cache.set(key, otp)
return Promise.resolve()
}
- getOtpForEmail = (email: string) => {
- if (!this.cache.has(email)) {
+ getOtpForEmail = (email: string, ip: string) => {
+ const key = this.getCacheKey(email, ip)
+ if (!this.cache.has(key)) {
return Promise.resolve(null)
}
- return Promise.resolve(this.cache.get(email)!)
+ return Promise.resolve(this.cache.get(key)!)
}
}
@injectable()
export class OtpRepositoryMockDown implements OtpRepository {
- deleteOtpByEmail(_: string): Promise {
+ getRedisKey(email: string, ip: string): string {
+ return `${email}:${ip}`
+ }
+
+ deleteOtpByEmail(_: string, __: string): Promise {
return Promise.reject(Error())
}
- setOtpForEmail(_: string, __: StorableOtp): Promise {
+ setOtpForEmail(_: string, __: string, ___: StorableOtp): Promise {
return Promise.reject(Error())
}
- getOtpForEmail(_: string): Promise {
+ getOtpForEmail(_: string, __: string): Promise {
return Promise.reject(Error())
}
}
export class OtpRepositoryMockNoWrite extends OtpRepositoryMock {
- deleteOtpByEmail = (_: string) => Promise.reject()
+ deleteOtpByEmail = (_: string, __: string) => Promise.reject()
- setOtpForEmail = (__: string, _: StorableOtp) => Promise.reject()
+ setOtpForEmail = (_: string, __: string, ___: StorableOtp) => Promise.reject()
}
diff --git a/test/server/mocks/repositories/UrlRepository.ts b/test/server/mocks/repositories/UrlRepository.ts
index f9b46f255..b488d2b7e 100644
--- a/test/server/mocks/repositories/UrlRepository.ts
+++ b/test/server/mocks/repositories/UrlRepository.ts
@@ -39,6 +39,10 @@ export class UrlRepositoryMock implements UrlRepositoryInterface {
throw new Error('Not implemented')
}
+ isShortUrlAvailable: (shortUrl: string) => Promise = () => {
+ throw new Error('Not implemented')
+ }
+
getLongUrl: (shortUrl: string) => Promise = () => {
throw new Error('Not implemented')
}
diff --git a/webpack.config.ts b/webpack.config.ts
index 51fe5a336..932eec3f7 100644
--- a/webpack.config.ts
+++ b/webpack.config.ts
@@ -110,7 +110,7 @@ module.exports = () => {
'!/(assets/**|bundle.js|favicon*)': 'http://localhost:8080',
},
historyApiFallback: true,
- disableHostCheck: true,
+ allowedHosts: 'all',
},
devtool: 'source-map',
plugins: [