Skip to content

Commit

Permalink
wincred: add tests for namespace matching of creds
Browse files Browse the repository at this point in the history
  • Loading branch information
mjcheetham committed Jul 12, 2023
1 parent de7b93b commit 88e1297
Showing 1 changed file with 64 additions and 0 deletions.
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://[email protected]")]
Expand Down

0 comments on commit 88e1297

Please sign in to comment.