diff --git a/.travis.yml b/.travis.yml index 10b3f169..90064caf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,10 +5,9 @@ os: go: - 1.12.x go_import_path: github.com/kataras/iris -# we disable test caching via GOCACHE=off -# env: -# global: -# - GOCACHE=off +env: + global: + - GO111MODULE=on install: - go get ./... script: diff --git a/httptest/httptest_go19.go b/httptest/httptest_go19.go new file mode 100644 index 00000000..0bcd5ad3 --- /dev/null +++ b/httptest/httptest_go19.go @@ -0,0 +1,8 @@ +// +build go1.9 + +package httptest + +import "github.com/gavv/httpexpect" + +// Request type alias. +type Request = httpexpect.Request diff --git a/sessions/cookie.go b/sessions/cookie.go index 5a0bf359..23d47534 100644 --- a/sessions/cookie.go +++ b/sessions/cookie.go @@ -115,6 +115,7 @@ func formatCookieDomain(ctx context.Context, disableSubdomainPersistence bool) s requestDomain = requestDomain[dotIdx+1:] } } + // finally set the .localhost.com (for(1-level) || .mysubdomain.localhost.com (for 2-level subdomain allow) return "." + requestDomain // . to allow persistence } diff --git a/sessions/sessions.go b/sessions/sessions.go index 046972d3..e829a4d5 100644 --- a/sessions/sessions.go +++ b/sessions/sessions.go @@ -177,12 +177,12 @@ func (s *Sessions) decodeCookieValue(cookieValue string) string { return "" } - var cookieValueDecoded *string + var cookieValueDecoded string if decode := s.config.Decode; decode != nil { err := decode(s.config.Cookie, cookieValue, &cookieValueDecoded) if err == nil { - cookieValue = *cookieValueDecoded + cookieValue = cookieValueDecoded } else { cookieValue = "" } diff --git a/sessions/sessions_test.go b/sessions/sessions_test.go index 9457d5a0..c0d52546 100644 --- a/sessions/sessions_test.go +++ b/sessions/sessions_test.go @@ -17,7 +17,7 @@ func TestSessions(t *testing.T) { } const ( - testEnableSubdomain = false + testEnableSubdomain = true ) func testSessions(t *testing.T, sess *sessions.Sessions, app *iris.Application) { @@ -35,16 +35,14 @@ func testSessions(t *testing.T, sess *sessions.Sessions, app *iris.Application) } if testEnableSubdomain { - app.Party("subdomain.").Get("/get", func(ctx context.Context) { - writeValues(ctx) - }) + app.Party("subdomain.").Get("/get", writeValues) } app.Post("/set", func(ctx context.Context) { s := sess.Start(ctx) vals := make(map[string]interface{}, 0) if err := ctx.ReadJSON(&vals); err != nil { - t.Fatalf("Cannot readjson. Trace %s", err.Error()) + t.Fatalf("Cannot read JSON. Trace %s", err.Error()) } for k, v := range vals { s.Set(k, v) @@ -84,10 +82,11 @@ func testSessions(t *testing.T, sess *sessions.Sessions, app *iris.Application) e.POST("/set").WithJSON(values).Expect().Status(iris.StatusOK).Cookies().NotEmpty() e.GET("/get").Expect().Status(iris.StatusOK).JSON().Object().Equal(values) if testEnableSubdomain { - es := httptest.New(t, app, httptest.URL("http://subdomain.example.com")) + es := e.Builder(func(req *httptest.Request) { + req.WithURL("http://subdomain.example.com") + }) es.Request("GET", "/get").Expect().Status(iris.StatusOK).JSON().Object().Equal(values) } - // test destroy which also clears first d := e.GET("/destroy").Expect().Status(iris.StatusOK) d.JSON().Object().Empty()