This repository was archived by the owner on Jul 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 619
Expand file tree
/
Copy pathAuthenticationTests.cs
More file actions
56 lines (49 loc) · 2.41 KB
/
AuthenticationTests.cs
File metadata and controls
56 lines (49 loc) · 2.41 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
using GitHub.Authentication.Test.Fakes;
using Microsoft.Alm.Authentication;
using System;
using System.Threading.Tasks;
using Xunit;
namespace GitHub.Authentication.Test
{
public class AuthenticationTests
{
[Theory]
[InlineData("https://github.com/", "https://github.com/")]
[InlineData("https://gist.github.com/", "https://gist.github.com/")]
[InlineData("https://github.com/", "https://gist.github.com/")]
public async Task GetSetCredentialsNormalizesGistUrls(string writeUriString, string retrieveUriString)
{
var retrieveUri = new Uri(retrieveUriString);
var credentialStore = new InMemoryCredentialStore();
var prompts = new AuthenticationPrompts(RuntimeContext.Default, IntPtr.Zero);
var authentication = new Authentication(
RuntimeContext.Default,
new Uri(writeUriString),
TokenScope.Gist,
credentialStore,
new Authentication.AcquireCredentialsDelegate(prompts.CredentialModalPrompt),
new Authentication.AcquireAuthenticationCodeDelegate(prompts.AuthenticationCodeModalPrompt),
null);
await authentication.SetCredentials(new Uri(writeUriString), new Credential("haacked", string.Empty));
var credentials = await authentication.GetCredentials(retrieveUri);
Assert.Equal("haacked", credentials.Username);
}
[Fact]
public async Task GetSetCredentialsDoesNotReturnCredentialForRandomUrl()
{
var retrieveUri = new Uri("https://example.com/");
var credentialStore = new InMemoryCredentialStore();
var prompts = new AuthenticationPrompts(RuntimeContext.Default, IntPtr.Zero);
var authentication = new Authentication(
RuntimeContext.Default,
new Uri("https://github.com/"),
TokenScope.Gist,
credentialStore,
new Authentication.AcquireCredentialsDelegate(prompts.CredentialModalPrompt),
new Authentication.AcquireAuthenticationCodeDelegate(prompts.AuthenticationCodeModalPrompt),
null);
await authentication.SetCredentials(new Uri("https://github.com/"), new Credential("haacked", string.Empty));
Assert.Null(await authentication.GetCredentials(retrieveUri));
}
}
}