8000 Master PR for refactoring connections by grokys · Pull Request #1277 · github/VisualStudio · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Master PR for refactoring connections #1277

Merged
merged 43 commits into from
Nov 21, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
b790d96
ILoginCache -> IKeychain
grokys Aug 25, 2017
1c81104
Use IKeychain for credentials.
grokys Aug 25, 2017
21f888e
Updated parameter name.
grokys Aug 25, 2017
7e061d1
Removed unneeded usings.
grokys Aug 25, 2017
c8b8dd7
Updated variable names.
grokys Aug 25, 2017
95f2c0b
Remove `IObservableKeychainAdapter`.
grokys Aug 25, 2017
7b4080f
Merge branch 'master' into fixes/1176-duplicate-login-classes
grokys Aug 30, 2017
3b13736
Store "master" credential.
grokys Aug 30, 2017
a142423
Merge branch 'master' into fixes/1176-duplicate-login-classes
grokys Sep 7, 2017
bcfbd79
Fix broken merge.
grokys Sep 7, 2017
c52a261
Merge branch 'fixes/1176-duplicate-login-classes' into fixes/harden-c…
grokys Sep 7, 2017
e6c5d89
Merge branch 'master' into fixes/1176-duplicate-login-classes
grokys Oct 20, 2017
17c845e
Merge branch 'fixes/1176-duplicate-login-classes' into fixes/harden-c…
grokys Oct 20, 2017
a627271
Merge branch 'master' into refactor/connections-master
grokys Oct 20, 2017
470ea13
Removed `IConnection.Repositories`.
grokys Oct 20, 2017
d98ec51
Refactored ConnectionManager/Connection.
grokys Oct 23, 2017
aa78f03
Refactored RepositoryHost(s).
grokys Oct 23, 2017
7cf89c9
Added DebuggerDisplay back in.
grokys Oct 23, 2017
213a7fc
Moved LocalRepositories to GitHub.VisualStudio.
grokys Oct 24, 2017
90c35c5
Track login metrics.
grokys Oct 26, 2017
9db05a7
Fix failing tests.
grokys Oct 26, 2017
f854b79
WIP: Removing RepositoryHost(s)
grokys Oct 26, 2017
3240372
WIP: Still removing RepositoryHost(s)
grokys Oct 26, 2017
038f232
WIP: Removing RepositoryHost(s) from tests.
grokys Oct 26, 2017
a57a759
Finished migrating tests (I think).
grokys Oct 27, 2017
95cd0b1
Added IModelServiceFactory implemenation.
grokys Oct 27, 2017
6034643
Added IGlobalConnection.
grokys Oct 27, 2017
17aebf8
Removed ConnectionManager.ConnectionCreated.
grokys Oct 27, 2017
00232f0
Merge branch 'master' into refactor/connections-master
grokys Nov 3, 2017
01aad33
Merge branch 'refactor/connections-master' into refactor/connections/…
grokys Nov 3, 2017
217e415
Merge branch 'refactor/connections/local-repositories' into refactor/…
grokys Nov 3, 2017
7e57621
Insert AccountCacheItem for connection.
grokys Nov 7, 2017
e45d0c6
Merge branch 'master' into refactor/connections-master
grokys Nov 7, 2017
8f6d218
Merge branch 'refactor/connections-master' into refactor/connections/…
grokys Nov 7, 2017
32f073a
Merge branch 'refactor/connections/local-repositories' into refactor/…
grokys Nov 7, 2017
9f15db6
Merge branch 'refactor/connection-manager' into refactor/connections/…
grokys Nov 7, 2017
cd546bb
Fix CA errors.
grokys Nov 7, 2017
def6070
Merge pull request #1283 from github/refactor/connections/remove-repo…
grokys Nov 8, 2017
fc57163
Merge branch 'master' into refactor/connections-master
grokys Nov 8, 2017
d9c2a2f
Removed empty file.
grokys Nov 8, 2017
cefd4b9
Merge branch 'master' into refactor/connections-master
grokys Nov 14, 2017
7d7b188
Merge branch 'master' into refactor/connections-master
grokys Nov 20, 2017
4701dd0
Merge branch 'master' into refactor/connections-master
grokys Nov 20, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
ILoginCache -> IKeychain
  • Loading branch information
grokys committed Aug 25, 2017
commit b790d965c9ab27a1fc49b8b42e6fe2f390c2630f
18 changes: 9 additions & 9 deletions src/GitHub.Api/ILoginCache.cs → src/GitHub.Api/IKeychain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,33 @@
namespace GitHub.Api
{
/// <summary>
/// Stores login details.
/// Represents a keychain used to store credentials.
/// </summary>
public interface ILoginCache
public interface IKeychain
{
/// <summary>
/// Gets the login details for the specified host address.
/// Loads the credentials for the specified host address.
/// </summary>
/// <param name="hostAddress">The host address.</param>
/// <returns>
/// A task returning a tuple containing the retrieved username and password.
/// A task returning a tuple consisting of the retrieved username and password.
/// </returns>
Task<Tuple<string, string>> GetLogin(HostAddress hostAddress);
Task<Tuple<string, string>> Load(HostAddress hostAddress);

/// <summary>
/// Saves the login details for the specified host address.
/// Saves the credentials for the specified host address.
/// </summary>
/// <param name="userName">The username.</param>
/// <param name="password">The password.</param>
/// <param name="hostAddress">The host address.</param>
/// <returns>A task tracking the operation.</returns>
Task SaveLogin(string userName, string password, HostAddress hostAddress);
Task Save(string userName, string password, HostAddress hostAddress);

/// <summary>
/// Removes the login details for the specified host address.
/// Deletes the login details for the specified host address.
/// </summary>
/// <param name="hostAddress"></param>
/// <returns>A task tracking the operation.</returns>
Task EraseLogin(HostAddress hostAddress);
Task Delete(HostAddress hostAddress);
}
}
14 changes: 7 additions & 7 deletions src/GitHub.Api/LoginManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace GitHub.Api
public class LoginManager : ILoginManager
{
readonly string[] scopes = { "user", "repo", "gist", "write:public_key" };
readonly ILoginCache loginCache;
readonly IKeychain loginCache;
readonly ITwoFactorChallengeHandler twoFactorChallengeHandler;
readonly string clientId;
readonly string clientSecret;
Expand All @@ -30,7 +30,7 @@ public class LoginManager : ILoginManager
/// <param name="authorizationNote">An note to store with the authorization.</param>
/// <param name="fingerprint">The machine fingerprint.</param>
public LoginManager(
ILoginCache loginCache,
IKeychain loginCache,
ITwoFactorChallengeHandler twoFactorChallengeHandler,
string clientId,
string clientSecret,
Expand Down Expand Up @@ -64,7 +64,7 @@ public async Task<User> Login(

// Start by saving the username and password, these will be used by the `IGitHubClient`
// until an authorization token has been created and acquired:
await loginCache.SaveLogin(userName, password, hostAddress).ConfigureAwait(false);
await loginCache.Save(userName, password, hostAddress).ConfigureAwait(false);

var newAuth = new NewAuthorization
{
Expand Down Expand Up @@ -99,13 +99,13 @@ public async Task<User> Login(
}
else
{
await loginCache.EraseLogin(hostAddress).ConfigureAwait(false);
await loginCache.Delete(hostAddress).ConfigureAwait(false);
throw;
}
}
} while (auth == null);

await loginCache.SaveLogin(userName, auth.Token, hostAddress).ConfigureAwait(false);
await loginCache.Save(userName, auth.Token, hostAddress).ConfigureAwait(false);

var retry = 0;

Expand Down Expand Up @@ -141,7 +141,7 @@ public async Task Logout(HostAddress hostAddress, IGitHubClient client)
Guard.ArgumentNotNull(hostAddress, nameof(hostAddress));
Guard.ArgumentNotNull(client, nameof(client));

await loginCache.EraseLogin(hostAddress);
await loginCache.Delete(hostAddress);
}

async Task<ApplicationAuthorization> CreateAndDeleteExistingApplicationAuthorization(
Expand Down Expand Up @@ -219,7 +219,7 @@ async Task<ApplicationAuthorization> HandleTwoFactorAuthorization(
catch (Exception e)
{
await twoFactorChallengeHandler.ChallengeFailed(e);
await loginCache.EraseLogin(hostAddress).ConfigureAwait(false);
await loginCache.Delete(hostAddress).ConfigureAwait(false);
throw;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
namespace GitHub.Api
{
/// <summary>
/// A login cache that stores logins in the windows credential cache.
/// A keychain that stores logins in the windows credential store.
/// </summary>
[Export(typeof(ILoginCache))]
[Export(typeof(IKeychain))]
[PartCreationPolicy(CreationPolicy.Shared)]
public class WindowsLoginCache : ILoginCache
public class WindowsKeychain : IKeychain
{
/// <inheritdoc/>
public Task<Tuple<string, string>> GetLogin(HostAddress hostAddress)
public Task<Tuple<string, string>> Load(HostAddress hostAddress)
{
Guard.ArgumentNotNull(hostAddress, nameof(hostAddress));

Expand All @@ -33,7 +33,7 @@ public Task<Tuple<string, string>> GetLogin(HostAddress hostAddress)
}

/// <inheritdoc/>
public Task SaveLogin(string userName, string password, HostAddress hostAddress)
public Task Save(string userName, string password, HostAddress hostAddress)
{
Guard.ArgumentNotEmptyString(userName, nameof(userName));
Guard.ArgumentNotEmptyString(password, nameof(password));
Expand All @@ -56,7 +56,7 @@ public Task SaveLogin(string userName, string password, HostAddress hostAddress)
}

/// <inheritdoc/>
public Task EraseLogin(HostAddress hostAddress)
public Task Delete(HostAddress hostAddress)
{
Guard.ArgumentNotNull(hostAddress, nameof(hostAddress));

Expand Down
34 changes: 17 additions & 17 deletions src/UnitTests/GitHub.Api/LoginManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ public async Task LoginTokenIsSavedToCache()
client.Authorization.GetOrCreateApplicationAuthentication("id", "secret", Arg.Any<NewAuthorization>())
.Returns(new ApplicationAuthorization("123abc"));

var loginCache = Substitute.For<ILoginCache>();
var loginCache = Substitute.For<IKeychain>();
var tfa = Substitute.For<ITwoFactorChallengeHandler>();

var target = new LoginManager(loginCache, tfa, "id", "secret");
await target.Login(host, client, "foo", "bar");

await loginCache.Received().SaveLogin("foo", "123abc", host);
await loginCache.Received().Save("foo", "123abc", host);
}

[Fact]
Expand All @@ -39,7 +39,7 @@ public async Task LoggedInUserIsReturned()
.Returns(new ApplicationAuthorization("123abc"));
client.User.Current().Returns(user);

var loginCache = Substitute.For<ILoginCache>();
var loginCache = Substitute.For<IKeychain>();
var tfa = Substitute.For<ITwoFactorChallengeHandler>();

var target = new LoginManager(loginCache, tfa, "id", "secret");
Expand All @@ -62,15 +62,15 @@ public async Task DeletesExistingAuthenticationIfNullTokenReturned()
new ApplicationAuthorization("123abc"));
client.User.Current().Returns(user);

var loginCache = Substitute.For<ILoginCache>();
var loginCache = Substitute.For<IKeychain>();
var tfa = Substitute.For<ITwoFactorChallengeHandler>();

var target = new LoginManager(loginCache, tfa, "id", "secret");
var result = await target.Login(host, client, "foo", "bar");

await client.Authorization.Received(2).GetOrCreateApplicationAuthentication("id", "secret", Arg.Any<NewAuthorization>());
await client.Authorization.Received(1).Delete(0);
await loginCache.Received().SaveLogin("foo", "123abc", host);
await loginCache.Received().Save("foo", "123abc", host);
}

[Fact]
Expand All @@ -84,7 +84,7 @@ public async Task TwoFactorExceptionIsPassedToHandler()
client.Authorization.GetOrCreateApplicationAuthentication("id", "secret", Arg.Any<NewAuthorization>(), "123456")
.Returns(new ApplicationAuthorization("123abc"));

var loginCache = Substitute.For<ILoginCache>();
var loginCache = Substitute.For<IKeychain>();
var tfa = Substitute.For<ITwoFactorChallengeHandler>();
tfa.HandleTwoFactorException(exception).Returns(new TwoFactorChallengeResult("123456"));

Expand All @@ -111,7 +111,7 @@ public async Task Failed2FACodeResultsInRetry()
client.Authorization.GetOrCreateApplicationAuthentication("id", "secret", Arg.Any<NewAuthorization>(), "123456")
.Returns(new ApplicationAuthorization("123abc"));

var loginCache = Substitute.For<ILoginCache>();
var loginCache = Substitute.For<IKeychain>();
var tfa = Substitute.For<ITwoFactorChallengeHandler>();
tfa.HandleTwoFactorException(exception).Returns(
new TwoFactorChallengeResult("111111"),
Expand Down Expand Up @@ -146,7 +146,7 @@ public async Task HandlerNotifiedOfExceptionIn2FAChallengeResponse()
client.Authorization.GetOrCreateApplicationAuthentication("id", "secret", Arg.Any<NewAuthorization>(), "111111")
.Returns<ApplicationAuthorization>(_ => { throw loginAttemptsException; });

var loginCache = Substitute.For<ILoginCache>();
var loginCache = Substitute.For<IKeychain>();
var tfa = Substitute.For<ITwoFactorChallengeHandler>();
tfa.HandleTwoFactorException(twoFaException).Returns(
new TwoFactorChallengeResult("111111"),
Expand Down Expand Up @@ -176,7 +176,7 @@ public async Task RequestResendCodeResultsInRetryingLogin()
.Returns(new ApplicationAuthorization("456def"));
client.User.Current().Returns(user);

var loginCache = Substitute.For<ILoginCache>();
var loginCache = Substitute.For<IKeychain>();
var tfa = Substitute.For<ITwoFactorChallengeHandler>();
tfa.HandleTwoFactorException(exception).Returns(
TwoFactorChallengeResult.RequestResendCode,
Expand All @@ -201,13 +201,13 @@ public async Task UsesUsernameAndPasswordInsteadOfAuthorizationTokenWhenEnterpri
});
client.User.Current().Returns(user);

var loginCache = Substitute.For<ILoginCache>();
var loginCache = Substitute.For<IKeychain>();
var tfa = Substitute.For<ITwoFactorChallengeHandler>();

var target = new LoginManager(loginCache, tfa, "id", "secret");
await target.Login(enterprise, client, "foo", "bar");

await loginCache.Received().SaveLogin("foo", "bar", enterprise);
await loginCache.Received().Save("foo", "bar", enterprise);
}

[Fact]
Expand All @@ -219,13 +219,13 @@ public async Task ErasesLoginWhenUnauthorized()
client.Authorization.GetOrCreateApplicationAuthentication("id", "secret", Arg.Any<NewAuthorization>())
.Returns<ApplicationAuthorization>(_ => { throw new AuthorizationException(); });

var loginCache = Substitute.For<ILoginCache>();
var loginCache = Substitute.For<IKeychain>();
var tfa = Substitute.For<ITwoFactorChallengeHandler>();

var target = new LoginManager(loginCache, tfa, "id", "secret");
await Assert.ThrowsAsync<AuthorizationException>(async () => await target.Login(enterprise, client, "foo", "bar"));

await loginCache.Received().EraseLogin(enterprise);
await loginCache.Received().Delete(enterprise);
}

[Fact]
Expand All @@ -237,13 +237,13 @@ public async Task ErasesLoginWhenNonOctokitExceptionThrown()
client.Authorization.GetOrCreateApplicationAuthentication("id", "secret", Arg.Any<NewAuthorization>())
.Returns<ApplicationAuthorization>(_ => { throw new InvalidOperationException(); });

var loginCache = Substitute.For<ILoginCache>();
var loginCache = Substitute.For<IKeychain>();
var tfa = Substitute.For<ITwoFactorChallengeHandler>();

var target = new LoginManager(loginCache, tfa, "id", "secret");
await Assert.ThrowsAsync<InvalidOperationException>(async () => await target.Login(host, client, "foo", "bar"));

await loginCache.Received().EraseLogin(host);
await loginCache.Received().Delete(host);
}

[Fact]
Expand All @@ -259,14 +259,14 @@ public async Task ErasesLoginWhenNonOctokitExceptionThrownIn2FA()
.Returns<ApplicationAuthorization>(_ => { throw new InvalidOperationException(); });
client.User.Current().Returns(user);

var loginCache = Substitute.For<ILoginCache>();
var loginCache = Substitute.For<IKeychain>();
var tfa = Substitute.For<ITwoFactorChallengeHandler>();
tfa.HandleTwoFactorException(exception).Returns(new TwoFactorChallengeResult("123456"));

var target = new LoginManager(loginCache, tfa, "id", "secret");
await Assert.ThrowsAsync<InvalidOperationException>(async () => await target.Login(host, client, "foo", "bar"));

await loginCache.Received().EraseLogin(host);
await loginCache.Received().Delete(host);
}
}
}
0