44 "context"
55 "crypto"
66 "crypto/rand"
7+ "crypto/tls"
78 "encoding/json"
89 "fmt"
910 "io"
@@ -32,6 +33,7 @@ import (
3233 "github.com/coder/coder/v2/coderd/audit"
3334 "github.com/coder/coder/v2/coderd/coderdtest"
3435 "github.com/coder/coder/v2/coderd/coderdtest/oidctest"
36+ "github.com/coder/coder/v2/coderd/coderdtest/testjar"
3537 "github.com/coder/coder/v2/coderd/cryptokeys"
3638 "github.com/coder/coder/v2/coderd/database"
3739 "github.com/coder/coder/v2/coderd/database/dbauthz"
@@ -65,8 +67,16 @@ func TestOIDCOauthLoginWithExisting(t *testing.T) {
6567 cfg .SecondaryClaims = coderd .MergedClaimsSourceNone
6668 })
6769
70+ certificates := []tls.Certificate {testutil .GenerateTLSCertificate (t , "localhost" )}
6871 client , _ , api := coderdtest .NewWithAPI (t , & coderdtest.Options {
69- OIDCConfig : cfg ,
72+ OIDCConfig : cfg ,
73+ TLSCertificates : certificates ,
74+ DeploymentValues : coderdtest .DeploymentValues (t , func (values * codersdk.DeploymentValues ) {
75+ values .HTTPCookies = codersdk.HTTPCookieConfig {
76+ Secure : true ,
77+ SameSite : "none" ,
78+ }
79+ }),
7080 })
7181
7282 const username = "alice"
@@ -77,15 +87,35 @@ func TestOIDCOauthLoginWithExisting(t *testing.T) {
7787 "sub" : uuid .NewString (),
7888 }
7989
80- helper := oidctest .NewLoginHelper (client , fake )
8190 // Signup alice
82- userClient , _ := helper .Login (t , claims )
91+ freshClient := func () * codersdk.Client {
92+ cli := codersdk .New (client .URL )
93+ cli .HTTPClient .Transport = & http.Transport {
94+ TLSClientConfig : & tls.Config {
95+ InsecureSkipVerify : true ,
96+ },
97+ }
98+ cli .HTTPClient .Jar = testjar .New ()
99+ return cli
100+ }
101+
102+ unauthenticated := freshClient ()
103+ userClient , _ := fake .Login (t , unauthenticated , claims )
104+
105+ cookies := unauthenticated .HTTPClient .Jar .Cookies (client .URL )
106+ require .True (t , len (cookies ) > 0 )
107+ for _ , c := range cookies {
108+ require .Truef (t , c .Secure , "cookie %q" , c .Name )
109+ require .Equalf (t , http .SameSiteNoneMode , c .SameSite , "cookie %q" , c .Name )
110+ }
83111
84112 // Expire the link. This will force the client to refresh the token.
113+ helper := oidctest .NewLoginHelper (userClient , fake )
85114 helper .ExpireOauthToken (t , api .Database , userClient )
86115
87116 // Instead of refreshing, just log in again.
88- helper .Login (t , claims )
117+ unauthenticated = freshClient ()
118+ fake .Login (t , unauthenticated , claims )
89119}
90120
91121func TestUserLogin (t * testing.T ) {
0 commit comments