Skip to content

Commit

Permalink
Merge branch 'develop' into fix-formik-validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Zangetsu101 authored Dec 23, 2024
2 parents 5b02693 + e290682 commit 76284d5
Show file tree
Hide file tree
Showing 322 changed files with 13,299 additions and 9,717 deletions.
4 changes: 2 additions & 2 deletions packages/auth/src/features/authenticate/handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
*/
import * as fetchAny from 'jest-fetch-mock'
import { createProductionEnvironmentServer } from '@auth/tests/util'
import { createServer } from '@auth/server'
import { AuthServer, createServer } from '@auth/server'

const fetch = fetchAny as fetchAny.FetchMock
describe('authenticate handler receives a request', () => {
let server: any
let server: AuthServer

beforeEach(async () => {
server = await createServer()
Expand Down
8 changes: 8 additions & 0 deletions packages/auth/src/features/authenticate/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,11 @@ export const responseSchema = Joi.object({
status: Joi.string(),
token: Joi.string().optional()
})

export type AuthenticateResponse = {
nonce: string
mobile?: string
email?: string
status: string
token?: string
}
2 changes: 2 additions & 0 deletions packages/auth/src/features/authenticate/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const sign = promisify<
jwt.SignOptions,
string
>(jwt.sign)

export interface IUserName {
use: string
family: string
Expand Down Expand Up @@ -213,6 +214,7 @@ export async function generateAndSendVerificationCode(
} else {
verificationCode = await generateVerificationCode(nonce)
}

if (!env.isProd || env.QA_ENV) {
logger.info(
`Sending a verification to,
Expand Down
4 changes: 2 additions & 2 deletions packages/auth/src/features/invalidateToken/handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
*
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
*/
import { createServer } from '@auth/server'
import { AuthServer, createServer } from '@auth/server'
import { get, setex } from '@auth/database'
import { INVALID_TOKEN_NAMESPACE } from '@auth/constants'

describe('invalidate token handler', () => {
let server: any
let server: AuthServer

beforeEach(async () => {
server = await createServer()
Expand Down
4 changes: 2 additions & 2 deletions packages/auth/src/features/oauthToken/handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
*/
import * as fetchAny from 'jest-fetch-mock'
import { createServer } from '@auth/server'
import { AuthServer, createServer } from '@auth/server'
import * as authService from '@auth/features/authenticate/service'

const fetch = fetchAny as fetchAny.FetchMock
describe('authenticate handler receives a request', () => {
let server: any
let server: AuthServer

beforeEach(async () => {
server = await createServer()
Expand Down
85 changes: 52 additions & 33 deletions packages/auth/src/features/refresh/handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
*
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
*/
import { AuthServer } from '@auth/server'
import { createProductionEnvironmentServer } from '@auth/tests/util'
import { AuthenticateResponse } from '@auth/features/authenticate/handler'

describe('authenticate handler receives a request', () => {
let server: any
let server: AuthServer

beforeEach(async () => {
server = await createProductionEnvironmentServer()
Expand All @@ -31,37 +33,47 @@ describe('authenticate handler receives a request', () => {
mobile: '+345345343'
})

const authRes = await server.server.inject({
method: 'POST',
url: '/authenticate',
payload: {
username: '+345345343',
password: '2r23432'
}
})
const authRes: { result?: AuthenticateResponse } =
await server.server.inject({
method: 'POST',
url: '/authenticate',
payload: {
username: '+345345343',
password: '2r23432'
}
})

expect(authRes.result).toBeDefined()

const authCode = codeSpy.mock.calls[0][0]
const res = await server.server.inject({
const res: { result?: { token: string } } = await server.server.inject({
method: 'POST',
url: '/verifyCode',
payload: {
nonce: authRes.result.nonce,
nonce: authRes.result!.nonce,
code: authCode
}
})

const refreshResponse = await server.server.inject({
method: 'POST',
url: '/refreshToken',
payload: {
nonce: authRes.result.nonce,
token: res.result.token
}
})
expect(res.result).toBeDefined()

const refreshResponse: { result?: { token: string } } =
await server.server.inject({
method: 'POST',
url: '/refreshToken',
payload: {
nonce: authRes.result!.nonce,
token: res.result!.token
}
})
expect(refreshResponse.result).toBeDefined()

const { token } = refreshResponse.result!

expect(refreshResponse.result.token).toBeDefined()
expect(refreshResponse.result.token.split('.')).toHaveLength(3)
expect(token).toBeDefined()
expect(token.split('.')).toHaveLength(3)

const [, payload] = refreshResponse.result.token.split('.')
const [, payload] = token.split('.')
const body = JSON.parse(Buffer.from(payload, 'base64').toString())
expect(body.scope).toEqual(['admin'])
expect(body.sub).toBe('1')
Expand All @@ -78,31 +90,38 @@ describe('authenticate handler receives a request', () => {
username: '+345345343'
})

const authRes = await server.server.inject({
method: 'POST',
url: '/authenticate',
payload: {
username: '+345345343',
password: '2r23432'
}
})
const authRes: { result?: AuthenticateResponse } =
await server.server.inject({
method: 'POST',
url: '/authenticate',
payload: {
username: '+345345343',
password: '2r23432'
}
})
const smsCode = codeSpy.mock.calls[0][1]

expect(authRes.result).toBeDefined()

await server.server.inject({
method: 'POST',
url: '/verifyCode',
payload: {
nonce: authRes.result.nonce,
nonce: authRes.result!.nonce,
code: smsCode
}
})

const badToken = 'ilgiglig'

const refreshResponse = await server.server.inject({
const refreshResponse: {
result?: { token: string }
statusCode: number
} = await server.server.inject({
method: 'POST',
url: '/refreshToken',
payload: {
nonce: authRes.result.nonce,
nonce: authRes.result!.nonce,
token: badToken
}
})
Expand Down
4 changes: 2 additions & 2 deletions packages/auth/src/features/resend/handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import {
createProductionEnvironmentServer,
createServerWithEnvironment
} from '@auth/tests/util'
import { createServer } from '@auth/server'
import { AuthServer, createServer } from '@auth/server'

describe('resend handler receives a request', () => {
let server: any
let server: AuthServer

beforeEach(async () => {
server = await createServer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
*/
import * as fetchAny from 'jest-fetch-mock'
import { createServer } from '@auth/server'
import { AuthServer, createServer } from '@auth/server'
import {
storeRetrievalStepInformation,
RetrievalSteps
Expand All @@ -18,7 +18,7 @@ import {
const fetch = fetchAny as fetchAny.FetchMock

describe('password change', () => {
let server: any
let server: AuthServer

beforeEach(async () => {
server = await createServer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
*/
import * as fetchAny from 'jest-fetch-mock'
import { createServer } from '@auth/server'
import { AuthServer, createServer } from '@auth/server'
import {
storeRetrievalStepInformation,
RetrievalSteps
Expand All @@ -19,7 +19,7 @@ import { logger } from '@opencrvs/commons'
const fetch = fetchAny as fetchAny.FetchMock

describe('username reminder', () => {
let server: any
let server: AuthServer

beforeEach(async () => {
server = await createServer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
*
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
*/
import { createServer } from '@auth/server'
import { AuthServer, createServer } from '@auth/server'
import * as codeService from '@auth/features/verifyCode/service'
import * as retrievalService from '@auth/features/retrievalSteps/verifyUser/service'
import * as fetchAny from 'jest-fetch-mock'
const fetch = fetchAny as fetchAny.FetchMock

describe('verifyNumber handler receives a request', () => {
let server: any
let server: AuthServer

beforeEach(async () => {
server = await createServer()
Expand All @@ -33,19 +33,25 @@ describe('verifyNumber handler receives a request', () => {
securityQuestionKey: 'dummyKey'
})
)
const stepOneRes = await server.server.inject({
const stepOneRes: {
result?: { nonce: string; securityQuestionKey?: string }
} = await server.server.inject({
method: 'POST',
url: '/verifyUser',
payload: { mobile: '+8801711111111', retrieveFlow: 'password' }
})

const stepOneResNonce = stepOneRes.result?.nonce ?? undefined

expect(stepOneResNonce).toBe('12345')

const res = await server.server.inject({
method: 'POST',
url: '/verifyNumber',
payload: { nonce: stepOneRes.result.nonce, code: '000000' }
payload: { nonce: stepOneResNonce, code: '000000' }
})
expect(res.statusCode).toBe(200)
expect(JSON.parse(res.payload).nonce).toBe(stepOneRes.result.nonce)
expect(JSON.parse(res.payload).nonce).toBe(stepOneResNonce)
expect(JSON.parse(res.payload).securityQuestionKey).toBe('dummyKey')
})
it('throws error for an invalid nonce', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
*/
import * as fetchAny from 'jest-fetch-mock'
import { createServer } from '@auth/server'
import { AuthServer, createServer } from '@auth/server'
import {
RetrievalSteps,
storeRetrievalStepInformation,
Expand All @@ -19,7 +19,7 @@ import {
const fetch = fetchAny as fetchAny.FetchMock

describe('security question answer checking', () => {
let server: any
let server: AuthServer

beforeEach(async () => {
server = await createServer()
Expand Down Expand Up @@ -52,7 +52,10 @@ describe('security question answer checking', () => {
})

describe('when submitted security answer is correct', () => {
let res: any
let res: {
statusCode: number
payload: string
}
beforeEach(async () => {
res = await server.server.inject({
method: 'POST',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
import * as fetchAny from 'jest-fetch-mock'
import { createProductionEnvironmentServer } from '@auth/tests/util'
import * as codeService from '@auth/features/verifyCode/service'
import { createServer } from '@auth/server'
import { AuthServer, createServer } from '@auth/server'

const fetch = fetchAny as fetchAny.FetchMock

describe('verifyUser handler receives a request', () => {
let server: any
let server: AuthServer

beforeEach(async () => {
server = await createServer()
Expand Down
Loading

0 comments on commit 76284d5

Please sign in to comment.