-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Expand file tree
/
Copy pathOAuth2SystemWebBrowserTests.cs
More file actions
66 lines (57 loc) · 2.67 KB
/
OAuth2SystemWebBrowserTests.cs
File metadata and controls
66 lines (57 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using System;
using GitCredentialManager.Authentication.OAuth;
using GitCredentialManager.Tests.Objects;
using Xunit;
namespace GitCredentialManager.Tests.Authentication;
public class OAuth2SystemWebBrowserTests
{
[Fact]
public void OAuth2SystemWebBrowser_UpdateRedirectUri_NonLoopback_ThrowsError()
{
var sm = new TestSessionManager();
var options = new OAuth2WebBrowserOptions();
var browser = new OAuth2SystemWebBrowser(sm, options);
Assert.Throws<ArgumentException>(() => browser.UpdateRedirectUri(new Uri("http://example.com")));
}
[Theory]
[InlineData("http://localhost:1234", "http://localhost:1234")]
[InlineData("http://localhost:1234/", "http://localhost:1234/")]
[InlineData("http://localhost:1234/oauth-callback", "http://localhost:1234/oauth-callback")]
[InlineData("http://localhost:1234/oauth-callback/", "http://localhost:1234/oauth-callback/")]
[InlineData("http://127.0.0.7:1234", "http://127.0.0.7:1234")]
[InlineData("http://127.0.0.7:1234/", "http://127.0.0.7:1234/")]
[InlineData("http://127.0.0.7:1234/oauth-callback", "http://127.0.0.7:1234/oauth-callback")]
[InlineData("http://127.0.0.7:1234/oauth-callback/", "http://127.0.0.7:1234/oauth-callback/")]
public void OAuth2SystemWebBrowser_UpdateRedirectUri_SpecificPort(string input, string expected)
{
var sm = new TestSessionManager();
var options = new OAuth2WebBrowserOptions();
var browser = new OAuth2SystemWebBrowser(sm, options);
Uri actualUri = browser.UpdateRedirectUri(new Uri(input));
Assert.Equal(expected, actualUri.OriginalString);
}
[Theory]
[InlineData("http://localhost")]
[InlineData("http://localhost/")]
[InlineData("http://localhost/oauth-callback")]
[InlineData("http://localhost/oauth-callback/")]
[InlineData("http://127.0.0.7")]
[InlineData("http://127.0.0.7/")]
[InlineData("http://127.0.0.7/oauth-callback")]
[InlineData("http://127.0.0.7/oauth-callback/")]
public void OAuth2SystemWebBrowser_UpdateRedirectUri_AnyPort(string input)
{
var sm = new TestSessionManager();
var options = new OAuth2WebBrowserOptions();
var browser = new OAuth2SystemWebBrowser(sm, options);
var inputUri = new Uri(input);
Uri actualUri = browser.UpdateRedirectUri(inputUri);
Assert.Equal(inputUri.Scheme, actualUri.Scheme);
Assert.Equal(inputUri.Host, actualUri.Host);
Assert.Equal(
inputUri.GetComponents(UriComponents.Path, UriFormat.Unescaped),
actualUri.GetComponents(UriComponents.Path, UriFormat.Unescaped)
);
Assert.False(actualUri.IsDefaultPort);
}
}