Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 509042e

Browse files
committed
fix: remove shared mutable state between oidc tests
1 parent 7b14b4f commit 509042e

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

coderd/userauth_test.go

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1988,30 +1988,36 @@ func TestUserLogout(t *testing.T) {
19881988
func TestOIDCDomainErrorMessage(t *testing.T) {
19891989
t.Parallel()
19901990

1991-
fake := oidctest.NewFakeIDP(t, oidctest.WithServing())
1992-
19931991
allowedDomains := []string{"allowed1.com", "allowed2.org", "company.internal"}
1994-
cfg := fake.OIDCConfig(t, nil, func(cfg *coderd.OIDCConfig) {
1995-
cfg.EmailDomain = allowedDomains
1996-
cfg.AllowSignups = true
1997-
})
19981992

1999-
server := coderdtest.New(t, &coderdtest.Options{
2000-
OIDCConfig: cfg,
2001-
})
1993+
setup := func() (*oidctest.FakeIDP, *codersdk.Client) {
1994+
fake := oidctest.NewFakeIDP(t, oidctest.WithServing())
1995+
1996+
cfg := fake.OIDCConfig(t, nil, func(cfg *coderd.OIDCConfig) {
1997+
cfg.EmailDomain = allowedDomains
1998+
cfg.AllowSignups = true
1999+
})
2000+
2001+
client := coderdtest.New(t, &coderdtest.Options{
2002+
OIDCConfig: cfg,
2003+
})
2004+
return fake, client
2005+
}
20022006

20032007
// Test case 1: Email domain not in allowed list
20042008
t.Run("ErrorMessageOmitsDomains", func(t *testing.T) {
20052009
t.Parallel()
20062010

2011+
fake, client := setup()
2012+
20072013
// Prepare claims with email from unauthorized domain
20082014
claims := jwt.MapClaims{
20092015
"email": "[email protected]",
20102016
"email_verified": true,
20112017
"sub": uuid.NewString(),
20122018
}
20132019

2014-
_, resp := fake.AttemptLogin(t, server, claims)
2020+
_, resp := fake.AttemptLogin(t, client, claims)
20152021
defer resp.Body.Close()
20162022

20172023
require.Equal(t, http.StatusForbidden, resp.StatusCode)
@@ -2031,14 +2037,16 @@ func TestOIDCDomainErrorMessage(t *testing.T) {
20312037
t.Run("MalformedEmailErrorOmitsDomains", func(t *testing.T) {
20322038
t.Parallel()
20332039

2040+
fake, client := setup()
2041+
20342042
// Prepare claims with an invalid email format (no @ symbol)
20352043
claims := jwt.MapClaims{
20362044
"email": "invalid-email-without-domain",
20372045
"email_verified": true,
20382046
"sub": uuid.NewString(),
20392047
}
20402048

2041-
_, resp := fake.AttemptLogin(t, server, claims)
2049+
_, resp := fake.AttemptLogin(t, client, claims)
20422050
defer resp.Body.Close()
20432051

20442052
require.Equal(t, http.StatusForbidden, resp.StatusCode)

0 commit comments

Comments
 (0)