-
Notifications
You must be signed in to change notification settings - Fork 1
/
httpsverifier_test.go
41 lines (33 loc) · 982 Bytes
/
httpsverifier_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"net/http/httptest"
"testing"
"github.com/pushc6/httpsverifier/servicetypes"
)
func TestHandler(t *testing.T) {
theReq := &servicetypes.FingerprintRequest{
Domains: []string{"https://facebook.com", "linkedin.com", "ddfsvsdvsv.com", "reddit.com"},
}
jReq, _ := json.Marshal(&theReq)
fmt.Println(jReq)
req, err := http.NewRequest("GET", "localhost:8080/blah", bytes.NewBuffer(jReq))
if err != nil {
t.Fatal(err)
}
rr := httptest.NewRecorder()
handlerTest := http.HandlerFunc(handler)
handlerTest.ServeHTTP(rr, req)
decoder := json.NewDecoder(rr.Body)
fingerResponse := &servicetypes.FingerprintResponse{}
decoder.Decode(fingerResponse)
for _, result := range fingerResponse.Results {
fmt.Println("Result for ", result.Domain, " is ", result.Fingerprint)
}
if len(fingerResponse.Results) == 0 || len(fingerResponse.Results) == 0 {
t.Error("Either domain or fingerprint failed")
}
}