Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit54c78df

Browse files
committed
add custom expirary
1 parente9c1290 commit54c78df

File tree

1 file changed

+38
-4
lines changed
  • coderd/coderdtest/oidctest

1 file changed

+38
-4
lines changed

‎coderd/coderdtest/oidctest/idp.go‎

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ type FakeIDP struct {
8989
hookAuthenticateClientfunc(t testing.TB,req*http.Request) (url.Values,error)
9090
servebool
9191
// optional middlewares
92-
middlewares chi.Middlewares
92+
middlewares chi.Middlewares
93+
defaultExpire time.Duration
9394
}
9495

9596
funcStatusError(codeint,errerror)error {
@@ -134,6 +135,23 @@ func WithRefresh(hook func(email string) error) func(*FakeIDP) {
134135
}
135136
}
136137

138+
funcWithDefaultExpire(d time.Duration)func(*FakeIDP) {
139+
returnfunc(f*FakeIDP) {
140+
f.defaultExpire=d
141+
}
142+
}
143+
144+
funcWithStaticCredentials(id,secretstring)func(*FakeIDP) {
145+
returnfunc(f*FakeIDP) {
146+
ifid!="" {
147+
f.clientID=id
148+
}
149+
ifsecret!="" {
150+
f.clientSecret=secret
151+
}
152+
}
153+
}
154+
137155
// WithExtra returns extra fields that be accessed on the returned Oauth Token.
138156
// These extra fields can override the default fields (id_token, access_token, etc).
139157
funcWithMutateToken(mutateTokenfunc(tokenmap[string]interface{}))func(*FakeIDP) {
@@ -219,6 +237,7 @@ func NewFakeIDP(t testing.TB, opts ...FakeIDPOpt) *FakeIDP {
219237
hookOnRefresh:func(_string)error {returnnil },
220238
hookUserInfo:func(emailstring) (jwt.MapClaims,error) {return jwt.MapClaims{},nil },
221239
hookValidRedirectURL:func(redirectURLstring)error {returnnil },
240+
defaultExpire:time.Minute*5,
222241
}
223242

224243
for_,opt:=rangeopts {
@@ -272,8 +291,23 @@ func (f *FakeIDP) updateIssuerURL(t testing.TB, issuer string) {
272291
func (f*FakeIDP)realServer(t testing.TB)*httptest.Server {
273292
t.Helper()
274293

294+
srvURL:="localhost:0"
295+
issURL,err:=url.Parse(f.issuer)
296+
iferr==nil {
297+
ifissURL.Hostname()=="localhost"||issURL.Hostname()=="127.0.0.1" {
298+
srvURL=issURL.Host
299+
}
300+
}
301+
302+
l,err:=net.Listen("tcp",srvURL)
303+
require.NoError(t,err,"failed to create listener")
304+
275305
ctx,cancel:=context.WithCancel(context.Background())
276-
srv:=httptest.NewUnstartedServer(f.handler)
306+
srv:=&httptest.Server{
307+
Listener:l,
308+
Config:&http.Server{Handler:f.handler},
309+
}
310+
277311
srv.Config.BaseContext=func(_ net.Listener) context.Context {
278312
returnctx
279313
}
@@ -731,15 +765,15 @@ func (f *FakeIDP) httpHandler(t testing.TB) http.Handler {
731765
return
732766
}
733767

734-
exp:=time.Now().Add(time.Minute*5)
768+
exp:=time.Now().Add(f.defaultExpire)
735769
claims["exp"]=exp.UnixMilli()
736770
email:=getEmail(claims)
737771
refreshToken:=f.newRefreshTokens(email)
738772
token:=map[string]interface{}{
739773
"access_token":f.newToken(email),
740774
"refresh_token":refreshToken,
741775
"token_type":"Bearer",
742-
"expires_in":int64((time.Minute*5).Seconds()),
776+
"expires_in":int64((f.defaultExpire).Seconds()),
743777
"id_token":f.encodeClaims(t,claims),
744778
}
745779
iff.hookMutateToken!=nil {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp