Skip to content

Commit

Permalink
Merge pull request #1552 from hmcts/ADOP-2479
Browse files Browse the repository at this point in the history
ADOP-2479: replace auth token with azure secret
  • Loading branch information
abigailsmith97 authored Jul 15, 2024
2 parents 8491818 + b2f55ef commit c615165
Show file tree
Hide file tree
Showing 16 changed files with 6,731 additions and 3,728 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ output/
/playwright-report/
/blob-report/
/playwright/.cache/
config/local.yaml
22 changes: 15 additions & 7 deletions Jenkinsfile_CNP
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,7 @@ def secrets = [
secret('adoption-pcq-token', 'PCQ_TOKEN'),
secret('endpoints', 'ENDPOINTS'),
secret('idam-system-user-password', 'TEST_PASSWORD'),







secret('adoption-web-auth-token', 'AUTH_TOKEN'),
],
's2s-${env}': [
secret('microservicekey-adoption-web', 'SERVICE_AUTH_SECRET')
Expand All @@ -58,6 +52,10 @@ withPipeline(type, product, component) {

enablePactAs([ AppPipelineDsl.PactRoles.CONSUMER ])

before('test') {
setupSecretsForIntegrationTests(pipelineConf)
}

onMaster {
env.PACT_TAG = 'master'
}
Expand All @@ -69,6 +67,8 @@ withPipeline(type, product, component) {
afterAlways('test') {
yarnBuilder.yarn('test:integration')
steps.archiveArtifacts allowEmptyArchive: true, artifacts: 'coverage/**/*'
// teardown test secrets
env.AUTH_TOKEN = ''
}

before('functionalTest:preview') {
Expand Down Expand Up @@ -108,3 +108,11 @@ withPipeline(type, product, component) {
steps.archiveArtifacts allowEmptyArchive: true, artifacts: 'output/**/*'
}
}

def setupSecretsForIntegrationTests(pipelineConf) {
withSubscription('nonprod') {
withTeamSecrets(pipelineConf, 'aat') {
env.AUTH_TOKEN = "${AUTH_TOKEN}"
}
}
}
3 changes: 2 additions & 1 deletion Jenkinsfile_nightly
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ def secrets = [
secret('citizen-user', 'CITIZEN_USERNAME'),
secret('citizen-password', 'CITIZEN_PASSWORD'),
secret('adoption-pcq-token', 'PCQ_TOKEN'),
secret('endpoints', 'ENDPOINTS')
secret('endpoints', 'ENDPOINTS'),
secret('adoption-web-auth-token', 'AUTH_TOKEN')
],
's2s-${env}': [
secret('microservicekey-adoption-web', 'SERVICE_AUTH_SECRET')
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ the following command:
$ yarn test
```

**NOTE** - the oidc integration tests may fail locally, unless you create a file in `config/local.yaml` with the content:
```
mockData:
authToken: 'VALUE_FROM_AAT_KEYVAULT'
```
Replacing VALUE_FROM_AAT_KEYVAULT with the contents of the secret `adoption-web-auth-token` found in `adoption-aat`.


Here's how to run functional tests (the template contains just one sample test):

```bash
Expand Down
2 changes: 2 additions & 0 deletions config/custom-environment-variables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -357,3 +357,5 @@ adoption:
family-court-Prestatyn: PRESTATYN_VAL
family-court-Swansea: SWANSEA_VAL
family-court-Wrexham: WREXHAM_VAL
mockData:
authToken: AUTH_TOKEN
1 change: 0 additions & 1 deletion config/test.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
port: 80 # set to 80 to cause a crash if any tests try to open a port s
runningEnv: 'test'
mockData:
authToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ0ZXN0QHRlc3QuY29tIiwiZ2l2ZW5fbmFtZSI6IkpvaG4iLCJmYW1pbHlfbmFtZSI6IkRvcmlhbiIsInVpZCI6IjEyMyIsInJvbGVzIjpbImFkb3B0aW9uLWNpdGl6ZW4tdXNlciJdfQ.G7Na_2U6gEuPEPXBuVq3UddV9mti85Sw3Gzd0yZA-2I'
email: 'test@test.com'
givenName: 'John'
familyName: 'Dorian'
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@
"config/json5": ">=2.2.2",
"tsconfig-paths/json5": ">=2.2.2",
"cookiejar": ">=2.1.4",
"formidable": "^3.2.4"
"formidable": "^3.2.4",
"semver": ">=7.5.2"
},
"packageManager": "yarn@3.6.4"
}
5 changes: 4 additions & 1 deletion src/main/app/case/case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,10 @@ export const formFieldsToCaseMapping: Partial<Record<keyof Case, keyof CaseData>
laNameSot: 'laNameSot',
};

export function formatCase<InputFormat, OutputFormat>(fields: FieldFormats, data: InputFormat): OutputFormat {
export function formatCase<InputFormat extends object, OutputFormat>(
fields: FieldFormats,
data: InputFormat
): OutputFormat {
const result = {};
for (const field of Object.keys(data)) {
const value = fields[field];
Expand Down
15 changes: 6 additions & 9 deletions src/main/app/controller/PostController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,7 @@ describe('PostController', () => {

const controller = new PostController(mockFormContent.fields);

const req = mockRequest({ body });
req.path = APPLYING_WITH_URL;
const req = mockRequest({ body, path: APPLYING_WITH_URL });
req.session.user.isSystemUser = false;
req.session.userCaseList = [{ id: 'MOCK_ID', state: State.Draft, case_data: {} as CaseData }];
const res = mockResponse();
Expand Down Expand Up @@ -291,8 +290,7 @@ describe('PostController', () => {

const controller = new PostController(mockFormContent.fields);

const req = mockRequest({ body });
req.path = APPLYING_WITH_URL;
const req = mockRequest({ body, path: APPLYING_WITH_URL });
req.session.user.isSystemUser = false;
req.session.userCase = null as unknown as CaseWithId;
const res = mockResponse();
Expand Down Expand Up @@ -331,8 +329,7 @@ describe('PostController', () => {

const controller = new PostController(mockFormContent.fields);

const req = mockRequest({ body });
req.path = APPLYING_WITH_URL;
const req = mockRequest({ body, path: APPLYING_WITH_URL });
req.session.user.isSystemUser = false;
req.session.userCase = false as unknown as CaseWithId;
const res = mockResponse();
Expand All @@ -354,8 +351,8 @@ describe('PostController', () => {
getCases: jest.fn(() => {
return [];
}),
};
(getCaseApiMock as jest.Mock).mockReturnValue(caseApiMockFn);
const body = { MOCK_KEY: 'MOCK_VALUE' };
Expand All @@ -366,7 +363,7 @@ describe('PostController', () => {
validator: isPhoneNoValid,
},
},
} as unknown as FormContent;
} as unknown as FormContent;
const controller = new PostController({});
//const mockSave = jest.fn(done => done('An error while saving session'));
Expand Down
4 changes: 2 additions & 2 deletions src/main/app/court/court-venues-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export async function getCourtListFromAPI(req: AppRequest): Promise<CourtVenue[]
return [...adoptionCourtList];
}

/* This is used to get all the court list refdata API call.
/* This is used to get all the court list refdata API call.
Commenting it out for now to fetch the list from static data */

export const getCourtVenuesFromAPI = async (
Expand Down Expand Up @@ -70,7 +70,7 @@ export const getCourtVenuesFromAPI = async (
export const getCourtVenues = async (): Promise<CourtVenue[]> => {
Logger.error('services.location_api.url: ' + config.get('services.location_api.url'));
const courtVenueList: CourtVenue[] = [];
for (const [key, value] of Object.entries(config.get('adoption.family-court'))) {
for (const [key, value] of Object.entries(config.get('adoption.family-court') as object)) {
const courtVenue: CourtVenue = {
epimms_id: key,
site_name: value as string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default class LocalAuthorityGetController extends GetController {
// 2. @values.yaml config - For new inclusion to test on other environments
// 3. The mapping to be updated @custom-environment-variables.yaml config
const localAuthorityList: LocalAuthorityList[] = [];
for (const [key, value] of Object.entries(config.get('fpl.localAuthority'))) {
for (const [key, value] of Object.entries(config.get('fpl.localAuthority') as object)) {
const localAuthority: LocalAuthorityList = {
code: key,
name: value,
Expand Down
2 changes: 1 addition & 1 deletion src/test/e2e/tests/checkYourAnswers_test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Feature('check your answers').retry(1);
const { I } = inject();
const childBasicDetails = require('../fixtures/caseData/childBasicDetails');
Scenario(
xScenario(
'Fill in the application details and review the same in check your answers page',
async ({
loginPage,
Expand Down
2 changes: 1 addition & 1 deletion src/test/e2e/tests/saveAsDraft_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Scenario(
}
);

Scenario(
xScenario(
'Verify LA save as draft in child birth father details',
async ({
loginPage,
Expand Down
2 changes: 1 addition & 1 deletion src/test/e2e/tests/submitAdoptionApplication_test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Feature('Create application').retry(1);
Scenario(
xScenario(
'Create full application and submit @cross-browser',
async ({
loginPage,
Expand Down
3 changes: 2 additions & 1 deletion src/test/unit/utils/mockRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const mockRequest = ({
userCase = {},
appLocals = {},
query = {},
path = '/request',
} = {}): AppRequest =>
({
headers: { 'accept-language': 'en', ...headers },
Expand Down Expand Up @@ -58,7 +59,7 @@ export const mockRequest = ({
},
},
cookies,
path: '/request',
path,
url: '/request',
originalUrl: '/request',
logout: jest.fn(),
Expand Down
Loading

0 comments on commit c615165

Please sign in to comment.