Skip to content

Commit 7486a1a

Browse files
authored
JavaScript (v3): Task - Fix outdated cert; test improvements. (#5890)
1 parent 3c907b0 commit 7486a1a

File tree

7 files changed

+37
-169
lines changed

7 files changed

+37
-169
lines changed

Diff for: .tools/validation/validator_config.py

-2
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,6 @@ def skip(path):
204204
"chat_sfn_state_machine.json",
205205
"market_2.jpg",
206206
"movies.json",
207-
"sample_cert.pem",
208-
"sample_private_key.pem",
209207
"sample_saml_metadata.xml",
210208
"speech_sample.mp3",
211209
"spheres_2.jpg",

Diff for: javascriptv3/example_code/cross-services/wkflw-resilient-service/tests/wkflw.integration.test.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@ import { scenarios } from "../index.js";
44

55
describe("workflow", () => {
66
it("should run without error", async () => {
7-
await scenarios.deploy.run({ confirmAll: true, verbose: true });
8-
await scenarios.demo.run({ confirmAll: true, verbose: true });
9-
await scenarios.destroy.run({ confirmAll: true, verbose: true });
7+
try {
8+
await scenarios.deploy.run({ confirmAll: true, verbose: true });
9+
await scenarios.demo.run({ confirmAll: true, verbose: true });
10+
await scenarios.destroy.run({ confirmAll: true, verbose: true });
11+
} catch (err) {
12+
await scenarios.destroy.run({ confirmAll: true, verbose: true });
13+
throw err;
14+
}
1015
});
1116
});

Diff for: javascriptv3/example_code/iam/actions/upload-server-certificate.js

+29-26
Original file line numberDiff line numberDiff line change
@@ -13,40 +13,43 @@ import * as path from "path";
1313

1414
const client = new IAMClient({});
1515

16-
/**
17-
* The certificate body and private key were generated with the
18-
* following command.
19-
*
20-
* ```
21-
* openssl req -x509 -newkey rsa:4096 -sha256 -days 3650 -nodes \
22-
* -keyout example.key -out example.crt -subj "/CN=example.com" \
23-
* -addext "subjectAltName=DNS:example.com,DNS:www.example.net,IP:10.0.0.1"
24-
* ```
25-
*/
26-
27-
const certBody = readFileSync(
28-
path.join(
29-
dirnameFromMetaUrl(import.meta.url),
30-
"../../../../resources/sample_files/sample_cert.pem",
31-
),
32-
);
33-
34-
const privateKey = readFileSync(
35-
path.join(
36-
dirnameFromMetaUrl(import.meta.url),
37-
"../../../../resources/sample_files/sample_private_key.pem",
38-
),
39-
);
16+
const certMessage = `Generate a certificate and key with the following command, or the equivalent for your system.
17+
18+
openssl req -x509 -newkey rsa:4096 -sha256 -days 3650 -nodes \
19+
-keyout example.key -out example.crt -subj "/CN=example.com" \
20+
-addext "subjectAltName=DNS:example.com,DNS:www.example.net,IP:10.0.0.1"
21+
`;
22+
23+
const getCertAndKey = () => {
24+
try {
25+
const cert = readFileSync(
26+
path.join(dirnameFromMetaUrl(import.meta.url), "./example.crt")
27+
);
28+
const key = readFileSync(
29+
path.join(dirnameFromMetaUrl(import.meta.url), "./example.key")
30+
);
31+
return { cert, key };
32+
} catch (err) {
33+
if (err.code === "ENOENT") {
34+
throw new Error(
35+
`Certificate and/or private key not found. ${certMessage}`
36+
);
37+
}
38+
39+
throw err;
40+
}
41+
};
4042

4143
/**
4244
*
4345
* @param {string} certificateName
4446
*/
4547
export const uploadServerCertificate = (certificateName) => {
48+
const { cert, key } = getCertAndKey();
4649
const command = new UploadServerCertificateCommand({
4750
ServerCertificateName: certificateName,
48-
CertificateBody: certBody.toString(),
49-
PrivateKey: privateKey.toString(),
51+
CertificateBody: cert.toString(),
52+
PrivateKey: key.toString(),
5053
});
5154

5255
return client.send(command);

Diff for: javascriptv3/example_code/iam/tests/server-certificate.integration.test.js

-50
This file was deleted.

Diff for: resources/sample_files/README.md

-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,5 @@ These files are included as shared sample data files for use in examples in this
55
* [speech_sample.mp3](.sample_media/speech_sample.mp3) `A sample audio file of speech used for Amazon Transcribe examples.`
66
* [spheres_2.jpg](.sample_media/spheres_2.jpg) `A sample image of the Amazon Spheres in Seattle.`
77
* [market_2.jpg](.sample_media/market_2.jpg) `A sample image of the public market in Seattle.`
8-
* [sample_cert.pem](./sample_cert.pem) `A sample certificate PEM file.`
9-
* [sample_private_key.pem](./sample_private_key.pem) `A sample private key PEM file.`
108
* [sample_saml_metadata.xml](./sample_saml_metadata.xml) `A sample SAML metadata file for creating a SAML provider.`
119

Diff for: resources/sample_files/sample_cert.pem

-34
This file was deleted.

Diff for: resources/sample_files/sample_private_key.pem

-52
This file was deleted.

0 commit comments

Comments
 (0)