Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure we honor credentials namespace/scope #104

Merged
merged 1 commit into from
May 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 1 addition & 2 deletions src/CredentialManager/CredentialManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ public static class CredentialManager
/// <returns>The <see cref="ICredentialStore"/>.</returns>
public static ICredentialStore Create(string? @namespace = default)
{
using var context = new CommandContextWrapper(new CommandContext(), @namespace);
// The context already does the check for the platform and configured store to initialize.
// By overriding the settings with our wrapper, we ensure just the namespace is overriden.
return context.CredentialStore;
return new CredentialStore(new CommandContextWrapper(new CommandContext(), @namespace));
}

class CommandContextWrapper(CommandContext context, string? @namespace) : ICommandContext
Expand Down
18 changes: 18 additions & 0 deletions src/Tests/EndToEnd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,24 @@ public void LinuxSecretService()
Run();
}

[WindowsFact]
public void SavedOneNamespaceCannotRetrieveAnother()
{
var ns1 = Guid.NewGuid().ToString("N");
var ns2 = Guid.NewGuid().ToString("N");

var store1 = CredentialManager.Create(ns1);
var store2 = CredentialManager.Create(ns2);

var usr = Guid.NewGuid().ToString("N");
var pwd = Guid.NewGuid().ToString("N");

store1.AddOrUpdate("https://test.com", usr, pwd);

Assert.Null(store2.Get("https://test.com", usr));
Assert.Empty(store2.GetAccounts("https://test.com"));
}

void Run()
{
var store = CredentialManager.Create(Guid.NewGuid().ToString("N"));
Expand Down
Loading