-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Note that in 6.1, IsLocalUrl got copied into the EF package
- Loading branch information
1 parent
5e69ed0
commit 4a861f2
Showing
3 changed files
with
80 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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 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,62 @@ | ||
using System.Collections.Generic; | ||
using FluentAssertions; | ||
using Xunit; | ||
using Duende.IdentityServer.EntityFramework.Extensions; | ||
|
||
namespace UnitTests.Validation; | ||
|
||
public class IsLocalUrlTests | ||
{ | ||
private const string queryParameters = "?client_id=mvc.code" + | ||
"&redirect_uri=https%3A%2F%2Flocalhost%3A44302%2Fsignin-oidc" + | ||
"&response_type=code" + | ||
"&scope=openid%20profile%20email%20custom.profile%20resource1.scope1%20resource2.scope1%20offline_access" + | ||
"&code_challenge=LcJN1shWmezC0J5EU7QOi7N_amBuvMDb6PcTY0sB2YY" + | ||
"&code_challenge_method=S256" + | ||
"&response_mode=form_post" + | ||
"&nonce=nonce" + | ||
"&state=state"; | ||
|
||
public static IEnumerable<object[]> TestCases => | ||
new List<object[]> | ||
{ | ||
new object[] { "/connect/authorize/callback" + queryParameters, true }, | ||
new object[] { "//evil.com/" + queryParameters, false }, | ||
// Tab character | ||
new object[] { "/\t/evil.com/connect/authorize/callback" + queryParameters, false }, | ||
// Tabs and Spaces | ||
new object[] { "/ \t/evil.com/connect/authorize/callback" + queryParameters, false }, | ||
new object[] { "/ \t/evil.com/connect/authorize/callback" + queryParameters, false }, | ||
new object[] { "/ \t/evil.com/connect/authorize/callback" + queryParameters, false }, | ||
new object[] { "/\t /evil.com/connect/authorize/callback" + queryParameters, false }, | ||
new object[] { "/\t /evil.com/connect/authorize/callback" + queryParameters, false }, | ||
new object[] { "/\t /evil.com/connect/authorize/callback" + queryParameters, false }, | ||
// Various new line related things | ||
new object[] { "/\n/evil.com/" + queryParameters, false }, | ||
new object[] { "/\n\n/evil.com/" + queryParameters, false }, | ||
new object[] { "/\r/evil.com/" + queryParameters, false }, | ||
new object[] { "/\r\r/evil.com/" + queryParameters, false }, | ||
new object[] { "/\r\n/evil.com/" + queryParameters, false }, | ||
new object[] { "/\r\n\r\n/evil.com/" + queryParameters, false }, | ||
// Tabs and Newlines | ||
new object[] { "/\t\n/evil.com/" + queryParameters, false }, | ||
new object[] { "/\t\n\n/evil.com/" + queryParameters, false }, | ||
new object[] { "/\t\r/evil.com/" + queryParameters, false }, | ||
new object[] { "/\t\r\r/evil.com/" + queryParameters, false }, | ||
new object[] { "/\t\r\n/evil.com/" + queryParameters, false }, | ||
new object[] { "/\t\r\n\r\n/evil.com/" + queryParameters, false }, | ||
new object[] { "/\n/evil.com\t/" + queryParameters, false }, | ||
new object[] { "/\n\n/evil.com\t/" + queryParameters, false }, | ||
new object[] { "/\r/evil.com\t/" + queryParameters, false }, | ||
new object[] { "/\r\r/evil.com\t/" + queryParameters, false }, | ||
new object[] { "/\r\n/evil.com\t/" + queryParameters, false }, | ||
new object[] { "/\r\n\r\n/evil.com\t/" + queryParameters, false }, | ||
}; | ||
|
||
[Theory] | ||
[MemberData(nameof(TestCases))] | ||
public void IsLocalUrl(string returnUrl, bool expected) | ||
{ | ||
returnUrl.IsLocalUrl().Should().Be(expected); | ||
} | ||
} |
This file contains 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