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

Only match credential entries with correct namespace in the Windows Credential Manager #1328

Merged
merged 2 commits into from
Jul 12, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
wincred: add tests for namespace matching of creds
  • Loading branch information
mjcheetham committed Jul 12, 2023
commit 88e1297d855362c74e50d71ddd8d1b2f05aaefc9
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,70 @@ public void WindowsCredentialManager_IsMatch(
Assert.Equal(expected, actual);
}

[PlatformFact(Platforms.Windows)]
public void WindowsCredentialManager_IsMatch_NoNamespace_NotMatched()
{
var win32Cred = new Win32Credential
{
UserName = "test",
TargetName = $"{WindowsCredentialManager.TargetNameLegacyGenericPrefix}https://example.com"
};

var credManager = new WindowsCredentialManager(TestNamespace);

bool result = credManager.IsMatch("https://example.com", null, win32Cred);

Assert.False(result);
}

[PlatformFact(Platforms.Windows)]
public void WindowsCredentialManager_IsMatch_DifferentNamespace_NotMatched()
{
var win32Cred = new Win32Credential
{
UserName = "test",
TargetName = $"{WindowsCredentialManager.TargetNameLegacyGenericPrefix}:random-namespace:https://example.com"
};

var credManager = new WindowsCredentialManager(TestNamespace);

bool result = credManager.IsMatch("https://example.com", null, win32Cred);

Assert.False(result);
}

[PlatformFact(Platforms.Windows)]
public void WindowsCredentialManager_IsMatch_CaseSensitiveNamespace_NotMatched()
{
var win32Cred = new Win32Credential
{
UserName = "test",
TargetName = $"{WindowsCredentialManager.TargetNameLegacyGenericPrefix}:nAmEsPaCe:https://example.com"
};

var credManager = new WindowsCredentialManager("namespace");

bool result = credManager.IsMatch("https://example.com", null, win32Cred);

Assert.False(result);
}

[PlatformFact(Platforms.Windows)]
public void WindowsCredentialManager_IsMatch_NoNamespaceInQuery_IsMatched()
{
var win32Cred = new Win32Credential
{
UserName = "test",
TargetName = $"{WindowsCredentialManager.TargetNameLegacyGenericPrefix}https://example.com"
};

var credManager = new WindowsCredentialManager();

bool result = credManager.IsMatch("https://example.com", null, win32Cred);

Assert.True(result);
}

[PlatformTheory(Platforms.Windows)]
[InlineData("https://example.com", null, "https://example.com")]
[InlineData("https://example.com", "bob", "https://bob@example.com")]
Expand Down