Skip to content

Commit 88e1297

Browse files
committed
wincred: add tests for namespace matching of creds
1 parent de7b93b commit 88e1297

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

src/shared/Core.Tests/Interop/Windows/WindowsCredentialManagerTests.cs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,70 @@ public void WindowsCredentialManager_IsMatch(
270270
Assert.Equal(expected, actual);
271271
}
272272

273+
[PlatformFact(Platforms.Windows)]
274+
public void WindowsCredentialManager_IsMatch_NoNamespace_NotMatched()
275+
{
276+
var win32Cred = new Win32Credential
277+
{
278+
UserName = "test",
279+
TargetName = $"{WindowsCredentialManager.TargetNameLegacyGenericPrefix}https://example.com"
280+
};
281+
282+
var credManager = new WindowsCredentialManager(TestNamespace);
283+
284+
bool result = credManager.IsMatch("https://example.com", null, win32Cred);
285+
286+
Assert.False(result);
287+
}
288+
289+
[PlatformFact(Platforms.Windows)]
290+
public void WindowsCredentialManager_IsMatch_DifferentNamespace_NotMatched()
291+
{
292+
var win32Cred = new Win32Credential
293+
{
294+
UserName = "test",
295+
TargetName = $"{WindowsCredentialManager.TargetNameLegacyGenericPrefix}:random-namespace:https://example.com"
296+
};
297+
298+
var credManager = new WindowsCredentialManager(TestNamespace);
299+
300+
bool result = credManager.IsMatch("https://example.com", null, win32Cred);
301+
302+
Assert.False(result);
303+
}
304+
305+
[PlatformFact(Platforms.Windows)]
306+
public void WindowsCredentialManager_IsMatch_CaseSensitiveNamespace_NotMatched()
307+
{
308+
var win32Cred = new Win32Credential
309+
{
310+
UserName = "test",
311+
TargetName = $"{WindowsCredentialManager.TargetNameLegacyGenericPrefix}:nAmEsPaCe:https://example.com"
312+
};
313+
314+
var credManager = new WindowsCredentialManager("namespace");
315+
316+
bool result = credManager.IsMatch("https://example.com", null, win32Cred);
317+
318+
Assert.False(result);
319+
}
320+
321+
[PlatformFact(Platforms.Windows)]
322+
public void WindowsCredentialManager_IsMatch_NoNamespaceInQuery_IsMatched()
323+
{
324+
var win32Cred = new Win32Credential
325+
{
326+
UserName = "test",
327+
TargetName = $"{WindowsCredentialManager.TargetNameLegacyGenericPrefix}https://example.com"
328+
};
329+
330+
var credManager = new WindowsCredentialManager();
331+
332+
bool result = credManager.IsMatch("https://example.com", null, win32Cred);
333+
334+
Assert.True(result);
335+
}
336+
273337
[PlatformTheory(Platforms.Windows)]
274338
[InlineData("https://example.com", null, "https://example.com")]
275339
[InlineData("https://example.com", "bob", "https://[email protected]")]

0 commit comments

Comments
 (0)