From 6d1ff7f416b8b65b0d73f879120df2a5bef3e73c Mon Sep 17 00:00:00 2001 From: Gilles De Mey Date: Wed, 19 Jul 2023 19:24:14 +0200 Subject: [PATCH] Alerting: Fix edit / view of webhook contact point when no authorization is set (#71965) --- .../alerting/unified/components/receivers/form/util.test.ts | 5 +++++ .../alerting/unified/components/receivers/form/util.ts | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/public/app/features/alerting/unified/components/receivers/form/util.test.ts b/public/app/features/alerting/unified/components/receivers/form/util.test.ts index f941939ea13..f4bbbe346c7 100644 --- a/public/app/features/alerting/unified/components/receivers/form/util.test.ts +++ b/public/app/features/alerting/unified/components/receivers/form/util.test.ts @@ -34,6 +34,11 @@ describe('normalizeFormValues', () => { expect(normalizeFormValues(config)).toEqual(createContactPoint({ bearer_token_file: 'file' })); }); + + it('should normalize even if authorization is not defined', () => { + const config = createContactPoint({}); + expect(normalizeFormValues(config)).toEqual(createContactPoint({})); + }); }); function createContactPoint(httpConfig: DeprecatedAuthHTTPConfig | HTTPAuthConfig) { diff --git a/public/app/features/alerting/unified/components/receivers/form/util.ts b/public/app/features/alerting/unified/components/receivers/form/util.ts index ec4279257c0..7ac64cc9401 100644 --- a/public/app/features/alerting/unified/components/receivers/form/util.ts +++ b/public/app/features/alerting/unified/components/receivers/form/util.ts @@ -8,7 +8,7 @@ export interface DeprecatedAuthHTTPConfig { } export interface HTTPAuthConfig { - authorization: { + authorization?: { type: string; credentials?: string; credentials_file?: string; @@ -42,8 +42,8 @@ function normalizeHTTPConfig(config: HTTPAuthConfig | DeprecatedAuthHTTPConfig): return { ...omit(config, 'authorization'), - bearer_token: config.authorization.credentials, - bearer_token_file: config.authorization.credentials_file, + bearer_token: config.authorization?.credentials, + bearer_token_file: config.authorization?.credentials_file, }; }