Skip to content

Commit

Permalink
improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kikidawson-gds committed Feb 25, 2025
1 parent 4c1ac19 commit 03bd913
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 37 deletions.
36 changes: 18 additions & 18 deletions backend-api/tests/infra-tests/application.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,24 @@ describe("Backend application infrastructure", () => {
});
});

describe("API Gateways", () => {
test("They should always pin ACM certificates to a version", () => {
const lines = readFileSync("template.yaml", "utf-8").split("\n");
const regexMatcher1 =
/\-\s\!Sub\s\'\{\{resolve:ssm:\/\$\{Environment\}\/Platform\/ACM\/.*\}\}\'/;
const regexMatcher2 = /.*:[1-9]+.*/;

let resolveSsmLines = new Array();

lines.forEach((line) => {
if (regexMatcher1.test(line.trim())) {
resolveSsmLines.push(line.trim());
}
});

resolveSsmLines.forEach((resolveSsmLine) => {
expect(resolveSsmLine).toEqual(expect.stringMatching(regexMatcher2));
});
describe("Domain Names", () => {
test("They should always pin ACM certificates to an SSM Parameter version", () => {
const resolveSsmWildcardCertRegex = /{{resolve:ssm:\/\$\{Environment\}\/Platform\/ACM\/AsyncPrimaryZoneWildcardCertificateARN:[0-9]+}}/
const resolveSsmCertRegex = /{{resolve:ssm:\/\$\{Environment\}\/Platform\/ACM\/[a-zA-Z]+:[0-9]+}}/

let resolveSsmWildcardCert = new Capture()
let resolveSsmCert = new Capture()

template.allResourcesProperties("AWS::ApiGateway::DomainName", {
"RegionalCertificateArn": { "Fn::If": [
"DevelopmentStack",
{ "Fn::Sub": resolveSsmWildcardCert},
{ "Fn::Sub": resolveSsmCert},
] }
})

expect(resolveSsmWildcardCert.asString()).toEqual(expect.stringMatching(resolveSsmWildcardCertRegex));
expect(resolveSsmCert.asString()).toEqual(expect.stringMatching(resolveSsmCertRegex));
});
});

Expand Down
40 changes: 21 additions & 19 deletions test-resources/tests/infrastructure-tests/application.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,6 @@ describe("STS mock infrastructure", () => {
});
});

test("They should always pin ACM certificates to a version", () => {
const lines = readFileSync("template.yaml", "utf-8").split("\n");
const regexMatcher1 =
/\-\s\!Sub\s\'\{\{resolve:ssm:\/\$\{Environment\}\/Platform\/ACM\/.*\}\}\'/;
const regexMatcher2 = /.*:[1-9]+.*/;

let resolveSsmLines = new Array();

lines.forEach((line) => {
if (regexMatcher1.test(line.trim())) {
resolveSsmLines.push(line.trim());
}
});

resolveSsmLines.forEach((resolveSsmLine) => {
expect(resolveSsmLine).toEqual(expect.stringMatching(regexMatcher2));
});
});

describe("API Gateway method settings", () => {
test("metrics are enabled", () => {
const methodSettings = new Capture();
Expand Down Expand Up @@ -113,6 +94,27 @@ describe("STS mock infrastructure", () => {
});
});

describe("Domain Names", () => {
test("They should always pin ACM certificates to an SSM Parameter version", () => {
const resolveSsmWildcardCertRegex = /{{resolve:ssm:\/\$\{Environment\}\/Platform\/ACM\/AsyncPrimaryZoneWildcardCertificateARN:[0-9]+}}/
const resolveSsmCertRegex = /{{resolve:ssm:\/\$\{Environment\}\/Platform\/ACM\/[a-zA-Z]+:[0-9]+}}/

let resolveSsmWildcardCert = new Capture()
let resolveSsmCert = new Capture()

template.allResourcesProperties("AWS::ApiGateway::DomainName", {
"RegionalCertificateArn": { "Fn::If": [
"DevelopmentStack",
{ "Fn::Sub": resolveSsmWildcardCert},
{ "Fn::Sub": resolveSsmCert},
] }
})

expect(resolveSsmWildcardCert.asString()).toEqual(expect.stringMatching(resolveSsmWildcardCertRegex));
expect(resolveSsmCert.asString()).toEqual(expect.stringMatching(resolveSsmCertRegex));
});
});

test("access log group is attached to the API gateway", () => {
template.hasResourceProperties("AWS::Serverless::Api", {
Name: { "Fn::Sub": "${AWS::StackName}-api" },
Expand Down

0 comments on commit 03bd913

Please sign in to comment.