Skip to content

Commit 5e9529d

Browse files
committed
Improve unit test
1 parent 44937ea commit 5e9529d

File tree

3 files changed

+13
-27
lines changed

3 files changed

+13
-27
lines changed

templates/user/settings/applications_oauth2_edit_form.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
<div class="field {{if .Err_Confidential}}error{{end}}">
4343
<label for="confidential">{{.locale.Tr "settings.oauth2_confidential"}}</label>
4444
<input type="checkbox" name="confidential" id="confidential" {{if .App.Confidential}}checked{{end}}>
45-
</div>
45+
</div>
4646
<div class="field {{if .Err_RedirectURI}}error{{end}}">
4747
<label for="redirect-uri">{{.locale.Tr "settings.oauth2_redirect_uri"}}</label>
4848
<input type="url" name="redirect_uri" value="{{.App.PrimaryRedirectURI}}" id="redirect-uri">

templates/user/settings/applications_oauth2_list.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
<label for="application-name">{{.locale.Tr "settings.oauth2_application_name"}}</label>
3434
<input id="application-name" name="application_name" value="{{.application_name}}" required>
3535
</div>
36-
<div class="field {{if .Err_Confidential}}error{{end}}">
36+
<div class="field {{if .Err_Confidential}}error{{end}}">
3737
<label for="confidential">{{.locale.Tr "settings.oauth2_confidential"}}</label>
3838
<input type="checkbox" name="confidential" id="confidential" checked>
3939
</div>

tests/integration/oauth_test.go

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,17 @@ func TestRedirectWithExistingGrant(t *testing.T) {
5454
assert.Truef(t, len(u.Query().Get("code")) > 30, "authorization code '%s' should be longer then 30", u.Query().Get("code"))
5555
}
5656

57+
func TestAuthorizePKCERequiredForPublicClient(t *testing.T) {
58+
defer tests.PrepareTestEnv(t)()
59+
req := NewRequest(t, "GET", "/login/oauth/authorize?client_id=ce5a1322-42a7-11ed-b878-0242ac120002&redirect_uri=http%3A%2F%2F127.0.0.1&response_type=code&state=thestate")
60+
ctx := loginUser(t, "user1")
61+
resp := ctx.MakeRequest(t, req, http.StatusSeeOther)
62+
u, err := resp.Result().Location()
63+
assert.NoError(t, err)
64+
assert.Equal(t, "invalid_request", u.Query().Get("error"))
65+
assert.Equal(t, "PKCE is required for public clients", u.Query().Get("error_description"))
66+
}
67+
5768
func TestAccessTokenExchange(t *testing.T) {
5869
defer tests.PrepareTestEnv(t)()
5970
req := NewRequestWithValues(t, "POST", "/login/oauth/access_token", map[string]string{
@@ -168,31 +179,6 @@ func TestAccessTokenExchangeWithInvalidCredentials(t *testing.T) {
168179
MakeRequest(t, req, http.StatusBadRequest)
169180
}
170181

171-
func TestAccessTokenExchangeForPublicClient(t *testing.T) {
172-
defer tests.PrepareTestEnv(t)()
173-
req := NewRequestWithValues(t, "POST", "/login/oauth/access_token", map[string]string{
174-
"grant_type": "authorization_code",
175-
"client_id": "ce5a1322-42a7-11ed-b878-0242ac120002",
176-
"client_secret": "4MK8Na6R55smdCY0WuCCumZ6hjRPnGY5saWVRHHjJiA=",
177-
// redirect port may vary
178-
"redirect_uri": "http://127.0.0.1:3456",
179-
"code": "authcodepublic",
180-
"code_verifier": "N1Zo9-8Rfwhkt68r1r29ty8YwIraXR8eh_1Qwxg7yQXsonBt",
181-
})
182-
MakeRequest(t, req, http.StatusOK)
183-
184-
req = NewRequestWithValues(t, "POST", "/login/oauth/access_token", map[string]string{
185-
"grant_type": "authorization_code",
186-
"client_id": "ce5a1322-42a7-11ed-b878-0242ac120002",
187-
"client_secret": "4MK8Na6R55smdCY0WuCCumZ6hjRPnGY5saWVRHHjJiA=",
188-
// redirect port may vary
189-
"redirect_uri": "http://127.0.0.1:3456",
190-
"code": "authcodepublic",
191-
// omit PKCE
192-
})
193-
MakeRequest(t, req, http.StatusBadRequest)
194-
}
195-
196182
func TestAccessTokenExchangeWithBasicAuth(t *testing.T) {
197183
defer tests.PrepareTestEnv(t)()
198184
req := NewRequestWithValues(t, "POST", "/login/oauth/access_token", map[string]string{

0 commit comments

Comments
 (0)