|
1 | 1 | using System;
|
2 | 2 | using Xunit;
|
3 | 3 | using GitCredentialManager.Interop.Windows;
|
| 4 | +using GitCredentialManager.Interop.Windows.Native; |
4 | 5 |
|
5 | 6 | namespace GitCredentialManager.Tests.Interop.Windows
|
6 | 7 | {
|
@@ -233,5 +234,75 @@ public void WindowsCredentialManager_RemoveUriUserInfo(string input, string expe
|
233 | 234 | string actual = WindowsCredentialManager.RemoveUriUserInfo(input);
|
234 | 235 | Assert.Equal(expected, actual);
|
235 | 236 | }
|
| 237 | + |
| 238 | + [PlatformTheory(Platforms.Windows)] |
| 239 | + [InlineData("https://example.com", null, "https://example.com", "alice", true)] |
| 240 | + [InlineData("https://example.com", "alice", "https://example.com", "alice", true)] |
| 241 | + [InlineData("https://example.com", null, "https://example.com:443", "alice", true)] |
| 242 | + [InlineData("https://example.com", "alice", "https://example.com:443", "alice", true)] |
| 243 | + [InlineData("https://example.com:1234", null, "https://example.com:1234", "alice", true)] |
| 244 | + [InlineData("https://example.com:1234", "alice", "https://example.com:1234", "alice", true)] |
| 245 | + [InlineData("https://example.com", null, "http://example.com", "alice", false)] |
| 246 | + [InlineData("https://example.com", "alice", "http://example.com", "alice", false)] |
| 247 | + [InlineData("https://example.com", "alice", "http://example.com:443", "alice", false)] |
| 248 | + [InlineData("http://example.com:443", "alice", "https://example.com", "alice", false)] |
| 249 | + [InlineData("https://example.com", "bob", "https://example.com", "alice", false)] |
| 250 | + [InlineData("https://example.com", "bob", "https://[email protected]", "bob", true)] |
| 251 | + [InlineData("https://example.com", "bob", "https://example.com", "bob", true)] |
| 252 | + [InlineData("https://example.com", "alice", "https://example.com", "ALICE", false)] // username case sensitive |
| 253 | + [InlineData("https://example.com", "alice", "https://EXAMPLE.com", "alice", true)] // host NOT case sensitive |
| 254 | + [InlineData("https://example.com/path", "alice", "https://example.com/path", "alice", true)] |
| 255 | + [InlineData("https://example.com/path", "alice", "https://example.com/PATH", "alice", true)] // path NOT case sensitive |
| 256 | + public void WindowsCredentialManager_IsMatch( |
| 257 | + string service, string account, string targetName, string userName, bool expected) |
| 258 | + { |
| 259 | + string fullTargetName = $"{WindowsCredentialManager.TargetNameLegacyGenericPrefix}{TestNamespace}:{targetName}"; |
| 260 | + var win32Cred = new Win32Credential |
| 261 | + { |
| 262 | + UserName = userName, |
| 263 | + TargetName = fullTargetName |
| 264 | + }; |
| 265 | + |
| 266 | + var credManager = new WindowsCredentialManager(TestNamespace); |
| 267 | + |
| 268 | + bool actual = credManager.IsMatch(service, account, win32Cred); |
| 269 | + |
| 270 | + Assert.Equal(expected, actual); |
| 271 | + } |
| 272 | + |
| 273 | + [PlatformTheory(Platforms.Windows)] |
| 274 | + [InlineData("https://example.com", null, "https://example.com")] |
| 275 | + [InlineData("https://example.com", "bob", "https://[email protected]")] |
| 276 | + [InlineData("https://example.com", "[email protected]", "https://[email protected]")] // @ in user |
| 277 | + [InlineData("https://example.com:443", null, "https://example.com")] // default port |
| 278 | + [InlineData("https://example.com:1234", null, "https://example.com:1234")] |
| 279 | + [InlineData("https://example.com/path", null, "https://example.com/path")] |
| 280 | + [InlineData("https://example.com/path/with/more/parts", null, "https://example.com/path/with/more/parts")] |
| 281 | + [InlineData("https://example.com/path/trim/", null, "https://example.com/path/trim")] // path trailing slash |
| 282 | + [InlineData("https://example.com/", null, "https://example.com")] // no path trailing slash |
| 283 | + public void WindowsCredentialManager_CreateTargetName(string service, string account, string expected) |
| 284 | + { |
| 285 | + string fullExpected = $"{TestNamespace}:{expected}"; |
| 286 | + |
| 287 | + var credManager = new WindowsCredentialManager(TestNamespace); |
| 288 | + |
| 289 | + string actual = credManager.CreateTargetName(service, account); |
| 290 | + |
| 291 | + Assert.Equal(fullExpected, actual); |
| 292 | + } |
| 293 | + |
| 294 | + [PlatformTheory(Platforms.Windows)] |
| 295 | + [InlineData(TestNamespace, "https://example.com", null, $"{TestNamespace}:https://example.com")] |
| 296 | + [InlineData(null, "https://example.com", null, "https://example.com")] |
| 297 | + [InlineData("", "https://example.com", null, "https://example.com")] |
| 298 | + [InlineData(" ", "https://example.com", null, "https://example.com")] |
| 299 | + public void WindowsCredentialManager_CreateTargetName_Namespace(string @namespace, string service, string account, string expected) |
| 300 | + { |
| 301 | + var credManager = new WindowsCredentialManager(@namespace); |
| 302 | + |
| 303 | + string actual = credManager.CreateTargetName(service, account); |
| 304 | + |
| 305 | + Assert.Equal(expected, actual); |
| 306 | + } |
236 | 307 | }
|
237 | 308 | }
|
0 commit comments