@@ -15,6 +15,8 @@ func TestValidateInhooksConfig_OK(t *testing.T) {
1515 assert .NoError (t , err )
1616
1717 delay := 12 * time .Minute
18+ var hmacAlgorithm HMACAlgorithm = HMACAlgorithmSHA256
19+
1820 c := & InhooksConfig {
1921 Flows : []* Flow {
2022 {
@@ -39,6 +41,12 @@ func TestValidateInhooksConfig_OK(t *testing.T) {
3941 ID : "source-2" ,
4042 Slug : "source-2-slug" ,
4143 Type : "http" ,
44+ Verification : & Verification {
45+ VerificationType : VerificationTypeHMAC ,
46+ HMACAlgorithm : & hmacAlgorithm ,
47+ SignatureHeader : "x-my-header" ,
48+ CurrentSecretEnvVar : "FLOW_2_VERIFICATION_SECRET" ,
49+ },
4250 },
4351 Sinks : []* Sink {
4452 {
@@ -286,3 +294,68 @@ func TestValidateInhooksConfig_InvalidSinkUrl(t *testing.T) {
286294
287295 assert .ErrorContains (t , ValidateInhooksConfig (appConf , c ), "invalid url: ABCD123" )
288296}
297+
298+ func TestValidateInhooksConfig_InvalidVerificationType (t * testing.T ) {
299+ ctx := context .Background ()
300+ appConf , err := testsupport .InitAppConfig (ctx )
301+ assert .NoError (t , err )
302+
303+ c := & InhooksConfig {
304+ Flows : []* Flow {
305+ {
306+ ID : "flow-1" ,
307+ Source : & Source {
308+ ID : "source-1" ,
309+ Slug : "source-1-slug" ,
310+ Type : "http" ,
311+ Verification : & Verification {
312+ VerificationType : "random" ,
313+ },
314+ },
315+ Sinks : []* Sink {
316+ {
317+ ID : "sink-1" ,
318+ Type : "http" ,
319+ URL : "https://example.com/sink" ,
320+ },
321+ },
322+ },
323+ },
324+ }
325+
326+ assert .ErrorContains (t , ValidateInhooksConfig (appConf , c ), "invalid verification type: random. allowed: [hmac]" )
327+ }
328+
329+ func TestValidateInhooksConfig_InvalidHMACAlgorithm (t * testing.T ) {
330+ ctx := context .Background ()
331+ appConf , err := testsupport .InitAppConfig (ctx )
332+ assert .NoError (t , err )
333+
334+ hmacAlgorithm := HMACAlgorithm ("somealgorithm" )
335+
336+ c := & InhooksConfig {
337+ Flows : []* Flow {
338+ {
339+ ID : "flow-1" ,
340+ Source : & Source {
341+ ID : "source-1" ,
342+ Slug : "source-1-slug" ,
343+ Type : "http" ,
344+ Verification : & Verification {
345+ VerificationType : VerificationTypeHMAC ,
346+ HMACAlgorithm : & hmacAlgorithm ,
347+ },
348+ },
349+ Sinks : []* Sink {
350+ {
351+ ID : "sink-1" ,
352+ Type : "http" ,
353+ URL : "https://example.com/sink" ,
354+ },
355+ },
356+ },
357+ },
358+ }
359+
360+ assert .ErrorContains (t , ValidateInhooksConfig (appConf , c ), "invalid hmac algorithm: somealgorithm. allowed: [sha256]" )
361+ }
0 commit comments