@@ -412,18 +412,35 @@ func TestCORSLoginOriginPerDatabase(t *testing.T) {
412412 name string
413413 unsupportedOptions * db.UnsupportedOptions
414414 sameSite http.SameSite
415+ useTLS bool
415416 }{
416417 {
417- name : "No unsupported options" ,
418+ name : "No unsupported options with TLS " ,
418419 unsupportedOptions : nil ,
419420 sameSite : http .SameSiteNoneMode ,
421+ useTLS : true ,
420422 },
421423 {
422- name : "With unsupported options" ,
424+ name : "No unsupported options without TLS" ,
425+ unsupportedOptions : nil ,
426+ sameSite : 0 , // go 1.25 doesn't have a constant for not present when reading from Set-Cookie, this could turn into SameSiteDefaultMode (1) in future
427+ useTLS : false ,
428+ },
429+ {
430+ name : "With unsupported options and TLS" ,
423431 unsupportedOptions : & db.UnsupportedOptions {
424432 SameSiteCookie : base .Ptr ("Strict" ),
425433 },
426434 sameSite : http .SameSiteStrictMode ,
435+ useTLS : true ,
436+ },
437+ {
438+ name : "With unsupported options and no TLS" ,
439+ unsupportedOptions : & db.UnsupportedOptions {
440+ SameSiteCookie : base .Ptr ("Strict" ),
441+ },
442+ sameSite : http .SameSiteStrictMode , // forces strict mode even though this would result in an unusable cookie
443+ useTLS : false ,
427444 },
428445 }
429446 for _ , dbTestCases := range testCases {
@@ -432,6 +449,13 @@ func TestCORSLoginOriginPerDatabase(t *testing.T) {
432449 rt := NewRestTesterPersistentConfigNoDB (t )
433450 defer rt .Close ()
434451
452+ // fake TLS on public port
453+ if dbTestCases .useTLS {
454+ rt .ServerContext ().Config .API .HTTPS .TLSCertPath = "/pretend/valid/cert"
455+ } else {
456+ require .Empty (t , rt .ServerContext ().Config .API .HTTPS .TLSCertPath )
457+ }
458+
435459 dbConfig := rt .NewDbConfig ()
436460 dbConfig .Unsupported = dbTestCases .unsupportedOptions
437461 dbConfig .CORS = & auth.CORSConfig {
@@ -480,7 +504,7 @@ func TestCORSLoginOriginPerDatabase(t *testing.T) {
480504 cookie , err := http .ParseSetCookie (resp .Header ().Get ("Set-Cookie" ))
481505 require .NoError (t , err )
482506 require .NotEmpty (t , cookie .Path )
483- require .Equal (t , dbTestCases .sameSite , cookie .SameSite )
507+ require .Equal (t , dbTestCases .sameSite , cookie .SameSite , "Cookie=%#+v" , cookie )
484508 reqHeaders ["Cookie" ] = fmt .Sprintf ("%s=%s" , cookie .Name , cookie .Value )
485509 }
486510 resp = rt .SendRequestWithHeaders (http .MethodDelete , "/{{.db}}/_session" , "" , reqHeaders )
0 commit comments