Skip to content

Commit 4af61cf

Browse files
fix: fix logic in loadMatcherConfig to pass all tests
1 parent 85df592 commit 4af61cf

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

lambdas/functions/webhook/src/ConfigLoader.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,27 @@ describe('ConfigLoader Tests', () => {
195195
expect(config.matcherConfig).toEqual(combinedMatcherConfig);
196196
expect(config.webhookSecret).toBe('secret');
197197
});
198+
199+
it('should throw error if config loading fails from multiple paths', async () => {
200+
process.env.PARAMETER_RUNNER_MATCHER_CONFIG_PATH = '/path/to/matcher/config-1:/path/to/matcher/config-2';
201+
process.env.PARAMETER_GITHUB_APP_WEBHOOK_SECRET = '/path/to/webhook/secret';
202+
203+
const partialMatcher1 =
204+
'[{"id":"1","arn":"arn:aws:sqs:queue1","matcherConfig":{"labelMatchers":[["a"]],"exactMatch":true}}';
205+
const partialMatcher2 =
206+
',{"id":"2","arn":"arn:aws:sqs:queue2","matcherConfig":{"labelMatchers":[["b"]],"exactMatch":true}}';
207+
208+
vi.mocked(getParameter).mockImplementation(async (paramPath: string) => {
209+
if (paramPath === '/path/to/matcher/config-1') return partialMatcher1;
210+
if (paramPath === '/path/to/matcher/config-2') return partialMatcher2;
211+
if (paramPath === '/path/to/webhook/secret') return 'secret';
212+
return '';
213+
});
214+
215+
await expect(ConfigWebhook.load()).rejects.toThrow(
216+
'Failed to load config: Failed to parse combined matcher config: Expected \',\' or \']\' after array element in JSON at position 196 (line 1 column 197)', // eslint-disable-line max-len
217+
);
218+
});
198219
});
199220

200221
describe('ConfigWebhookEventBridge', () => {

lambdas/functions/webhook/src/ConfigLoader.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,11 @@ abstract class BaseConfig {
9090
abstract class MatcherAwareConfig extends BaseConfig {
9191
matcherConfig: RunnerMatcherConfig[] = [];
9292

93-
protected async loadMatcherConfig(paramPathsEnv: string | undefined) {
94-
if (!paramPathsEnv) return;
93+
protected async loadMatcherConfig(paramPathsEnv: string) {
94+
if (!paramPathsEnv || paramPathsEnv === 'undefined' || paramPathsEnv === 'null' || !paramPathsEnv.includes(':')) {
95+
await this.loadParameter(paramPathsEnv, 'matcherConfig');
96+
return;
97+
}
9598

9699
const paths = paramPathsEnv
97100
.split(':')
@@ -101,16 +104,13 @@ abstract class MatcherAwareConfig extends BaseConfig {
101104

102105
for (const path of paths) {
103106
await this.loadParameter(path, 'matcherConfig');
104-
if (typeof this.matcherConfig === 'string') {
105-
combinedString += this.matcherConfig;
106-
}
107+
combinedString += this.matcherConfig;
107108
}
108109

109110
try {
110111
this.matcherConfig = JSON.parse(combinedString);
111112
} catch (error) {
112113
this.configLoadingErrors.push(`Failed to parse combined matcher config: ${(error as Error).message}`);
113-
this.matcherConfig = [];
114114
}
115115
}
116116
}

0 commit comments

Comments
 (0)