@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.
@@ -11,18 +11,18 @@ on:
11
11
  - ready_for_review
12
12
 
13
13
  permissions:
14
- contents: read
14
+ contents: write
15
15
 
16
16
  jobs:
17
17
  cdp-workflows:
18
18
  name: Run Pull Request Checks
19
19
  runs-on: ubuntu-latest
20
20
  steps:
21
- - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 #v7.0.0
21
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 #v7.0.1
22
22
  with:
23
23
  fetch-depth: 0
24
24
 
25
- - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e #v6.4.0
25
+ - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 #v7.0.0
26
26
  with:
27
27
  node-version-file: .nvmrc
28
28
  registry-url: "https://registry.npmjs.org/"
@@ -46,7 +46,7 @@ jobs:
46
46
  - name: SonarCloud Scan
47
47
  if: github.actor != 'dependabot[bot]' &&
48
48
  !startsWith(github.head_ref, 'changeset-release/')
49
- uses: SonarSource/sonarqube-scan-action@713881670b6b3676cda39549040e2d88c70d582e #8.2.0
49
+ uses: SonarSource/sonarqube-scan-action@22918119ff8e1ca75a623e15c8296b6ea4fbe28f #8.2.1
50
50
  env:
51
51
  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
52
52
  SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
@@ -25,13 +25,13 @@ jobs:
25
25
 
26
26
  steps:
27
27
  - name: Checkout repository
28
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 #v7.0.0
28
+ uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 #v7.0.1
29
29
  with:
30
30
  fetch-depth: 0
31
31
  fetch-tags: true
32
32
 
33
33
  - name: Set up Node.js
34
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e #v6.4.0
34
+ uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 #v7.0.0
35
35
  with:
36
36
  node-version-file: .nvmrc
37
37
  registry-url: "https://registry.npmjs.org/"
@@ -44,7 +44,7 @@ jobs:
44
44
 
45
45
  - name: SonarCloud Scan
46
46
  if: github.actor != 'dependabot[bot]' && github.actor != 'github-actions[bot]' && !contains(github.event.head_commit.message, 'Create new config version')
47
- uses: SonarSource/sonarqube-scan-action@713881670b6b3676cda39549040e2d88c70d582e #8.2.0
47
+ uses: SonarSource/sonarqube-scan-action@22918119ff8e1ca75a623e15c8296b6ea4fbe28f #8.2.1
48
48
  env:
49
49
  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
50
50
  SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
package/AGENTS.md CHANGED
@@ -27,3 +27,7 @@ Developers can add their own `AGENTS.local.md` and should be read as an addendum
27
27
  ## Testing Guidelines
28
28
 
29
29
  Add or update focused unit tests with shared utility changes. Run the relevant Vitest file, then `npm test`, `npm run lint`, and `npm run format:check`.
30
+
31
+ ## Command preference
32
+
33
+ Use the `npm run` command whenever possible, and avoid `npx` where possible.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @defra/grants-config-utils
2
2
 
3
+ ## 1.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 385953a: Add SQS subscriber. Provide deployer name for config publishes
8
+
9
+ ## 1.0.0
10
+
11
+ ### Major Changes
12
+
13
+ - 822c57c: BREAKING CHANGE:
14
+ Remove support for API key headers in config broker helpers.
15
+
16
+ Add support for using service auth with STS
17
+
3
18
  ## 0.6.0
4
19
 
5
20
  ### Minor Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defra/grants-config-utils",
3
- "version": "0.6.0",
3
+ "version": "1.1.0",
4
4
  "description": "NPM module for providing utils for publishing grants config",
5
5
  "engines": {
6
6
  "node": ">=24",
@@ -32,8 +32,11 @@
32
32
  ".": "./src/service/config-store-and-inform.js",
33
33
  "./s3-interactions": "./src/s3/s3-interactions.js",
34
34
  "./sns-client": "./src/sns/sns-client.js",
35
+ "./sqs-subscriber": "./src/sqs/sqs-subscriber.js",
35
36
  "./config": "./src/config/config.js",
36
- "./broker": "./src/broker/broker-auth-helper.js"
37
+ "./broker": "./src/broker/broker-auth-helper.js",
38
+ "./sts-client-plugin": "./src/sts/sts-client-plugin.js",
39
+ "./grants-config-broker-token": "./src/sts/grants-config-broker-token.js"
37
40
  },
38
41
  "license": "OGL-UK-3.0",
39
42
  "bugs": {
@@ -41,26 +44,33 @@
41
44
  },
42
45
  "homepage": "https://github.com/DEFRA/grants-config-utils#readme",
43
46
  "dependencies": {
44
- "@aws-sdk/client-s3": "3.1078.0",
45
- "@aws-sdk/client-sns": "3.1078.0",
47
+ "@aws-sdk/client-s3": "3.1095.0",
48
+ "@aws-sdk/client-sns": "3.1095.0",
49
+ "@aws-sdk/client-sqs": "3.1095.0",
50
+ "@aws-sdk/client-sts": "3.1095.0",
51
+ "brace-expansion": "5.0.9",
46
52
  "convict": "6.2.5",
47
53
  "convict-format-with-validator": "6.2.0"
48
54
  },
49
55
  "devDependencies": {
50
- "@babel/core": "7.29.7",
51
- "@babel/preset-env": "7.29.7",
56
+ "@babel/core": "8.0.1",
57
+ "@babel/preset-env": "8.0.2",
52
58
  "@changesets/changelog-github": "0.7.0",
53
- "@changesets/cli": "2.31.0",
54
- "@vitest/coverage-v8": "4.1.9",
55
- "eslint": "9.39.4",
59
+ "@changesets/cli": "2.31.1",
60
+ "@vitest/coverage-v8": "4.1.10",
61
+ "eslint": "10.7.0",
56
62
  "eslint-config-prettier": "10.1.1",
57
63
  "husky": "9.1.7",
58
- "lint-staged": "17.0.8",
64
+ "lint-staged": "17.2.0",
59
65
  "neostandard": "0.13.0",
60
- "prettier": "3.8.4",
61
- "vitest": "4.1.9",
66
+ "prettier": "3.9.6",
67
+ "vitest": "4.1.10",
62
68
  "vitest-fetch-mock": "0.4.5"
63
69
  },
70
+ "overrides": {
71
+ "brace-expansion": "5.0.9",
72
+ "eslint": "10.7.0"
73
+ },
64
74
  "release-it": {
65
75
  "npm": {
66
76
  "publish": false
@@ -1,74 +1,21 @@
1
- import { config } from "../config/config.js";
2
- import crypto from "node:crypto";
1
+ import { generateToken } from "../sts/grants-config-broker-token.js";
3
2
 
4
- const IV_LENGTH_BYTES = 12;
5
- const KEY_LENGTH_BYTES = 32;
6
- const SCRYPT_SALT = "salt";
7
- const CIPHER_ALGORITHM = "aes-256-gcm";
8
- /** @type {Record<string, BufferEncoding>} */
9
- const ENCODING = {
10
- UTF8: "utf8",
11
- BASE64: "base64",
12
- };
13
-
14
- const CONTENT_TYPE_JSON = "application/json";
15
3
  const AUTH_SCHEME = "Bearer";
16
- const GRANTS_CONFIG_BROKER_AUTH_TOKEN = config.get("configBroker.auth.token");
17
- const ENCRYPTION_KEY = config.get("configBroker.auth.encryptionKey");
18
- /**
19
- * Encrypts the bearer token using AES-256-GCM
20
- * @param {string} token - The token to encrypt
21
- * @param {string} encryptionKey - Encryption key
22
- * @returns {string} Encrypted token in format: iv:authTag:encryptedData (base64)
23
- */
24
- export function encryptToken(token, encryptionKey) {
25
- const iv = crypto.randomBytes(IV_LENGTH_BYTES);
26
- const key = crypto.scryptSync(encryptionKey, SCRYPT_SALT, KEY_LENGTH_BYTES);
27
- const cipher = crypto.createCipheriv(CIPHER_ALGORITHM, key, iv);
28
-
29
- let encrypted = cipher.update(token, ENCODING.UTF8, ENCODING.BASE64);
30
- encrypted += cipher.final(ENCODING.BASE64);
31
-
32
- const authTag = cipher.getAuthTag();
33
-
34
- return `${iv.toString(ENCODING.BASE64)}:${authTag.toString(ENCODING.BASE64)}:${encrypted}`;
35
- }
36
4
 
37
5
  /**
38
- * Creates headers for authenticating with the config-broker API
39
- * @param {string} token - Auth token
40
- * @param {string} encryptionKey - Encryption key
6
+ * Creates headers for authenticating with the config-broker API using service to service authentication
7
+ * @param {object} requestOrServer - Request or Server object
41
8
  * @param {object} baseHeaders - Base headers to extend
42
9
  * @returns {object} Headers with authentication if token is available
43
10
  */
44
- export function createAuthenticatedHeaders(
45
- token,
46
- encryptionKey,
11
+ export async function createAuthenticatedHeaders(
12
+ requestOrServer,
47
13
  baseHeaders = {},
48
14
  ) {
49
15
  const headers = { ...baseHeaders };
50
16
 
51
- if (token) {
52
- const encryptedToken = encryptToken(token, encryptionKey);
53
- const authCredentials = Buffer.from(encryptedToken).toString(
54
- ENCODING.BASE64,
55
- );
56
- headers.Authorization = `${AUTH_SCHEME} ${authCredentials}`;
57
- }
17
+ const authCredentials = await generateToken(requestOrServer.sts);
18
+ headers.Authorization = `${AUTH_SCHEME} ${authCredentials}`;
58
19
 
59
20
  return headers;
60
21
  }
61
-
62
- /**
63
- * Creates standard headers for API requests to grants-config-broker
64
- * @returns {object} Headers with Content-Type and authentication
65
- */
66
- export function createApiHeadersForConfigBroker() {
67
- return createAuthenticatedHeaders(
68
- GRANTS_CONFIG_BROKER_AUTH_TOKEN,
69
- ENCRYPTION_KEY,
70
- {
71
- "Content-Type": CONTENT_TYPE_JSON,
72
- },
73
- );
74
- }
@@ -1,262 +1,81 @@
1
- import { vi } from "vitest";
1
+ import { describe, it, expect, vi, beforeEach } from "vitest";
2
+ import { createAuthenticatedHeaders } from "./broker-auth-helper.js";
3
+ import { generateToken } from "../sts/grants-config-broker-token.js";
2
4
 
3
- const TEST_ENCRYPTION_KEY = "test-encryption-key-for-unit-tests-32-chars";
4
- const CONTENT_TYPE_JSON = "application/json";
5
-
6
- const HEADER_OBJECTS = {
7
- CONTENT_TYPE_JSON: { "Content-Type": CONTENT_TYPE_JSON },
8
- EMPTY: {},
9
- };
10
-
11
- const CONFIG_AUTH_TOKEN = "configBroker.auth.token";
12
- const CONFIG_ENCRYPTION_KEY = "configBroker.auth.encryptionKey";
13
-
14
- const MOCK_TOKENS = {
15
- DEFAULT: "test-token-123",
16
- API: "api-test-token",
17
- ALTERNATIVE: "test-token-456",
18
- THIRD: "test-token-789",
19
- MUTATION_TEST: "test-token-mutation",
20
- SECRET: "my-secret-token",
21
- };
22
-
23
- const TEST_HEADERS = {
24
- USER_AGENT: "test-agent",
25
- CUSTOM_VALUE: "custom-value",
26
- };
27
-
28
- const mockConfigGet = vi.fn((key) => {
29
- if (key === "configBroker.auth.token") {
30
- return "default-token";
31
- }
32
- if (key === "configBroker.auth.encryptionKey") {
33
- return TEST_ENCRYPTION_KEY;
34
- }
35
- return null;
36
- });
37
-
38
- vi.mock("../config/config.js", () => ({
39
- config: {
40
- get: mockConfigGet,
41
- },
5
+ vi.mock("../sts/grants-config-broker-token.js", () => ({
6
+ generateToken: vi.fn(),
42
7
  }));
43
8
 
44
- async function importConfigBrokerHelper() {
45
- return await import("./broker-auth-helper.js");
46
- }
47
-
48
- function setupMockConfig(value, encryptionKey = TEST_ENCRYPTION_KEY) {
49
- const configValues = {
50
- [CONFIG_AUTH_TOKEN]: value,
51
- [CONFIG_ENCRYPTION_KEY]: encryptionKey,
52
- };
53
-
54
- mockConfigGet.mockImplementation((key) => configValues[key] || null);
55
- }
56
-
57
9
  describe("Broker Auth Helper", () => {
10
+ let mockStsClient;
11
+
58
12
  beforeEach(() => {
59
13
  vi.clearAllMocks();
60
- vi.resetModules();
14
+ mockStsClient = {
15
+ send: vi.fn(),
16
+ };
61
17
  });
62
18
 
63
- describe("createApiHeadersForConfigBroker", () => {
64
- describe("when no token is configured", () => {
65
- it("should return base headers when no token is configured", async () => {
66
- setupMockConfig("", TEST_ENCRYPTION_KEY);
19
+ describe("createAuthenticatedHeaders", () => {
20
+ it("should add Authorization header with Bearer token from generateToken", async () => {
21
+ const mockToken = "mock-sts-token";
22
+ vi.mocked(generateToken).mockResolvedValue(mockToken);
23
+ const baseHeaders = { "Content-Type": "application/json" };
67
24
 
68
- const { createApiHeadersForConfigBroker } =
69
- await importConfigBrokerHelper();
70
- const headers = createApiHeadersForConfigBroker(
71
- HEADER_OBJECTS.CONTENT_TYPE_JSON,
72
- );
25
+ const headers = await createAuthenticatedHeaders(
26
+ { sts: mockStsClient },
27
+ baseHeaders,
28
+ );
73
29
 
74
- expect(mockConfigGet).toHaveBeenCalledWith(CONFIG_AUTH_TOKEN);
75
- expect(headers).toEqual(HEADER_OBJECTS.CONTENT_TYPE_JSON);
76
- expect(headers.Authorization).toBeUndefined();
30
+ expect(generateToken).toHaveBeenCalledWith(mockStsClient);
31
+ expect(headers).toEqual({
32
+ "Content-Type": "application/json",
33
+ Authorization: "Bearer mock-sts-token",
77
34
  });
78
35
  });
79
36
 
80
- describe("when token is configured", () => {
81
- it("should add Authorization header when token is configured", async () => {
82
- setupMockConfig(MOCK_TOKENS.DEFAULT);
37
+ it("should work with empty base headers", async () => {
38
+ const mockToken = "mock-sts-token";
39
+ vi.mocked(generateToken).mockResolvedValue(mockToken);
83
40
 
84
- const { createApiHeadersForConfigBroker } =
85
- await importConfigBrokerHelper();
86
- const headers = createApiHeadersForConfigBroker(
87
- HEADER_OBJECTS.CONTENT_TYPE_JSON,
88
- );
41
+ const headers = await createAuthenticatedHeaders({ sts: mockStsClient });
89
42
 
90
- expect(mockConfigGet).toHaveBeenCalledWith(CONFIG_AUTH_TOKEN);
91
- expect(headers).toHaveProperty("Content-Type", "application/json");
92
- expect(headers).toHaveProperty("Authorization");
93
- expect(headers.Authorization).toMatch(/^Bearer [A-Za-z0-9+/]+=*$/);
94
-
95
- const base64Part = headers.Authorization.replace("Bearer ", "");
96
- const decoded = Buffer.from(base64Part, "base64").toString("utf-8");
97
- expect(decoded).toMatch(
98
- /^([A-Za-z0-9+/]+=*):([A-Za-z0-9+/]+=*):([A-Za-z0-9+/]+=*)$/,
99
- );
100
- });
101
-
102
- it("should work with empty base headers", async () => {
103
- setupMockConfig(MOCK_TOKENS.ALTERNATIVE);
104
-
105
- const { createApiHeadersForConfigBroker } =
106
- await importConfigBrokerHelper();
107
- const headers = createApiHeadersForConfigBroker(undefined);
108
-
109
- expect(mockConfigGet).toHaveBeenCalledWith(CONFIG_AUTH_TOKEN);
110
- expect(headers).toHaveProperty("Authorization");
111
- expect(headers.Authorization).toMatch(/^Bearer [A-Za-z0-9+/]+=*$/);
112
-
113
- const base64Part = headers.Authorization.replace("Bearer ", "");
114
- const decoded = Buffer.from(base64Part, "base64").toString("utf-8");
115
- expect(decoded).toMatch(
116
- /^([A-Za-z0-9+/]+=*):([A-Za-z0-9+/]+=*):([A-Za-z0-9+/]+=*)$/,
117
- );
118
- });
119
-
120
- it("should preserve all base headers when adding auth", async () => {
121
- const baseHeaders = {
122
- "Content-Type": CONTENT_TYPE_JSON,
123
- "User-Agent": TEST_HEADERS.USER_AGENT,
124
- "X-Custom-Header": TEST_HEADERS.CUSTOM_VALUE,
125
- };
126
-
127
- const { createAuthenticatedHeaders } = await importConfigBrokerHelper();
128
- const headers = createAuthenticatedHeaders(
129
- MOCK_TOKENS.THIRD,
130
- TEST_ENCRYPTION_KEY,
131
- baseHeaders,
132
- );
133
-
134
- expect(mockConfigGet).toHaveBeenCalledWith(CONFIG_AUTH_TOKEN);
135
- expect(headers).toHaveProperty("Content-Type", CONTENT_TYPE_JSON);
136
- expect(headers).toHaveProperty("User-Agent", TEST_HEADERS.USER_AGENT);
137
- expect(headers).toHaveProperty(
138
- "X-Custom-Header",
139
- TEST_HEADERS.CUSTOM_VALUE,
140
- );
141
- expect(headers).toHaveProperty("Authorization");
142
- expect(headers.Authorization).toMatch(/^Bearer [A-Za-z0-9+/]+=*$/);
143
-
144
- const base64Part = headers.Authorization.replace("Bearer ", "");
145
- const decoded = Buffer.from(base64Part, "base64").toString("utf-8");
146
- expect(decoded).toMatch(
147
- /^([A-Za-z0-9+/]+=*):([A-Za-z0-9+/]+=*):([A-Za-z0-9+/]+=*)$/,
148
- );
43
+ expect(headers).toEqual({
44
+ Authorization: "Bearer mock-sts-token",
149
45
  });
150
46
  });
151
47
 
152
48
  it("should not mutate original base headers object", async () => {
153
- const baseHeaders = HEADER_OBJECTS.CONTENT_TYPE_JSON;
154
-
155
- setupMockConfig(MOCK_TOKENS.MUTATION_TEST);
156
-
157
- const { createApiHeadersForConfigBroker } =
158
- await importConfigBrokerHelper();
159
- const headers = createApiHeadersForConfigBroker(baseHeaders);
160
-
161
- expect(baseHeaders).toEqual(HEADER_OBJECTS.CONTENT_TYPE_JSON);
162
- expect(baseHeaders.Authorization).toBeUndefined();
163
- expect(headers.Authorization).toBeDefined();
164
- });
165
-
166
- it("should handle null token correctly", async () => {
167
- setupMockConfig(null, TEST_ENCRYPTION_KEY);
49
+ vi.mocked(generateToken).mockResolvedValue("token");
50
+ const baseHeaders = { "Content-Type": "application/json" };
168
51
 
169
- const { createApiHeadersForConfigBroker } =
170
- await importConfigBrokerHelper();
171
- const headers = createApiHeadersForConfigBroker({
172
- "Content-Type": CONTENT_TYPE_JSON,
173
- });
174
-
175
- expect(headers).toEqual(HEADER_OBJECTS.CONTENT_TYPE_JSON);
176
- expect(headers.Authorization).toBeUndefined();
177
- });
178
- });
179
-
180
- describe("createApiHeaders", () => {
181
- it("should return headers with Content-Type and no auth when no token configured", async () => {
182
- setupMockConfig("", TEST_ENCRYPTION_KEY);
183
-
184
- const { createApiHeadersForConfigBroker } =
185
- await importConfigBrokerHelper();
186
- const headers = createApiHeadersForConfigBroker();
187
-
188
- expect(headers).toEqual(HEADER_OBJECTS.CONTENT_TYPE_JSON);
189
- });
190
-
191
- it("should return headers with Content-Type and Authorization when token configured", async () => {
192
- setupMockConfig(MOCK_TOKENS.API);
193
-
194
- const { createApiHeadersForConfigBroker } =
195
- await importConfigBrokerHelper();
196
- const headers = createApiHeadersForConfigBroker();
197
-
198
- expect(headers).toHaveProperty("Content-Type", "application/json");
199
- expect(headers).toHaveProperty("Authorization");
200
- expect(headers.Authorization).toMatch(/^Bearer [A-Za-z0-9+/]+=*$/);
201
-
202
- const base64Part = headers.Authorization.replace("Bearer ", "");
203
- const decoded = Buffer.from(base64Part, "base64").toString("utf-8");
204
- expect(decoded).toMatch(
205
- /^([A-Za-z0-9+/]+=*):([A-Za-z0-9+/]+=*):([A-Za-z0-9+/]+=*)$/,
206
- );
207
- });
208
- });
209
-
210
- describe("Base64 encoding", () => {
211
- it("should encode encrypted token with blank username correctly", async () => {
212
- setupMockConfig(MOCK_TOKENS.SECRET);
213
-
214
- const { createApiHeadersForConfigBroker } =
215
- await importConfigBrokerHelper();
216
- const headers = createApiHeadersForConfigBroker();
217
- const authHeader = headers.Authorization;
218
-
219
- const base64Part = authHeader.replace("Bearer ", "");
220
- const decoded = Buffer.from(base64Part, "base64").toString("utf-8");
221
-
222
- expect(decoded).toMatch(
223
- /^([A-Za-z0-9+/]+=*):([A-Za-z0-9+/]+=*):([A-Za-z0-9+/]+=*)$/,
52
+ const headers = await createAuthenticatedHeaders(
53
+ { sts: mockStsClient },
54
+ baseHeaders,
224
55
  );
225
- });
226
- });
227
56
 
228
- describe("Token Encryption", () => {
229
- beforeEach(() => {
230
- vi.resetAllMocks();
231
- // No longer needed with new mock structure
57
+ expect(headers).not.toBe(baseHeaders);
58
+ expect(baseHeaders).toEqual({ "Content-Type": "application/json" });
59
+ expect(baseHeaders.Authorization).toBeUndefined();
232
60
  });
233
61
 
234
- it("should encrypt token when encryption key is configured", async () => {
235
- const configValues = {
236
- [CONFIG_AUTH_TOKEN]: MOCK_TOKENS.DEFAULT,
237
- [CONFIG_ENCRYPTION_KEY]: TEST_ENCRYPTION_KEY,
62
+ it("should preserve all base headers", async () => {
63
+ vi.mocked(generateToken).mockResolvedValue("token");
64
+ const baseHeaders = {
65
+ "Content-Type": "application/json",
66
+ "User-Agent": "test-agent",
67
+ "X-Custom-Header": "custom-value",
238
68
  };
239
69
 
240
- mockConfigGet.mockImplementation((key) => configValues[key] || null);
241
-
242
- const { createApiHeadersForConfigBroker } =
243
- await importConfigBrokerHelper();
244
- const headers = createApiHeadersForConfigBroker(
245
- HEADER_OBJECTS.CONTENT_TYPE_JSON,
70
+ const headers = await createAuthenticatedHeaders(
71
+ { sts: mockStsClient },
72
+ baseHeaders,
246
73
  );
247
74
 
248
- expect(mockConfigGet).toHaveBeenCalledWith(CONFIG_AUTH_TOKEN);
249
- expect(mockConfigGet).toHaveBeenCalledWith(CONFIG_ENCRYPTION_KEY);
250
- expect(headers.Authorization).toBeDefined();
251
- expect(headers.Authorization).toMatch(/^Bearer /);
252
-
253
- const base64Part = headers.Authorization.replace("Bearer ", "");
254
- const decoded = Buffer.from(base64Part, "base64").toString("utf-8");
255
- const tokenPart = decoded.substring(1);
256
-
257
- expect(tokenPart).toMatch(
258
- /^[A-Za-z0-9+/]+=*:[A-Za-z0-9+/]+=*:[A-Za-z0-9+/]+=*$/,
259
- );
75
+ expect(headers).toHaveProperty("Content-Type", "application/json");
76
+ expect(headers).toHaveProperty("User-Agent", "test-agent");
77
+ expect(headers).toHaveProperty("X-Custom-Header", "custom-value");
78
+ expect(headers).toHaveProperty("Authorization", "Bearer token");
260
79
  });
261
80
  });
262
81
  });
@@ -49,20 +49,18 @@ export const config = convict({
49
49
  },
50
50
  },
51
51
  configBroker: {
52
- auth: {
53
- token: {
54
- doc: "Bearer token for service-to-service authentication",
52
+ serviceAuth: {
53
+ audience: {
54
+ doc: "JWT audience sent in the token request",
55
55
  format: String,
56
- default: "",
57
- env: "GRANTS_CONFIG_BROKER_AUTH_TOKEN",
58
- sensitive: true,
56
+ default: "grants-config-broker",
57
+ env: "BACKEND_SERVICE_AUTH_AUDIENCE",
59
58
  },
60
- encryptionKey: {
61
- doc: "Encryption key for decrypting bearer token",
62
- format: String,
63
- default: "",
64
- env: "GRANTS_CONFIG_BROKER_ENCRYPTION_KEY",
65
- sensitive: true,
59
+ tokenDuration: {
60
+ doc: "Token lifetime in seconds (max 900)",
61
+ format: Number,
62
+ default: 60,
63
+ env: "BACKEND_SERVICE_AUTH_TOKEN_DURATION",
66
64
  },
67
65
  },
68
66
  apiEndpoint: {
@@ -79,6 +77,12 @@ export const config = convict({
79
77
  default: "active",
80
78
  env: "GRANTS_CONFIG_PUBLISH_STATUS",
81
79
  },
80
+ user: {
81
+ doc: "Config published by user",
82
+ format: String,
83
+ default: "system",
84
+ env: "SERVICE_DEPLOYED_BY",
85
+ },
82
86
  },
83
87
  });
84
88