Skip to content

Commit

Permalink
Allow checking sites that have bad SSL certs (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
symm authored Jul 5, 2017
1 parent a1a21d6 commit 499e45b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ run-docker:
https://httpbin.org

test:
go test ./... -cover -coverprofile=coverage.out -race
go test ./... -cover -coverprofile=coverage.out

coverage: test
go tool cover -html=coverage.out
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ docker run \

### Optional Arguments

`-config full/path/to/Vapefile` specify an alternative to looking for `Vapefile` in the current directory
`-config full/path/to/Vapefile`: specify an alternative to looking for `Vapefile` in the current directory
`-skip-ssl-verification`: Ignore bad / self signed SSL certificates

## TODO

Expand Down
17 changes: 14 additions & 3 deletions http.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"crypto/tls"
"net/http"
"time"
)
Expand All @@ -10,7 +11,17 @@ type HTTPClient interface {
Get(url string) (*http.Response, error)
}

// DefaultClient returns a HTTP client with configured timeouts.
var DefaultClient = &http.Client{
Timeout: time.Duration(5 * time.Second),
// NewHTTPClient returns a configrued HTTP client.
func NewHTTPClient(sslSkip bool) *http.Client {
client := &http.Client{
Timeout: time.Duration(5 * time.Second),
}

client.Transport = &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: sslSkip,
},
}

return client
}
21 changes: 10 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import (
"time"
)

var vapeFile = flag.String("config", "Vapefile", "The full path to the Vape configuration file")

func main() {
start := time.Now()

vapeFile := flag.String("config", "Vapefile", "The full path to the Vape configuration file")
insecureSSL := flag.Bool("skip-ssl-verification", false, "Ignore bad SSL certs")
flag.Parse()

start := time.Now()

args := flag.Args()
if len(args) < 1 {
fmt.Println("vape: usage: no base URL specified")
Expand All @@ -34,28 +34,27 @@ func main() {

testsLen := len(smokeTests)
resCh, errCh := make(chan SmokeTestResult, testsLen), make(chan error, testsLen)
vape := NewVape(DefaultClient, baseURL, resCh, errCh)
vape.Process(smokeTests)

passedCount := 0
httpClient := NewHTTPClient(*insecureSSL)
vape := NewVape(httpClient, baseURL, resCh, errCh)
vape.Process(smokeTests)

var passedCount int
for i := 0; i < testsLen; i++ {
select {
case res := <-resCh:
if res.Passed() {
passedCount++
}

fmt.Println(formatResult(res))
case err := <-errCh:
fmt.Println(err)
}
}

fmt.Printf("\n✨ [%d/%d] tests passed in %s\n", passedCount, testsLen, time.Since(start))
if passedCount < testsLen {
fmt.Println("\n🔥 Some tests failed. You may have a bad deployment")
fmt.Println("🔥 Some tests failed. You may have a bad deployment")
os.Exit(2)
}

fmt.Printf("\n✨ [%d/%d] tests passed in %s\n", passedCount, testsLen, time.Since(start))
}

0 comments on commit 499e45b

Please sign in to comment.