github.com/Axway/agent-sdk@v1.1.101/pkg/config/webhookconfig_test.go (about) 1 package config 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 ) 8 9 func TestWebookConfig(t *testing.T) { 10 cfg := NewWebhookConfig() 11 assert.False(t, cfg.IsConfigured()) 12 13 err := cfg.ValidateConfig() 14 assert.Nil(t, err) 15 16 // this one should be all good 17 cfg = &WebhookConfiguration{ 18 URL: "https://foo.bar:4567", 19 Headers: "Header=contentType,Value=application/json", 20 Secret: "1234", 21 } 22 23 assert.True(t, cfg.IsConfigured()) 24 25 err = cfg.ValidateConfig() 26 assert.Nil(t, err) 27 assert.Equal(t, "https://foo.bar:4567", cfg.GetURL()) 28 m := map[string]string{"contentType": "application/json"} 29 assert.Equal(t, m, cfg.GetWebhookHeaders()) 30 assert.Equal(t, "1234", cfg.GetSecret()) 31 32 // this one should be all good with no headers 33 cfg = &WebhookConfiguration{ 34 URL: "https://foo.bar:4567", 35 Headers: "", 36 Secret: "1234", 37 } 38 39 err = cfg.ValidateConfig() 40 assert.Nil(t, err) 41 42 // this one should be all good with no secret 43 cfg = &WebhookConfiguration{ 44 URL: "https://foo.bar:4567", 45 Headers: "Header=contentType,Value=application/json", 46 Secret: "", 47 } 48 49 err = cfg.ValidateConfig() 50 assert.Nil(t, err) 51 52 // this one should be bad url 53 cfg = &WebhookConfiguration{ 54 URL: "xxxf", 55 Headers: "Header=contentType,Value=application/json", 56 Secret: "1234", 57 } 58 err = cfg.ValidateConfig() 59 assert.NotNil(t, err) 60 assert.Equal(t, "central.subscriptions.approvalWebhook.URL is not a valid URL", err.Error()) 61 62 // this one should be bad header 63 cfg = &WebhookConfiguration{ 64 URL: "https://foo.bar:4567", 65 Headers: "Header=contentType,Vue=application/json", 66 Secret: "1234", 67 } 68 err = cfg.ValidateConfig() 69 assert.NotNil(t, err) 70 assert.Equal(t, "could not parse value of central.subscriptions.approvalWebhook.headers", err.Error()) 71 }