Skip to content

Commit 7ca0ecb

Browse files
committed
Make sure we honor credentials namespace/scope
A missing test uncovers the issue: we're not filtering credentials at all and are instead just defaulting to the 'git' default namespace. We ensure now that the credential store uses our context and settings wrappers to override this value. Fixes #103
1 parent eaf384a commit 7ca0ecb

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/CredentialManager/CredentialManager.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@ public static class CredentialManager
2222
/// <returns>The <see cref="ICredentialStore"/>.</returns>
2323
public static ICredentialStore Create(string? @namespace = default)
2424
{
25-
using var context = new CommandContextWrapper(new CommandContext(), @namespace);
2625
// The context already does the check for the platform and configured store to initialize.
2726
// By overriding the settings with our wrapper, we ensure just the namespace is overriden.
28-
return context.CredentialStore;
27+
return new CredentialStore(new CommandContextWrapper(new CommandContext(), @namespace));
2928
}
3029

3130
class CommandContextWrapper(CommandContext context, string? @namespace) : ICommandContext

src/Tests/EndToEnd.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,24 @@ public void LinuxSecretService()
5656
Run();
5757
}
5858

59+
[WindowsFact]
60+
public void SavedOneNamespaceCannotRetrieveAnother()
61+
{
62+
var ns1 = Guid.NewGuid().ToString("N");
63+
var ns2 = Guid.NewGuid().ToString("N");
64+
65+
var store1 = CredentialManager.Create(ns1);
66+
var store2 = CredentialManager.Create(ns2);
67+
68+
var usr = Guid.NewGuid().ToString("N");
69+
var pwd = Guid.NewGuid().ToString("N");
70+
71+
store1.AddOrUpdate("https://test.com", usr, pwd);
72+
73+
Assert.Null(store2.Get("https://test.com", usr));
74+
Assert.Empty(store2.GetAccounts("https://test.com"));
75+
}
76+
5977
void Run()
6078
{
6179
var store = CredentialManager.Create(Guid.NewGuid().ToString("N"));

0 commit comments

Comments
 (0)