Skip to content

Commit

Permalink
fix(dig): dig not working
Browse files Browse the repository at this point in the history
  • Loading branch information
kishore03109 committed Apr 1, 2024
1 parent 1c4b7ea commit f00c2db
Show file tree
Hide file tree
Showing 9 changed files with 349 additions and 122 deletions.
19 changes: 3 additions & 16 deletions package-lock.json

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

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
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)
})
})
Loading

0 comments on commit f00c2db

Please sign in to comment.