Skip to content

Commit

Permalink
Merge pull request #62 from /pull/61
Browse files Browse the repository at this point in the history
Fix for using correct host in networking mode
  • Loading branch information
steinfletcher authored Oct 17, 2019
2 parents ad74029 + aca8d2c commit 49f4f82
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
7 changes: 5 additions & 2 deletions apitest.go
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ func (a *APITest) doRequest() (*http.Response, *http.Request) {
} else {
res, err = a.networkingHTTPClient.Do(req)
if err != nil {
panic(err)
a.t.Fatal(err)
}
}

Expand Down Expand Up @@ -737,7 +737,10 @@ func (a *APITest) buildRequest() *http.Request {

req, _ := http.NewRequest(a.request.method, a.request.url, bytes.NewBufferString(a.request.body))
req.URL.RawQuery = formatQuery(a.request)
req.Host = "application"
req.Host = SystemUnderTestDefaultName
if a.networkingEnabled {
req.Host = req.URL.Host
}

for k, v := range a.request.headers {
for _, headerValue := range v {
Expand Down
12 changes: 12 additions & 0 deletions cookies.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,18 @@ func (cookie *Cookie) ToHttpCookie() *http.Cookie {
return &httpCookie
}

// FromHTTPCookie transforms an http cookie into a Cookie
func FromHTTPCookie(httpCookie *http.Cookie) *Cookie {
return NewCookie(httpCookie.Name).
Value(httpCookie.Value).
Path(httpCookie.Path).
Domain(httpCookie.Domain).
Expires(httpCookie.Expires).
MaxAge(httpCookie.MaxAge).
Secure(httpCookie.Secure).
HttpOnly(httpCookie.HttpOnly)
}

// Compares cookies based on only the provided fields from Cookie.
// Supported fields are Name, Value, Domain, Path, Expires, MaxAge, Secure and HttpOnly
func compareCookies(expectedCookie *Cookie, actualCookie *http.Cookie) (bool, []string) {
Expand Down
17 changes: 17 additions & 0 deletions cookies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,23 @@ func TestApiTest_Cookies_ToHttpCookie(t *testing.T) {
}, *httpCookie)
}

func TestApiTest_Cookies_FromHttpCookie(t *testing.T) {
expiry, _ := time.Parse("1/2/2006 15:04:05", "03/01/2017 12:00:00")

cookie := NewCookie("Tom").
Value("LovesBeers").
Path("/at-the-lyric").
Domain("in.london").
Expires(expiry).
MaxAge(10).
Secure(true).
HttpOnly(false)

result := FromHTTPCookie(cookie.ToHttpCookie())

assert.Equal(t, cookie, result)
}

func TestApiTest_Cookies_ToHttpCookie_PartiallyCreated(t *testing.T) {
expiry, _ := time.Parse("1/2/2006 15:04:05", "03/01/2017 12:00:00")

Expand Down

0 comments on commit 49f4f82

Please sign in to comment.