-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Validate OAuth Redirect URIs #32643
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Validate OAuth Redirect URIs #32643
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
a814efc
fix: validate RedirectURIs when saving an Oauth2 Application
bohde 6ce43ab
test: avoid loading fixtures in user settings tests
bohde 6c2ae7f
test: add tests to verify that invalid redirects result in an error m…
bohde 3fbfdb2
fix: remove TODO
bohde 1bdfb94
fix: update for main
bohde ce4145f
test: add missing PrintCurrentTest
bohde 57958d2
fix wrong binding declaration
bohde e536a9d
add unit tests and fix failing cases
bohde 17b4c93
Merge branch 'main' into rb/validate-redirect-uri
lunny 2861557
standardize on using == for checking validation rules
bohde 3344494
Merge branch 'main' into rb/validate-redirect-uri
GiteaBot 24f5331
Merge branch 'main' into rb/validate-redirect-uri
GiteaBot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
// Copyright 2024 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package validation | ||
|
||
import ( | ||
"testing" | ||
|
||
"gitea.com/go-chi/binding" | ||
) | ||
|
||
// This is a copy of all the URL tests cases, plus additional ones to | ||
// account for multiple URLs | ||
var urlListValidationTestCases = []validationTestCase{ | ||
{ | ||
description: "Empty URL", | ||
data: TestForm{ | ||
URLs: "", | ||
}, | ||
expectedErrors: binding.Errors{}, | ||
}, | ||
{ | ||
description: "URL without port", | ||
data: TestForm{ | ||
URLs: "http://test.lan/", | ||
}, | ||
expectedErrors: binding.Errors{}, | ||
}, | ||
{ | ||
description: "URL with port", | ||
data: TestForm{ | ||
URLs: "http://test.lan:3000/", | ||
}, | ||
expectedErrors: binding.Errors{}, | ||
}, | ||
{ | ||
description: "URL with IPv6 address without port", | ||
data: TestForm{ | ||
URLs: "http://[::1]/", | ||
}, | ||
expectedErrors: binding.Errors{}, | ||
}, | ||
{ | ||
description: "URL with IPv6 address with port", | ||
data: TestForm{ | ||
URLs: "http://[::1]:3000/", | ||
}, | ||
expectedErrors: binding.Errors{}, | ||
}, | ||
{ | ||
description: "Invalid URL", | ||
data: TestForm{ | ||
URLs: "http//test.lan/", | ||
}, | ||
expectedErrors: binding.Errors{ | ||
binding.Error{ | ||
FieldNames: []string{"URLs"}, | ||
Classification: binding.ERR_URL, | ||
Message: "http//test.lan/", | ||
}, | ||
}, | ||
}, | ||
{ | ||
description: "Invalid schema", | ||
data: TestForm{ | ||
URLs: "ftp://test.lan/", | ||
}, | ||
expectedErrors: binding.Errors{ | ||
binding.Error{ | ||
FieldNames: []string{"URLs"}, | ||
Classification: binding.ERR_URL, | ||
Message: "ftp://test.lan/", | ||
}, | ||
}, | ||
}, | ||
{ | ||
description: "Invalid port", | ||
data: TestForm{ | ||
URLs: "http://test.lan:3x4/", | ||
}, | ||
expectedErrors: binding.Errors{ | ||
binding.Error{ | ||
FieldNames: []string{"URLs"}, | ||
Classification: binding.ERR_URL, | ||
Message: "http://test.lan:3x4/", | ||
}, | ||
}, | ||
}, | ||
{ | ||
description: "Invalid port with IPv6 address", | ||
data: TestForm{ | ||
URLs: "http://[::1]:3x4/", | ||
}, | ||
expectedErrors: binding.Errors{ | ||
binding.Error{ | ||
FieldNames: []string{"URLs"}, | ||
Classification: binding.ERR_URL, | ||
Message: "http://[::1]:3x4/", | ||
}, | ||
}, | ||
}, | ||
{ | ||
description: "Multi URLs", | ||
data: TestForm{ | ||
URLs: "http://test.lan:3000/\nhttp://test.local/", | ||
}, | ||
expectedErrors: binding.Errors{}, | ||
}, | ||
{ | ||
description: "Multi URLs with newline", | ||
data: TestForm{ | ||
URLs: "http://test.lan:3000/\nhttp://test.local/\n", | ||
}, | ||
expectedErrors: binding.Errors{}, | ||
}, | ||
{ | ||
description: "List with invalid entry", | ||
data: TestForm{ | ||
URLs: "http://test.lan:3000/\nhttp://[::1]:3x4/", | ||
}, | ||
expectedErrors: binding.Errors{ | ||
binding.Error{ | ||
FieldNames: []string{"URLs"}, | ||
Classification: binding.ERR_URL, | ||
Message: "http://[::1]:3x4/", | ||
}, | ||
}, | ||
}, | ||
{ | ||
description: "List with two invalid entries", | ||
data: TestForm{ | ||
URLs: "ftp://test.lan:3000/\nhttp://[::1]:3x4/\n", | ||
}, | ||
expectedErrors: binding.Errors{ | ||
binding.Error{ | ||
FieldNames: []string{"URLs"}, | ||
Classification: binding.ERR_URL, | ||
Message: "ftp://test.lan:3000/", | ||
}, | ||
binding.Error{ | ||
FieldNames: []string{"URLs"}, | ||
Classification: binding.ERR_URL, | ||
Message: "http://[::1]:3x4/", | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
func Test_ValidURLListValidation(t *testing.T) { | ||
AddBindingRules() | ||
|
||
for _, testCase := range urlListValidationTestCases { | ||
t.Run(testCase.description, func(t *testing.T) { | ||
performValidationTest(t, testCase) | ||
}) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.