Skip to content

Commit 05b2b53

Browse files
committed
ensure immortal access tokens cannot be requested
if they haven't been explicitly configured
1 parent 856c77b commit 05b2b53

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

manage/manage_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
155185
func 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

Comments
 (0)