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

release v0.76.0 #1273

Merged
merged 7 commits into from
Apr 4, 2024
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
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,23 @@ All notable changes to this project will be documented in this file. Dates are d

Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

#### [v0.76.0](https://github.com/isomerpages/isomercms-backend/compare/v0.75.0...v0.76.0)

- fix: external links in top level nav [`#1272`](https://github.com/isomerpages/isomercms-backend/pull/1272)
- Improve APM spans (no more <anonymous>) [`#1267`](https://github.com/isomerpages/isomercms-backend/pull/1267)
- fix: remove unecessary join and site retrieval [`#1268`](https://github.com/isomerpages/isomercms-backend/pull/1268)
- fix(dig): dig not working [`#1246`](https://github.com/isomerpages/isomercms-backend/pull/1246)
- fix(server): server should die if unable to connect to db [`#1265`](https://github.com/isomerpages/isomercms-backend/pull/1265)
- backport v0.75.0 [`#1264`](https://github.com/isomerpages/isomercms-backend/pull/1264)

#### [v0.75.0](https://github.com/isomerpages/isomercms-backend/compare/v0.74.0...v0.75.0)

> 2 April 2024

- feat: carry the name of the wrapped handler [`#1260`](https://github.com/isomerpages/isomercms-backend/pull/1260)
- fix: only release the lock after the handler is done [`#1259`](https://github.com/isomerpages/isomercms-backend/pull/1259)
- backport v0.74.0 [`#1258`](https://github.com/isomerpages/isomercms-backend/pull/1258)
- chore: bump version to v0.75.0 [`b138978`](https://github.com/isomerpages/isomercms-backend/commit/b138978086136e15f42d7fc9484118ea835b42cc)

#### [v0.74.0](https://github.com/isomerpages/isomercms-backend/compare/v0.73.0...v0.74.0)

Expand Down
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ WORKDIR /opt/isomercms-backend
RUN apk update && \
apk add --no-cache bash && \
apk add git && \
apk add openssh-client && \
apk add bind-tools
apk add openssh-client

RUN adduser -u 900 webapp -D -h /home/webapp -s /bin/sh
USER webapp
Expand Down
23 changes: 5 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "isomercms",
"version": "0.75.0",
"version": "0.76.0",
"private": true,
"scripts": {
"build": "tsc -p tsconfig.build.json",
Expand All @@ -27,9 +27,9 @@
"postinstall": "patch-package"
},
"dependencies": {
"@aws-sdk/client-dynamodb": "^3.521.0",
"@aws-sdk/client-amplify": "^3.521.0",
"@aws-sdk/client-cloudwatch-logs": "^3.521.0",
"@aws-sdk/client-dynamodb": "^3.521.0",
"@aws-sdk/client-secrets-manager": "^3.389.0",
"@aws-sdk/lib-dynamodb": "^3.521.0",
"@growthbook/growthbook": "^0.34.0",
Expand Down Expand Up @@ -85,7 +85,6 @@
"morgan": "~1.10.0",
"neverthrow": "^6.1.0",
"nocache": "^3.0.4",
"node-dig-dns": "^0.3.3",
"otplib": "^12.0.1",
"papaparse": "^5.4.1",
"patch-package": "^8.0.0",
Expand Down
19 changes: 12 additions & 7 deletions src/middleware/routeHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,16 @@ const nameRouteHandlerWrapper = <
Params = Record<string, unknown>,
Locals extends Record<string, unknown> = Record<string, unknown>
>(
func: RequestHandler<Params, ResBody, ReqBody, ReqQuery, Locals>,
name: string
wrapper: RequestHandler<Params, ResBody, ReqBody, ReqQuery, Locals>,
original: { name: string }
): RequestHandler<Params, ResBody, ReqBody, ReqQuery, Locals> => {
Object.defineProperty(func, "name", { value: name, writable: false })
return func
if (original.name) {
Object.defineProperty(wrapper, "name", {
value: original.name.replace(/^bound /, ""),
writable: false,
})
}
return wrapper
}

// Used when there are no write API calls to the repo on GitHub
Expand All @@ -96,7 +101,7 @@ export const attachReadRouteHandlerWrapper: RouteWrapper = (routeHandler) =>
Promise.resolve(routeHandler(req, res, next)).catch((err: Error) => {
next(err)
})
}, routeHandler.name)
}, routeHandler)

// Used when there are write API calls to the repo on GitHub
export const attachWriteRouteHandlerWrapper: RouteWrapper<{
Expand Down Expand Up @@ -135,7 +140,7 @@ export const attachWriteRouteHandlerWrapper: RouteWrapper<{
next(err)
}
)
}, routeHandler.name)
}, routeHandler)

export const attachRollbackRouteHandlerWrapper: RouteWrapper<
{
Expand Down Expand Up @@ -340,4 +345,4 @@ export const attachRollbackRouteHandlerWrapper: RouteWrapper<
next(err)
}
)
}, routeHandler.name)
}, routeHandler)
202 changes: 202 additions & 0 deletions src/routes/formsg/__tests__/formsgSiteLaunch.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
import { CaaRecord } from "node:dns"
import dnsPromises from "node:dns/promises"

import UsersService from "@root/services/identity/UsersService"
import InfraService from "@root/services/infra/InfraService"
import { DigDNSRecord } from "@root/services/utilServices/SendDNSRecordEmailClient"
import { SiteLaunchResult } from "@root/types/siteLaunch"

import { FormsgSiteLaunchRouter as _FormsgSiteLaunchRouter } from "../formsgSiteLaunch"

const MockUsersService = ({
findById: jest.fn(),
findByGitHubId: jest.fn(),
findByEmail: jest.fn(),
} as any) as UsersService

const MockInfraService = ({
getSite: jest.fn(),
} as any) as InfraService

const FormsgSiteLaunch = new _FormsgSiteLaunchRouter({
usersService: MockUsersService,
infraService: MockInfraService,
})

const mockResult: SiteLaunchResult = ({
siteName: "testSite",
primaryDomain: "test.com",
primaryDomainSource: "test.com",
} as any) as SiteLaunchResult

const mockResultWithRedirection: SiteLaunchResult = ({
siteName: "testSite",
primaryDomain: "test.com",
primaryDomainSource: "test.com",
redirectionDomainSource: "test.com",
redirectionDomainTarget: "www.test.com",
} as any) as SiteLaunchResult

describe("FormsgSiteLaunchRouter", () => {
it("should add quad A records if any exists", async () => {
// Arrange
jest
.spyOn(dnsPromises, "resolve6")
.mockResolvedValue(["2404:6800:4003:c0f::64", "2404:6800:4003:c0f::8b"])
const expectedResult = [
{
domain: "test.com",
value: "2404:6800:4003:c0f::64",
type: "AAAA",
},
{
domain: "test.com",
value: "2404:6800:4003:c0f::8b",
type: "AAAA",
},
] as DigDNSRecord[]

// Act
const actualResult = await FormsgSiteLaunch.digAAAADomainRecords(mockResult)

// Assert
expect(actualResult).toEqual(expectedResult)
})

it("should not add quad A records if none exists", async () => {
// Arrange
jest.spyOn(dnsPromises, "resolve6").mockResolvedValue([])
const expectedResult = [] as DigDNSRecord[]

// Act
const actualResult = await FormsgSiteLaunch.digAAAADomainRecords(mockResult)

// Assert
expect(actualResult).toEqual(expectedResult)
})

it("should add AWS CAA records if required", async () => {
// Arrange
const caaResult: CaaRecord[] = [
{
critical: 0,
issue: "cloudflaressl.com",
},
]
jest.spyOn(dnsPromises, "resolveCaa").mockResolvedValue(caaResult)
const expectedResult = {
addAWSACMCertCAA: true,
addLetsEncryptCAA: false,
}

// Act
const actualResult = await FormsgSiteLaunch.digCAADomainRecords(mockResult)

// Assert
expect(actualResult).toEqual(expectedResult)
})

it("should not add AWS CAA if not required", async () => {
// Arrange
const caaResult: CaaRecord[] = []
jest.spyOn(dnsPromises, "resolveCaa").mockResolvedValue(caaResult)
const expectedResult = {
addAWSACMCertCAA: false,
addLetsEncryptCAA: false,
}

// Act
const actualResult = await FormsgSiteLaunch.digCAADomainRecords(mockResult)

// Assert
expect(actualResult).toEqual(expectedResult)
})

it("should not add AWS CAA if already present", async () => {
// Arrange
const caaResult: CaaRecord[] = [
{
critical: 0,
issue: "amazon.com",
},
]
jest.spyOn(dnsPromises, "resolveCaa").mockResolvedValue(caaResult)
const expectedResult = {
addAWSACMCertCAA: false,
addLetsEncryptCAA: false,
}

// Act
const actualResult = await FormsgSiteLaunch.digCAADomainRecords(mockResult)

// Assert
expect(actualResult).toEqual(expectedResult)
})

it("should add LetsEncrypt CAA records if required", async () => {
// Arrange
const caaResult: CaaRecord[] = [
{
critical: 0,
issue: "amazon.com",
},
]
jest.spyOn(dnsPromises, "resolveCaa").mockResolvedValue(caaResult)
const expectedResult = {
addAWSACMCertCAA: false,
addLetsEncryptCAA: true,
}

// Act
const actualResult = await FormsgSiteLaunch.digCAADomainRecords(
mockResultWithRedirection
)

// Assert
expect(actualResult).toEqual(expectedResult)
})

it("should not add LetsEncrypt CAA if not required", async () => {
// Arrange
const caaResult: CaaRecord[] = []
jest.spyOn(dnsPromises, "resolveCaa").mockResolvedValue(caaResult)
const expectedResult = {
addAWSACMCertCAA: false,
addLetsEncryptCAA: false,
}

// Act
const actualResult = await FormsgSiteLaunch.digCAADomainRecords(
mockResultWithRedirection
)

// Assert
expect(actualResult).toEqual(expectedResult)
})

it("should not add LetsEncrypt CAA if already present", async () => {
// Arrange
const caaResult: CaaRecord[] = [
{
critical: 0,
issue: "letsencrypt.org",
},
{
critical: 0,
issue: "amazon.com",
},
]
jest.spyOn(dnsPromises, "resolveCaa").mockResolvedValue(caaResult)
const expectedResult = {
addAWSACMCertCAA: false,
addLetsEncryptCAA: false,
}

// Act
const actualResult = await FormsgSiteLaunch.digCAADomainRecords(
mockResultWithRedirection
)
// Assert
expect(actualResult).toEqual(expectedResult)
})
})
2 changes: 2 additions & 0 deletions src/routes/formsg/formsgSiteCreation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { BadRequestError } from "@errors/BadRequestError"
import { getField } from "@utils/formsg-utils"

import { attachFormSGHandler } from "@root/middleware"
import { nameAnonymousMethods } from "@root/utils/apm-utils"
import GitFileSystemService from "@services/db/GitFileSystemService"
import UsersService from "@services/identity/UsersService"
import InfraService from "@services/infra/InfraService"
Expand Down Expand Up @@ -45,6 +46,7 @@ export class FormsgSiteCreateRouter {
this.infraService = infraService
this.gitFileSystemService = gitFileSystemService
// We need to bind all methods because we don't invoke them from the class directly
nameAnonymousMethods(this)
autoBind(this)
}

Expand Down
Loading
Loading