diff --git a/cmd/karma/tests/testscript/049_invalid_tls_config.txt b/cmd/karma/tests/testscript/049_invalid_tls_config.txt deleted file mode 100644 index 1942eb82b..000000000 --- a/cmd/karma/tests/testscript/049_invalid_tls_config.txt +++ /dev/null @@ -1,15 +0,0 @@ -# Raises an error if tls config is invalid -karma.bin-should-fail --log.format=text --log.config=false --log.level=error --config.file=karma.yaml -! stdout . -stderr 'msg="Failed to create HTTP transport for Alertmanager ''client-auth'' with URI ''https://localhost:9093'': open /xxx/xxx-ca-bundle.crt: no such file or directory"' - --- karma.yaml -- -alertmanager: - servers: - - name: client-auth - uri: https://localhost:9093 - timeout: 10s - tls: - ca: /xxx/xxx-ca-bundle.crt - cert: /xxx/karma/client.pem - key: /xxx/karma/client.key diff --git a/cmd/karma/tests/testscript/078_tls_missing_ca.txt b/cmd/karma/tests/testscript/078_tls_missing_ca.txt new file mode 100644 index 000000000..13cc8326b --- /dev/null +++ b/cmd/karma/tests/testscript/078_tls_missing_ca.txt @@ -0,0 +1,64 @@ +# Raises an error if tls CA cert is missing + +karma.bin-should-fail --pid-file=karma.pid --log.format=text --log.config=true --log.level=info --config.file=karma.yaml --listen.address=127.0.0.1 --listen.port=8078 +! stdout . +stderr 'msg="Failed to create HTTP transport for Alertmanager ''client-auth'' with URI ''https:\/\/localhost:9093'': open ca.crt: no such file or directory"' + +-- karma.yaml -- +alertmanager: + servers: + - name: client-auth + uri: https://localhost:9093 + timeout: 10s + tls: + ca: ca.crt + cert: client.pem + key: client.key + +-- client.pem -- +-----BEGIN CERTIFICATE----- +MIICwzCCAaugAwIBAgIJAJSCPvgy3Fw5MA0GCSqGSIb3DQEBBQUAMBQxEjAQBgNV +BAMTCWxvY2FsaG9zdDAeFw0yMDEwMDQxMTA4MDNaFw0zMDEwMDIxMTA4MDNaMBQx +EjAQBgNVBAMTCWxvY2FsaG9zdDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC +ggEBAMdKdTkZTh8m1KetGiZPEk0kOoauARiVGIZ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T9OgGXu3w9rUQMJs/sh8XwKKL1llkwVFx+fFwgxFLyiCqbTaiMmiR +Mc5x8QKBgQCVGACXeKvgbc7J6hMUQX/ZPK6rv2yQWkTRn84lMD8TxagJIj0wtWGO +dshQeVDq07p2//410J1BVSQiAdwQ+HVmSO4Fqg0DHqmWn4fi1zBnxVvxW62iAV8+ +db9yajtsMsgPuw26UY9R33PZIUe+CKWKToipm2XbzPtlrbWblZ/g0Q== +-----END RSA PRIVATE KEY----- diff --git a/cmd/karma/tests/testscript/079_tls_missing_client.txt b/cmd/karma/tests/testscript/079_tls_missing_client.txt new file mode 100644 index 000000000..b2e0906ac --- /dev/null +++ b/cmd/karma/tests/testscript/079_tls_missing_client.txt @@ -0,0 +1,44 @@ +# Raises an error if tls CA cert is missing + +karma.bin-should-fail --pid-file=karma.pid --log.format=text --log.config=true --log.level=info --config.file=karma.yaml --listen.address=127.0.0.1 --listen.port=8078 +! stdout . +stderr 'msg="Failed to create HTTP transport for Alertmanager ''client-auth'' with URI ''https:\/\/localhost:9093'': open client.pem: no such file or directory"' + +-- karma.yaml -- +alertmanager: + servers: + - name: client-auth + uri: https://localhost:9093 + timeout: 10s + tls: + cert: client.pem + key: client.key + +-- client.key -- +-----BEGIN RSA PRIVATE KEY----- +MIIEpAIBAAKCAQEAx0p1ORlOHybUp60aJk8STSQ6hq4BGJUYhnRzH5fsK9ikOMWz +l7rewVwfnsMb/G0UGThDpRwbn98e2LWuafeYjOt5gOH6g5qJI34yzAdbpKK3kd+M +KBU62tl2NxVVcmZhl6t2gHSisy+53uR9tGCxB8nH0bQGkpFGYmjxt4SRXYsIinQ2 +zxtvtaWZbRF0VlbI+dYIitMg41fPIUDuMDBnzBV7CZg1YfUuq8fgGcSTPf1WAmgM +Mmn5Y0d7P0m/l86KoonCEq9XlSfrcM7P7G7B3cBIlHAqpJZM1MhxlrM+z2KF1go6 +eapoJ8jAUGOiiH/1DQHKsDYcfhVUqke2V3SZVwIDAQABAoIBAQCBg7sgy3hAuH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PK6rv2yQWkTRn84lMD8TxagJIj0wtWGO +dshQeVDq07p2//410J1BVSQiAdwQ+HVmSO4Fqg0DHqmWn4fi1zBnxVvxW62iAV8+ +db9yajtsMsgPuw26UY9R33PZIUe+CKWKToipm2XbzPtlrbWblZ/g0Q== +-----END RSA PRIVATE KEY----- diff --git a/cmd/karma/tests/testscript/080_tls_missing_key.txt b/cmd/karma/tests/testscript/080_tls_missing_key.txt new file mode 100644 index 000000000..3318d6fee --- /dev/null +++ b/cmd/karma/tests/testscript/080_tls_missing_key.txt @@ -0,0 +1,34 @@ +# Raises an error if tls CA cert is missing + +karma.bin-should-fail --pid-file=karma.pid --log.format=text --log.config=true --log.level=info --config.file=karma.yaml --listen.address=127.0.0.1 --listen.port=8078 +! stdout . +stderr 'msg="Failed to create HTTP transport for Alertmanager ''client-auth'' with URI ''https:\/\/localhost:9093'': open client.key: no such file or directory"' + +-- karma.yaml -- +alertmanager: + servers: + - name: client-auth + uri: https://localhost:9093 + timeout: 10s + tls: + cert: client.pem + key: client.key + +-- client.pem -- +-----BEGIN CERTIFICATE----- +MIICwzCCAaugAwIBAgIJAJSCPvgy3Fw5MA0GCSqGSIb3DQEBBQUAMBQxEjAQBgNV +BAMTCWxvY2FsaG9zdDAeFw0yMDEwMDQxMTA4MDNaFw0zMDEwMDIxMTA4MDNaMBQx +EjAQBgNVBAMTCWxvY2FsaG9zdDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC +ggEBAMdKdTkZTh8m1KetGiZPEk0kOoauARiVGIZ0cx+X7CvYpDjFs5e63sFcH57D +G/xtFBk4Q6UcG5/fHti1rmn3mIzreYDh+oOaiSN+MswHW6Sit5HfjCgVOtrZdjcV +VXJmYZerdoB0orMvud7kfbRgsQfJx9G0BpKRRmJo8beEkV2LCIp0Ns8bb7WlmW0R +dFZWyPnWCIrTIONXzyFA7jAwZ8wVewmYNWH1LqvH4BnEkz39VgJoDDJp+WNHez9J +v5fOiqKJwhKvV5Un63DOz+xuwd3ASJRwKqSWTNTIcZazPs9ihdYKOnmqaCfIwFBj +ooh/9Q0ByrA2HH4VVKpHtld0mVcCAwEAAaMYMBYwFAYDVR0RBA0wC4IJbG9jYWxo +b3N0MA0GCSqGSIb3DQEBBQUAA4IBAQB/cSeIdAHuWM9BENmdAlul1jrAegNRK57k +KLcRiirq9dTtusTlzars+DZdPHewHajWsSil2191DyqV3n/zYq/1g9oWYX80jvX1 +wSlfM/0T6PWc9miRChVx8mGQc/C7vKE4j4oxRZ9EsZIyqKlrxqWA4UXuOZUSaLWx +nECZRf/ofzcr6wNMdoZ8pQUqW05Jmnr+XiP09UoPHQsct9xfzOUGCB3PT47tVK7b +Hu1PStj2VzTPeSDGv/R8X5bPcUcZIdK7as5MKVu9slmk9QLlUj3C6dmw7VudWisg +CKglns9xWEOEA71DVeTS1ieLYychQdYIfNRMulgU+dC8djN2U/Sc +-----END CERTIFICATE----- diff --git a/cmd/karma/tests/testscript/081_tls_unparsable_cert.txt b/cmd/karma/tests/testscript/081_tls_unparsable_cert.txt new file mode 100644 index 000000000..7a3245418 --- /dev/null +++ b/cmd/karma/tests/testscript/081_tls_unparsable_cert.txt @@ -0,0 +1,47 @@ +# Raises an error if tls CA cert is missing + +karma.bin-should-fail --pid-file=karma.pid --log.format=text --log.config=true --log.level=info --config.file=karma.yaml --listen.address=127.0.0.1 --listen.port=8078 +! stdout . +stderr 'msg="Failed to create HTTP transport for Alertmanager ''client-auth'' with URI ''https:\/\/localhost:9093'': tls: failed to find any PEM data in certificate input"' + +-- karma.yaml -- +alertmanager: + servers: + - name: client-auth + uri: https://localhost:9093 + timeout: 10s + tls: + cert: client.pem + key: client.key + +-- client.pem -- +FOO + +-- client.key -- +-----BEGIN RSA PRIVATE KEY----- +MIIEpAIBAAKCAQEAx0p1ORlOHybUp60aJk8STSQ6hq4BGJUYhnRzH5fsK9ikOMWz +l7rewVwfnsMb/G0UGThDpRwbn98e2LWuafeYjOt5gOH6g5qJI34yzAdbpKK3kd+M +KBU62tl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wvGIixcJ0mAIn265HYR2QbU7WC +L7eXs53QIK07ocELJqKHT38CgYBOMULiXWLggsJST8yBbTveCc4CVAOXvtCf/l01 +OEe5+1qNTBizJV0m5YHK/lZs/sQ4wW8mY5Q4gQso/oMnN1TXuPFxQ7MD9Jya62Vw +GpJzAXcJTL7T9OgGXu3w9rUQMJs/sh8XwKKL1llkwVFx+fFwgxFLyiCqbTaiMmiR +Mc5x8QKBgQCVGACXeKvgbc7J6hMUQX/ZPK6rv2yQWkTRn84lMD8TxagJIj0wtWGO +dshQeVDq07p2//410J1BVSQiAdwQ+HVmSO4Fqg0DHqmWn4fi1zBnxVvxW62iAV8+ +db9yajtsMsgPuw26UY9R33PZIUe+CKWKToipm2XbzPtlrbWblZ/g0Q== +-----END RSA PRIVATE KEY----- diff --git a/cmd/karma/tests/testscript/082_tls_unparsable_key.txt b/cmd/karma/tests/testscript/082_tls_unparsable_key.txt new file mode 100644 index 000000000..066d8f4db --- /dev/null +++ b/cmd/karma/tests/testscript/082_tls_unparsable_key.txt @@ -0,0 +1,37 @@ +# Raises an error if tls CA cert is missing + +karma.bin-should-fail --pid-file=karma.pid --log.format=text --log.config=true --log.level=info --config.file=karma.yaml --listen.address=127.0.0.1 --listen.port=8078 +! stdout . +stderr 'msg="Failed to create HTTP transport for Alertmanager ''client-auth'' with URI ''https:\/\/localhost:9093'': tls: failed to find any PEM data in key input"' + +-- karma.yaml -- +alertmanager: + servers: + - name: client-auth + uri: https://localhost:9093 + timeout: 10s + tls: + cert: client.pem + key: client.key + +-- client.pem -- +-----BEGIN CERTIFICATE----- +MIICwzCCAaugAwIBAgIJAJSCPvgy3Fw5MA0GCSqGSIb3DQEBBQUAMBQxEjAQBgNV +BAMTCWxvY2FsaG9zdDAeFw0yMDEwMDQxMTA4MDNaFw0zMDEwMDIxMTA4MDNaMBQx +EjAQBgNVBAMTCWxvY2FsaG9zdDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC +ggEBAMdKdTkZTh8m1KetGiZPEk0kOoauARiVGIZ0cx+X7CvYpDjFs5e63sFcH57D +G/xtFBk4Q6UcG5/fHti1rmn3mIzreYDh+oOaiSN+MswHW6Sit5HfjCgVOtrZdjcV +VXJmYZerdoB0orMvud7kfbRgsQfJx9G0BpKRRmJo8beEkV2LCIp0Ns8bb7WlmW0R +dFZWyPnWCIrTIONXzyFA7jAwZ8wVewmYNWH1LqvH4BnEkz39VgJoDDJp+WNHez9J +v5fOiqKJwhKvV5Un63DOz+xuwd3ASJRwKqSWTNTIcZazPs9ihdYKOnmqaCfIwFBj +ooh/9Q0ByrA2HH4VVKpHtld0mVcCAwEAAaMYMBYwFAYDVR0RBA0wC4IJbG9jYWxo +b3N0MA0GCSqGSIb3DQEBBQUAA4IBAQB/cSeIdAHuWM9BENmdAlul1jrAegNRK57k +KLcRiirq9dTtusTlzars+DZdPHewHajWsSil2191DyqV3n/zYq/1g9oWYX80jvX1 +wSlfM/0T6PWc9miRChVx8mGQc/C7vKE4j4oxRZ9EsZIyqKlrxqWA4UXuOZUSaLWx +nECZRf/ofzcr6wNMdoZ8pQUqW05Jmnr+XiP09UoPHQsct9xfzOUGCB3PT47tVK7b +Hu1PStj2VzTPeSDGv/R8X5bPcUcZIdK7as5MKVu9slmk9QLlUj3C6dmw7VudWisg +CKglns9xWEOEA71DVeTS1ieLYychQdYIfNRMulgU+dC8djN2U/Sc +-----END CERTIFICATE----- + +-- client.key -- +FOO diff --git a/internal/alertmanager/model_test.go b/internal/alertmanager/models_test.go similarity index 85% rename from internal/alertmanager/model_test.go rename to internal/alertmanager/models_test.go index 13b68528a..b28095da9 100644 --- a/internal/alertmanager/model_test.go +++ b/internal/alertmanager/models_test.go @@ -193,3 +193,30 @@ func TestAlertmanagerPullWithInvalidURI(t *testing.T) { t.Error("am.Pull(invalid uri) didn't return any error") } } + +func TestAlertmanagerPullAlertsWithInvalidVersion(t *testing.T) { + log.SetLevel(log.PanicLevel) + am, _ := NewAlertmanager("cluster", "test", "http://localhost") + err := am.pullAlerts("0.0.1") + if err == nil { + t.Error("am.pullAlerts(invalid version) didn't return any error") + } +} + +func TestAlertmanagerPullSilencesWithInvalidVersion(t *testing.T) { + log.SetLevel(log.PanicLevel) + am, _ := NewAlertmanager("cluster", "test", "http://localhost") + err := am.pullSilences("0.0.1") + if err == nil { + t.Error("am.pullSilences(invalid version) didn't return any error") + } +} + +func TestAlertmanagerFetchStatusWithInvalidVersion(t *testing.T) { + log.SetLevel(log.PanicLevel) + am, _ := NewAlertmanager("cluster", "test", "http://localhost") + _, err := am.fetchStatus("0.0.1") + if err == nil { + t.Error("am.fetchStatus(invalid version) didn't return any error") + } +} diff --git a/internal/alertmanager/upstream_test.go b/internal/alertmanager/upstream_test.go index f37bfcd0f..a22b3fa2b 100644 --- a/internal/alertmanager/upstream_test.go +++ b/internal/alertmanager/upstream_test.go @@ -9,7 +9,8 @@ import ( ) type testCase struct { - config config.AlertmanagerConfig + config config.AlertmanagerConfig + shouldFail bool } var testCases = []testCase{ @@ -49,6 +50,32 @@ var testCases = []testCase{ Headers: map[string]string{}, }, }, + { + config: config.AlertmanagerConfig{ + Cluster: "cluster", + Name: "name", + URI: "%gh&%ij", + ExternalURI: "http://localhost:9095", + Timeout: time.Second * 30, + Proxy: false, + ReadOnly: true, + Headers: map[string]string{}, + }, + shouldFail: true, + }, + { + config: config.AlertmanagerConfig{ + Cluster: "cluster", + Name: "name", + URI: "http://localhost:9095", + ExternalURI: "%gh&%ij", + Timeout: time.Second * 30, + Proxy: false, + ReadOnly: true, + Headers: map[string]string{}, + }, + shouldFail: true, + }, } func TestOptions(t *testing.T) { @@ -72,9 +99,15 @@ func TestOptions(t *testing.T) { WithReadOnly(tc.config.ReadOnly), WithHTTPTransport(httpTransport), // we will pass a nil unless TLS.CA or TLS.Cert is set WithHTTPHeaders(tc.config.Headers), + WithCORSCredentials(tc.config.CORS.Credentials), ) + didFail := err != nil + if didFail != tc.shouldFail { + t.Errorf("Alertmanager '%s' error mismatch, shouldFail=%v, err=%v", tc.config.Name, tc.shouldFail, err) + } if err != nil { - t.Errorf("Failed to create Alertmanager '%s' with URI '%s': %s", tc.config.Name, tc.config.URI, err) + t.Logf("Alertmanager '%s' returned an error: %v", tc.config.Name, err) + continue } if am.Name != tc.config.Name { t.Errorf("AlertmanagerConfig with name '%s' returned Alertmanager with name '%s'", tc.config.Name, am.Name) @@ -88,5 +121,8 @@ func TestOptions(t *testing.T) { if am.ReadOnly != tc.config.ReadOnly { t.Errorf("AlertmanagerConfig with name '%s' and readonly '%v' returned Alertmanager with readonly '%v'", tc.config.Name, tc.config.ReadOnly, am.ReadOnly) } + if am.CORSCredentials != tc.config.CORS.Credentials { + t.Errorf("AlertmanagerConfig with name '%s' and cors:credentials '%v' returned Alertmanager with cors:credentials '%v'", tc.config.Name, tc.config.CORS.Credentials, am.CORSCredentials) + } } }