Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
Merge branch 'ssl-certificate-verify-pr' of github.com:justincmoy/go-…
Browse files Browse the repository at this point in the history
…pingdom into justincmoy-ssl-certificate-verify-pr
russellcardullo committed Sep 15, 2020
2 parents f97b22c + 364bdbe commit 2a42460
Showing 3 changed files with 123 additions and 45 deletions.
20 changes: 11 additions & 9 deletions pingdom/api_responses.go
Original file line number Diff line number Diff line change
@@ -204,15 +204,17 @@ func (c *CheckResponseType) UnmarshalJSON(b []byte) error {

// CheckResponseHTTPDetails represents the details specific to HTTP checks.
type CheckResponseHTTPDetails struct {
Url string `json:"url,omitempty"`
Encryption bool `json:"encryption,omitempty"`
Port int `json:"port,omitempty"`
Username string `json:"username,omitempty"`
Password string `json:"password,omitempty"`
ShouldContain string `json:"shouldcontain,omitempty"`
ShouldNotContain string `json:"shouldnotcontain,omitempty"`
PostData string `json:"postdata,omitempty"`
RequestHeaders map[string]string `json:"requestheaders,omitempty"`
Url string `json:"url,omitempty"`
Encryption bool `json:"encryption,omitempty"`
Port int `json:"port,omitempty"`
Username string `json:"username,omitempty"`
Password string `json:"password,omitempty"`
ShouldContain string `json:"shouldcontain,omitempty"`
ShouldNotContain string `json:"shouldnotcontain,omitempty"`
PostData string `json:"postdata,omitempty"`
RequestHeaders map[string]string `json:"requestheaders,omitempty"`
VerifyCertificate bool `json:"verify_certificate,omitempty"`
SSLDownDaysBefore int `json:"ssl_down_days_before,omitempty"`
}

// CheckResponseTCPDetails represents the details specific to TCP checks.
10 changes: 10 additions & 0 deletions pingdom/check_types.go
Original file line number Diff line number Diff line change
@@ -30,6 +30,8 @@ type HttpCheck struct {
ProbeFilters string `json:"probe_filters,omitempty"`
UserIds []int `json:"userids,omitempty"`
TeamIds []int `json:"teamids,omitempty"`
VerifyCertificate *bool `json:"verify_certificate,omitempty"`
SSLDownDaysBefore *int `json:"ssl_down_days_before,omitempty"`
}

// PingCheck represents a Pingdom ping check.
@@ -112,6 +114,14 @@ func (ck *HttpCheck) PutParams() map[string]string {
m["responsetime_threshold"] = strconv.Itoa(ck.ResponseTimeThreshold)
}

if ck.VerifyCertificate != nil {
m["verify_certificate"] = strconv.FormatBool(*ck.VerifyCertificate)
}

if ck.SSLDownDaysBefore != nil {
m["ssl_down_days_before"] = strconv.Itoa(*ck.SSLDownDaysBefore)
}

// ShouldContain and ShouldNotContain are mutually exclusive.
// But we must define one so they can be emptied if required.
if ck.ShouldContain != "" {
138 changes: 102 additions & 36 deletions pingdom/check_types_test.go
Original file line number Diff line number Diff line change
@@ -7,48 +7,110 @@ import (
)

func TestHttpCheckPutParams(t *testing.T) {
check := HttpCheck{
Name: "fake check",
Hostname: "example.com",
Url: "/foo",
RequestHeaders: map[string]string{
"User-Agent": "Pingdom.com_bot_version_1.4_(http://www.pingdom.com/)",
"Pragma": "no-cache",
verifyCertificate := true
sslDownDaysBefore := 10

tests := []struct {
name string
giveCheck HttpCheck
wantParams map[string]string
}{
{
name: "parametrizes http check",
giveCheck: HttpCheck{
Name: "fake check",
Hostname: "example.com",
Url: "/foo",
RequestHeaders: map[string]string{
"User-Agent": "Pingdom.com_bot_version_1.4_(http://www.pingdom.com/)",
"Pragma": "no-cache",
},
Username: "user",
Password: "pass",
IntegrationIds: []int{33333333, 44444444},
UserIds: []int{123, 456},
TeamIds: []int{789},
ResponseTimeThreshold: 2300,
VerifyCertificate: &verifyCertificate,
SSLDownDaysBefore: &sslDownDaysBefore,
},
wantParams: map[string]string{
"name": "fake check",
"host": "example.com",
"paused": "false",
"resolution": "0",
"notifyagainevery": "0",
"notifywhenbackup": "false",
"url": "/foo",
"requestheader0": "Pragma:no-cache",
"requestheader1": "User-Agent:Pingdom.com_bot_version_1.4_(http://www.pingdom.com/)",
"auth": "user:pass",
"encryption": "false",
"shouldnotcontain": "",
"postdata": "",
"integrationids": "33333333,44444444",
"tags": "",
"probe_filters": "",
"userids": "123,456",
"teamids": "789",
"responsetime_threshold": "2300",
"verify_certificate": "true",
"ssl_down_days_before": "10",
},
},
{
name: "parametrizes http check without optional fields",
giveCheck: HttpCheck{
Name: "fake check",
Hostname: "example.com",
Url: "/foo",
RequestHeaders: map[string]string{
"User-Agent": "Pingdom.com_bot_version_1.4_(http://www.pingdom.com/)",
"Pragma": "no-cache",
},
Username: "user",
Password: "pass",
IntegrationIds: []int{33333333, 44444444},
UserIds: []int{123, 456},
TeamIds: []int{789},
ResponseTimeThreshold: 2300,
},
wantParams: map[string]string{
"name": "fake check",
"host": "example.com",
"paused": "false",
"resolution": "0",
"notifyagainevery": "0",
"notifywhenbackup": "false",
"url": "/foo",
"requestheader0": "Pragma:no-cache",
"requestheader1": "User-Agent:Pingdom.com_bot_version_1.4_(http://www.pingdom.com/)",
"auth": "user:pass",
"encryption": "false",
"shouldnotcontain": "",
"postdata": "",
"integrationids": "33333333,44444444",
"tags": "",
"probe_filters": "",
"userids": "123,456",
"teamids": "789",
"responsetime_threshold": "2300",
},
},
Username: "user",
Password: "pass",
IntegrationIds: []int{33333333, 44444444},
UserIds: []int{123, 456},
TeamIds: []int{789},
ResponseTimeThreshold: 2300,
}
want := map[string]string{
"name": "fake check",
"host": "example.com",
"paused": "false",
"resolution": "0",
"notifyagainevery": "0",
"notifywhenbackup": "false",
"url": "/foo",
"requestheader0": "Pragma:no-cache",
"requestheader1": "User-Agent:Pingdom.com_bot_version_1.4_(http://www.pingdom.com/)",
"auth": "user:pass",
"encryption": "false",
"shouldnotcontain": "",
"postdata": "",
"integrationids": "33333333,44444444",
"tags": "",
"probe_filters": "",
"userids": "123,456",
"teamids": "789",
"responsetime_threshold": "2300",
}

params := check.PutParams()
assert.Equal(t, want, params)
for _, tt := range tests {
t.Run(tt.name, func(tst *testing.T) {
params := tt.giveCheck.PutParams()
assert.Equal(tst, tt.wantParams, params)
})
}
}

func TestHttpCheckPostParams(t *testing.T) {
verifyCertificate := true
sslDownDaysBefore := 10

check := HttpCheck{
Name: "fake check",
Hostname: "example.com",
@@ -63,6 +125,8 @@ func TestHttpCheckPostParams(t *testing.T) {
UserIds: []int{123, 456},
TeamIds: []int{789},
ResponseTimeThreshold: 2300,
VerifyCertificate: &verifyCertificate,
SSLDownDaysBefore: &sslDownDaysBefore,
}
want := map[string]string{
"name": "fake check",
@@ -81,6 +145,8 @@ func TestHttpCheckPostParams(t *testing.T) {
"userids": "123,456",
"teamids": "789",
"responsetime_threshold": "2300",
"verify_certificate": "true",
"ssl_down_days_before": "10",
}

params := check.PostParams()

0 comments on commit 2a42460

Please sign in to comment.