-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Felipe Zipitria <[email protected]>
- Loading branch information
Showing
10 changed files
with
336 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
package http | ||
|
||
import "testing" | ||
|
||
func TestNewClient(t *testing.T) { | ||
c := NewClient() | ||
|
||
if c.Jar == nil { | ||
t.Logf("Error creating Client") | ||
} | ||
} | ||
|
||
func TestConnectDestinationHTTPS(t *testing.T) { | ||
d := &Destination{ | ||
DestAddr: "example.com", | ||
Port: 443, | ||
Protocol: "https", | ||
} | ||
|
||
c := NewClient() | ||
|
||
err := c.NewConnection(*d) | ||
if err != nil { | ||
t.Logf("This should not error") | ||
} | ||
|
||
if c.Transport.protocol != "https" { | ||
t.Logf("Error connecting to example.com using https") | ||
} | ||
} | ||
|
||
func TestDoRequest(t *testing.T) { | ||
d := &Destination{ | ||
DestAddr: "httpbin.org", | ||
Port: 443, | ||
Protocol: "https", | ||
} | ||
|
||
c := NewClient() | ||
|
||
req := generateBaseRequestForTesting() | ||
|
||
err := c.NewConnection(*d) | ||
if err != nil { | ||
t.Logf("This should not error") | ||
} | ||
|
||
_, err = c.Do(*req) | ||
|
||
if err == nil { | ||
t.Logf("This should return error") | ||
} | ||
// if resp.Parsed.Status != 301 { | ||
|
||
// } | ||
} | ||
|
||
func TestGetTrackedTime(t *testing.T) { | ||
d := &Destination{ | ||
DestAddr: "httpbin.org", | ||
Port: 443, | ||
Protocol: "https", | ||
} | ||
|
||
c := NewClient() | ||
|
||
rl := &RequestLine{ | ||
Method: "POST", | ||
URI: "/post", | ||
Version: "HTTP/1.1", | ||
} | ||
|
||
h := Header{"Accept": "*/*", "User-Agent": "go-ftw test agent", "Host": "localhost"} | ||
|
||
data := []byte(`test=me&one=two`) | ||
req := NewRequest(rl, h, data, true) | ||
|
||
err := c.NewConnection(*d) | ||
if err != nil { | ||
t.Logf("This should not error") | ||
} | ||
|
||
c.StartTrackingTime() | ||
|
||
resp, err := c.Do(*req) | ||
|
||
c.StopTrackingTime() | ||
|
||
if err != nil { | ||
t.Logf("This should not error") | ||
} | ||
|
||
if resp.Parsed.StatusCode != 200 { | ||
t.Logf("Error in calling website") | ||
} | ||
|
||
rtt := c.GetRoundTripTime() | ||
|
||
if rtt.RoundTripDuration() < 0 { | ||
t.Logf("Error getting RTT") | ||
} | ||
} | ||
|
||
func TestClientMultipartFormDataRequest(t *testing.T) { | ||
d := &Destination{ | ||
DestAddr: "httpbin.org", | ||
Port: 443, | ||
Protocol: "https", | ||
} | ||
|
||
c := NewClient() | ||
|
||
rl := &RequestLine{ | ||
Method: "POST", | ||
URI: "/post", | ||
Version: "HTTP/1.1", | ||
} | ||
|
||
h := Header{ | ||
"Accept": "*/*", "User-Agent": "go-ftw test agent", "Host": "localhost", | ||
"Content-Type": "multipart/form-data; boundary=--------397236876", | ||
} | ||
|
||
data := []byte(`----------397236876 | ||
Content-Disposition: form-data; name="fileRap"; filename="test.txt" | ||
Content-Type: text/plain | ||
Some-file-test-here | ||
----------397236876--`) | ||
|
||
req := NewRequest(rl, h, data, true) | ||
|
||
err := c.NewConnection(*d) | ||
|
||
if err != nil { | ||
t.Logf("This should not error") | ||
} | ||
|
||
c.StartTrackingTime() | ||
|
||
resp, err := c.Do(*req) | ||
|
||
c.StopTrackingTime() | ||
|
||
if err != nil { | ||
t.Logf("This should not error") | ||
} | ||
|
||
if resp.Parsed.StatusCode != 200 { | ||
t.Logf("Error in calling website") | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,25 @@ | ||
package http | ||
|
||
import "testing" | ||
|
||
func TestDestinationFromString(t *testing.T) { | ||
|
||
} | ||
func TestMultipleRequestTypes(t *testing.T) { | ||
var req *Request | ||
|
||
rl := &RequestLine{ | ||
Method: "POST", | ||
URI: "/path", | ||
Version: "HTTP/1.1", | ||
} | ||
|
||
h := Header{"Accept": "*/*", "User-Agent": "go-ftw test agent", "Host": "localhost"} | ||
|
||
data := []byte(`test=me&one=two`) | ||
req = NewRequest(rl, h, data, true) | ||
|
||
if !req.WithAutoCompleteHeaders() { | ||
t.Error("Set Autocomplete headers error ") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.