Add tests for HTTP client configuration

This commit is contained in:
Simon Pasquier 2018-02-05 14:44:31 +01:00
parent d678022fea
commit 8b93f1085d
1 changed files with 57 additions and 0 deletions

View File

@ -1,6 +1,7 @@
package config
import (
"strings"
"testing"
"gopkg.in/yaml.v2"
@ -111,6 +112,62 @@ url: ''
}
}
func TestWebhookHttpConfigIsValid(t *testing.T) {
in := `
url: 'http://example.com'
http_config:
bearer_token: foo
bearer_token_file: /tmp/bar
`
var cfg WebhookConfig
err := yaml.Unmarshal([]byte(in), &cfg)
expected := "at most one of bearer_token & bearer_token_file must be configured"
if err == nil {
t.Fatalf("no error returned, expected:\n%v", expected)
}
if err.Error() != expected {
t.Errorf("\nexpected:\n%v\ngot:\n%v", expected, err.Error())
}
}
func TestWebhookHttpConfigIsOptional(t *testing.T) {
in := `
url: 'http://example.com'
`
var cfg WebhookConfig
err := yaml.Unmarshal([]byte(in), &cfg)
if err != nil {
t.Fatalf("no error expected, returned:\n%v", err.Error())
}
}
func TestWebhookPasswordIsObsfucated(t *testing.T) {
in := `
url: 'http://example.com'
http_config:
basic_auth:
username: foo
password: supersecret
`
var cfg WebhookConfig
err := yaml.Unmarshal([]byte(in), &cfg)
if err != nil {
t.Fatalf("no error expected, returned:\n%v", err.Error())
}
ycfg, err := yaml.Marshal(cfg)
if err != nil {
t.Fatalf("no error expected, returned:\n%v", err.Error())
}
if strings.Contains(string(ycfg), "supersecret") {
t.Errorf("Found password in the YAML cfg: %s\n", ycfg)
}
}
func TestWechatAPIKeyIsPresent(t *testing.T) {
in := `
api_secret: ''