File tree Expand file tree Collapse file tree 5 files changed +36
-23
lines changed Expand file tree Collapse file tree 5 files changed +36
-23
lines changed Original file line number Diff line number Diff line change @@ -110,7 +110,7 @@ func CSRFWithConfig(config CSRFConfig) echo.MiddlewareFunc {
110
110
if config .CookieMaxAge == 0 {
111
111
config .CookieMaxAge = DefaultCSRFConfig .CookieMaxAge
112
112
}
113
- if config .CookieSameSite == http . SameSiteNoneMode {
113
+ if config .CookieSameSite == SameSiteNoneMode {
114
114
config .CookieSecure = true
115
115
}
116
116
Original file line number Diff line number Diff line change 1
- // +build ! go1.12
1
+ // +build go1.13
2
2
3
3
package middleware
4
4
Original file line number Diff line number Diff line change 1
- // +build go1.12
1
+ // +build ! go1.13
2
2
3
3
package middleware
4
4
Original file line number Diff line number Diff line change
1
+ // +build go1.13
2
+
3
+ package middleware
4
+
5
+ import (
6
+ "net/http"
7
+ "net/http/httptest"
8
+ "testing"
9
+
10
+ "github.com/labstack/echo/v4"
11
+ "github.com/stretchr/testify/assert"
12
+ )
13
+
14
+ // Test for SameSiteModeNone moved to separate file for Go 1.12 support
15
+ func TestCSRFWithSameSiteModeNone (t * testing.T ) {
16
+ e := echo .New ()
17
+ req := httptest .NewRequest (http .MethodGet , "/" , nil )
18
+ rec := httptest .NewRecorder ()
19
+ c := e .NewContext (req , rec )
20
+
21
+ csrf := CSRFWithConfig (CSRFConfig {
22
+ CookieSameSite : SameSiteNoneMode ,
23
+ })
24
+
25
+ h := csrf (func (c echo.Context ) error {
26
+ return c .String (http .StatusOK , "test" )
27
+ })
28
+
29
+ r := h (c )
30
+ assert .NoError (t , r )
31
+ assert .Regexp (t , "SameSite=None" , rec .Header ()["Set-Cookie" ])
32
+ assert .Regexp (t , "Secure" , rec .Header ()["Set-Cookie" ])
33
+ }
Original file line number Diff line number Diff line change @@ -138,23 +138,3 @@ func TestCSRFWithSameSiteDefaultMode(t *testing.T) {
138
138
fmt .Println (rec .Header ()["Set-Cookie" ])
139
139
assert .NotRegexp (t , "SameSite=" , rec .Header ()["Set-Cookie" ])
140
140
}
141
-
142
- func TestCSRFWithSameSiteModeNone (t * testing.T ) {
143
- e := echo .New ()
144
- req := httptest .NewRequest (http .MethodGet , "/" , nil )
145
- rec := httptest .NewRecorder ()
146
- c := e .NewContext (req , rec )
147
-
148
- csrf := CSRFWithConfig (CSRFConfig {
149
- CookieSameSite : SameSiteNoneMode ,
150
- })
151
-
152
- h := csrf (func (c echo.Context ) error {
153
- return c .String (http .StatusOK , "test" )
154
- })
155
-
156
- r := h (c )
157
- assert .NoError (t , r )
158
- assert .Regexp (t , "SameSite=None" , rec .Header ()["Set-Cookie" ])
159
- assert .Regexp (t , "Secure" , rec .Header ()["Set-Cookie" ])
160
- }
You can’t perform that action at this time.
0 commit comments