summaryrefslogtreecommitdiffstats
path: root/integrations/oauth_test.go
diff options
context:
space:
mode:
authorJonas Franz <info@jonasfranz.software>2019-04-15 17:54:50 +0200
committertechknowlogick <matti@mdranta.net>2019-04-15 11:54:50 -0400
commit62d3f49c28c9df2991793fe6846b10088fd5d770 (patch)
tree87aa1161b6b9f3e64a5a46d1f3d8c92d387777e8 /integrations/oauth_test.go
parente6161b09fffe53273b6b91435f0dca39053920c8 (diff)
downloadgitea-62d3f49c28c9df2991793fe6846b10088fd5d770.tar.gz
gitea-62d3f49c28c9df2991793fe6846b10088fd5d770.zip
Add json tags for oauth2 form (#6627)
Diffstat (limited to 'integrations/oauth_test.go')
-rw-r--r--integrations/oauth_test.go25
1 files changed, 24 insertions, 1 deletions
diff --git a/integrations/oauth_test.go b/integrations/oauth_test.go
index 2b5839dd71..ed5761a86b 100644
--- a/integrations/oauth_test.go
+++ b/integrations/oauth_test.go
@@ -75,7 +75,30 @@ func TestAccessTokenExchange(t *testing.T) {
func TestAccessTokenExchangeWithoutPKCE(t *testing.T) {
prepareTestEnv(t)
- req := NewRequestWithValues(t, "POST", "/login/oauth/access_token", map[string]string{
+ req := NewRequestWithJSON(t, "POST", "/login/oauth/access_token", map[string]string{
+ "grant_type": "authorization_code",
+ "client_id": "da7da3ba-9a13-4167-856f-3899de0b0138",
+ "client_secret": "4MK8Na6R55smdCY0WuCCumZ6hjRPnGY5saWVRHHjJiA=",
+ "redirect_uri": "a",
+ "code": "authcode",
+ "code_verifier": "N1Zo9-8Rfwhkt68r1r29ty8YwIraXR8eh_1Qwxg7yQXsonBt", // test PKCE additionally
+ })
+ resp := MakeRequest(t, req, 200)
+ type response struct {
+ AccessToken string `json:"access_token"`
+ TokenType string `json:"token_type"`
+ ExpiresIn int64 `json:"expires_in"`
+ RefreshToken string `json:"refresh_token"`
+ }
+ parsed := new(response)
+ assert.NoError(t, json.Unmarshal(resp.Body.Bytes(), parsed))
+ assert.True(t, len(parsed.AccessToken) > 10)
+ assert.True(t, len(parsed.RefreshToken) > 10)
+}
+
+func TestAccessTokenExchangeJSON(t *testing.T) {
+ prepareTestEnv(t)
+ req := NewRequestWithJSON(t, "POST", "/login/oauth/access_token", map[string]string{
"grant_type": "authorization_code",
"client_id": "da7da3ba-9a13-4167-856f-3899de0b0138",
"client_secret": "4MK8Na6R55smdCY0WuCCumZ6hjRPnGY5saWVRHHjJiA=",