@defra/grants-config-utils 0.6.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/check-pull-request.yml +4 -4
- package/.github/workflows/release.yml +3 -3
- package/AGENTS.md +4 -0
- package/CHANGELOG.md +15 -0
- package/package.json +22 -12
- package/src/broker/broker-auth-helper.js +7 -60
- package/src/broker/broker-auth-helper.test.js +50 -231
- package/src/config/config.js +16 -12
- package/src/service/config-store-and-inform.js +7 -40
- package/src/service/config-store-and-inform.test.js +9 -61
- package/src/sqs/sqs-subscriber.js +122 -0
- package/src/sqs/sqs-subscriber.test.js +236 -0
- package/src/sqs/trace-parent.js +8 -0
- package/src/sqs/trace-parent.test.js +13 -0
- package/src/sts/grants-config-broker-token.js +19 -0
- package/src/sts/grants-config-broker-token.test.js +44 -0
- package/src/sts/sts-client-plugin.js +19 -0
- package/src/sts/sts-client-plugin.test.js +76 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { stsClientPlugin } from "./sts-client-plugin.js";
|
|
2
|
+
import { STSClient } from "@aws-sdk/client-sts";
|
|
3
|
+
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
4
|
+
|
|
5
|
+
vi.mock("@aws-sdk/client-sts", () => {
|
|
6
|
+
return {
|
|
7
|
+
STSClient: vi.fn().mockImplementation(function () {
|
|
8
|
+
this.destroy = vi.fn();
|
|
9
|
+
return this;
|
|
10
|
+
}),
|
|
11
|
+
};
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
describe("stsClientPlugin", () => {
|
|
15
|
+
let server;
|
|
16
|
+
|
|
17
|
+
beforeEach(() => {
|
|
18
|
+
vi.clearAllMocks();
|
|
19
|
+
|
|
20
|
+
server = {
|
|
21
|
+
decorate: vi.fn(),
|
|
22
|
+
events: {
|
|
23
|
+
on: vi.fn(),
|
|
24
|
+
},
|
|
25
|
+
logger: {
|
|
26
|
+
info: vi.fn(),
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("should have correct name and version", () => {
|
|
32
|
+
expect(stsClientPlugin.plugin.name).toBe("sts-client");
|
|
33
|
+
expect(stsClientPlugin.plugin.version).toBe("1.0.0");
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("should register the plugin and decorate server and request", () => {
|
|
37
|
+
stsClientPlugin.plugin.register(server);
|
|
38
|
+
|
|
39
|
+
expect(STSClient).toHaveBeenCalled();
|
|
40
|
+
const mockStsInstance = vi.mocked(STSClient).mock.results[0].value;
|
|
41
|
+
expect(server.decorate).toHaveBeenCalledWith(
|
|
42
|
+
"server",
|
|
43
|
+
"sts",
|
|
44
|
+
mockStsInstance,
|
|
45
|
+
);
|
|
46
|
+
expect(server.decorate).toHaveBeenCalledWith(
|
|
47
|
+
"request",
|
|
48
|
+
"sts",
|
|
49
|
+
expect.any(Function),
|
|
50
|
+
{ apply: true },
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
const decorateRequestFn = server.decorate.mock.calls.find(
|
|
54
|
+
(call) => call[0] === "request",
|
|
55
|
+
)[2];
|
|
56
|
+
expect(decorateRequestFn()).toBe(mockStsInstance);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("should handle server stop event", () => {
|
|
60
|
+
let stopHandler;
|
|
61
|
+
server.events.on.mockImplementation((event, handler) => {
|
|
62
|
+
if (event === "stop") {
|
|
63
|
+
stopHandler = handler;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
stsClientPlugin.plugin.register(server);
|
|
67
|
+
expect(server.events.on).toHaveBeenCalledWith("stop", expect.any(Function));
|
|
68
|
+
expect(stopHandler).toBeDefined();
|
|
69
|
+
|
|
70
|
+
stopHandler();
|
|
71
|
+
|
|
72
|
+
const mockStsInstance = vi.mocked(STSClient).mock.results[0].value;
|
|
73
|
+
expect(server.logger.info).toHaveBeenCalledWith("Closing AWS SDK clients");
|
|
74
|
+
expect(mockStsInstance.destroy).toHaveBeenCalled();
|
|
75
|
+
});
|
|
76
|
+
});
|