Skip to content
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

Production deploy #2573

Merged
merged 5 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
23 changes: 12 additions & 11 deletions api.planx.uk/modules/send/uniform/uniform.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import axios, { AxiosRequestConfig, isAxiosError } from "axios";
import { NextFunction, Request, Response } from "express";
import { Buffer } from "node:buffer";
import FormData from "form-data";
import fs from "fs";
import { markSessionAsSubmitted } from "../../saveAndReturn/service/utils";
import { gql } from "graphql-request";
import jwt from "jsonwebtoken";
import { Buffer } from "node:buffer";
import { $api } from "../../../client";
import { markSessionAsSubmitted } from "../../saveAndReturn/service/utils";
import { buildSubmissionExportZip } from "../utils/exportZip";

interface UniformClient {
Expand All @@ -21,8 +22,6 @@ interface UniformSubmissionResponse {

interface RawUniformAuthResponse {
access_token: string;
"organisation-name": string;
"organisation-id": string;
}

interface UniformAuthResponse {
Expand Down Expand Up @@ -204,19 +203,21 @@ async function authenticate({
throw Error("Failed to authenticate to Uniform - no access token returned");
}

if (
!response.data["organisation-name"] ||
!response.data["organisation-id"]
) {
// Decode access_token to get "organisation-name" & "organisation-id"
const decodedAccessToken = jwt.decode(response.data.access_token) as any;
const organisation = decodedAccessToken?.["organisation-name"];
const organisationId = decodedAccessToken?.["organisation-id"];

if (!organisation || !organisationId) {
throw Error(
"Failed to authenticate to Uniform - no organisation details returned",
"Failed to authenticate to Uniform - failed to decode organisation details from access_token",
);
}

const uniformAuthResponse: UniformAuthResponse = {
token: response.data.access_token,
organisation: response.data["organisation-name"],
organisationId: response.data["organisation-id"],
organisation: organisation,
organisationId: organisationId,
};

return uniformAuthResponse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"messsage": "MOCKED RESPONSE"
}

# UNIFORM token generation
# UNIFORM token generation, access_token is mock JWT with "organisation-name" & "organisation-id" properties
- request:
method: POST
path: /
Expand All @@ -21,9 +21,9 @@
Content-Type: application/json
body: >
{
"access_token": "TEST_TOKEN",
"organisation-name": "MOCKED",
"organisation-id": "MOCKED"
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJvcmdhbmlzYXRpb24tbmFtZSI6Ik1PQ0tFRCIsIm9yZ2FuaXNhdGlvbi1pZCI6Ik1PQ0tFRCJ9.p0DE8MUc9obE751XWOYPQWWtLXtq8-kJMPre4VuOBHg",
"token_type": "Bearer",
"expires_in": 35999
}

# UNIFORM submissions
Expand Down
2 changes: 1 addition & 1 deletion editor.planx.uk/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
}
],
"@typescript-eslint/no-unused-vars": [
"error",
"warn",
{
"varsIgnorePattern": "^_",
"argsIgnorePattern": "^_"
Expand Down
4 changes: 4 additions & 0 deletions infrastructure/application/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,10 @@ export = async () => {
includeSubdomains: true,
preload: true,
},
// Set X-Content-Type-Options = "nosniff"
contentTypeOptions: {
override: true,
},
},
}
).id,
Expand Down
Loading