@@ -45,6 +45,7 @@ func TestManager(t *testing.T) {
4545
4646 Convey ("zero expiration access token test" , func () {
4747 testZeroAccessExpirationManager (tgr , manager )
48+ testCannotRequestZeroExpirationAccessTokens (tgr , manager )
4849 })
4950
5051 Convey ("zero expiration refresh token test" , func () {
@@ -152,6 +153,35 @@ func testZeroAccessExpirationManager(tgr *oauth2.TokenGenerateRequest, manager o
152153 So (tokenInfo .GetAccessExpiresIn (), ShouldEqual , 0 )
153154}
154155
156+ func testCannotRequestZeroExpirationAccessTokens (tgr * oauth2.TokenGenerateRequest , manager oauth2.Manager ) {
157+ config := manage.Config {
158+ AccessTokenExp : time .Hour * 5 ,
159+ }
160+ m , ok := manager .(* manage.Manager )
161+ So (ok , ShouldBeTrue )
162+ m .SetAuthorizeCodeTokenCfg (& config )
163+
164+ cti , err := manager .GenerateAuthToken (oauth2 .Code , tgr )
165+ So (err , ShouldBeNil )
166+
167+ code := cti .GetCode ()
168+ So (code , ShouldNotBeEmpty )
169+
170+ atParams := & oauth2.TokenGenerateRequest {
171+ ClientID : tgr .ClientID ,
172+ ClientSecret : "11" ,
173+ RedirectURI : tgr .RedirectURI ,
174+ AccessTokenExp : 0 , // requesting token without expiration
175+ Code : code ,
176+ }
177+ ati , err := manager .GenerateAccessToken (oauth2 .AuthorizationCode , atParams )
178+ So (err , ShouldBeNil )
179+
180+ accessToken := ati .GetAccess ()
181+ So (accessToken , ShouldNotBeEmpty )
182+ So (ati .GetAccessExpiresIn (), ShouldEqual , time .Hour * 5 )
183+ }
184+
155185func testZeroRefreshExpirationManager (tgr * oauth2.TokenGenerateRequest , manager oauth2.Manager ) {
156186 config := manage.Config {
157187 RefreshTokenExp : 0 , // Set explicitly as we're testing 0 (no) expiration
0 commit comments