...

Source file src/github.com/gin-contrib/sessions/tester/tester_options_samesite_go1.11.go

Documentation: github.com/gin-contrib/sessions/tester

     1  // +build go1.11
     2  
     3  package tester
     4  
     5  import (
     6  	"net/http"
     7  	"net/http/httptest"
     8  	"strings"
     9  	"testing"
    10  
    11  	"github.com/gin-contrib/sessions"
    12  	"github.com/gin-gonic/gin"
    13  )
    14  
    15  func testOptionSameSitego(t *testing.T, r *gin.Engine) {
    16  	r.GET("/sameSite", func(c *gin.Context) {
    17  		session := sessions.Default(c)
    18  		session.Set("key", ok)
    19  		session.Options(sessions.Options{
    20  			SameSite: http.SameSiteStrictMode,
    21  		})
    22  		_ = session.Save()
    23  		c.String(200, ok)
    24  	})
    25  
    26  	res3 := httptest.NewRecorder()
    27  	req3, _ := http.NewRequest("GET", "/sameSite", nil)
    28  	r.ServeHTTP(res3, req3)
    29  
    30  	s := strings.Split(res3.Header().Get("Set-Cookie"), ";")
    31  	if s[1] != " SameSite=Strict" {
    32  		t.Error("Error writing samesite with options:", s[1])
    33  	}
    34  }
    35  

View as plain text