|
8 | 8 | "encoding/json"
|
9 | 9 | "testing"
|
10 | 10 |
|
| 11 | + "code.gitea.io/gitea/modules/setting" |
| 12 | + |
11 | 13 | "github.com/stretchr/testify/assert"
|
12 | 14 | )
|
13 | 15 |
|
@@ -177,3 +179,42 @@ func TestAccessTokenExchangeWithBasicAuth(t *testing.T) {
|
177 | 179 | })
|
178 | 180 | resp = MakeRequest(t, req, 400)
|
179 | 181 | }
|
| 182 | + |
| 183 | +func TestRefreshTokenInvalidation(t *testing.T) { |
| 184 | + prepareTestEnv(t) |
| 185 | + req := NewRequestWithValues(t, "POST", "/login/oauth/access_token", map[string]string{ |
| 186 | + "grant_type": "authorization_code", |
| 187 | + "client_id": "da7da3ba-9a13-4167-856f-3899de0b0138", |
| 188 | + "client_secret": "4MK8Na6R55smdCY0WuCCumZ6hjRPnGY5saWVRHHjJiA=", |
| 189 | + "redirect_uri": "a", |
| 190 | + "code": "authcode", |
| 191 | + "code_verifier": "N1Zo9-8Rfwhkt68r1r29ty8YwIraXR8eh_1Qwxg7yQXsonBt", // test PKCE additionally |
| 192 | + }) |
| 193 | + resp := MakeRequest(t, req, 200) |
| 194 | + type response struct { |
| 195 | + AccessToken string `json:"access_token"` |
| 196 | + TokenType string `json:"token_type"` |
| 197 | + ExpiresIn int64 `json:"expires_in"` |
| 198 | + RefreshToken string `json:"refresh_token"` |
| 199 | + } |
| 200 | + parsed := new(response) |
| 201 | + assert.NoError(t, json.Unmarshal(resp.Body.Bytes(), parsed)) |
| 202 | + |
| 203 | + // test without invalidation |
| 204 | + setting.OAuth2.InvalidateRefreshTokens = false |
| 205 | + |
| 206 | + refreshReq := NewRequestWithValues(t, "POST", "/login/oauth/access_token", map[string]string{ |
| 207 | + "grant_type": "refresh_token", |
| 208 | + "client_id": "da7da3ba-9a13-4167-856f-3899de0b0138", |
| 209 | + "client_secret": "4MK8Na6R55smdCY0WuCCumZ6hjRPnGY5saWVRHHjJiA=", |
| 210 | + "redirect_uri": "a", |
| 211 | + "refresh_token": parsed.RefreshToken, |
| 212 | + }) |
| 213 | + MakeRequest(t, refreshReq, 200) |
| 214 | + MakeRequest(t, refreshReq, 200) |
| 215 | + |
| 216 | + // test with invalidation |
| 217 | + setting.OAuth2.InvalidateRefreshTokens = true |
| 218 | + MakeRequest(t, refreshReq, 200) |
| 219 | + MakeRequest(t, refreshReq, 400) |
| 220 | +} |
0 commit comments