1
+ using System ;
2
+ using Microsoft . TeamFoundation . DistributedTask . WebApi ;
3
+ using Microsoft . VisualStudio . Services . Agent . Util ;
4
+ using Xunit ;
5
+
6
+ namespace Microsoft . VisualStudio . Services . Agent . Tests . Util
7
+ {
8
+ public class UrlUtilL0
9
+ {
10
+ [ Fact ]
11
+ [ Trait ( "Level" , "L0" ) ]
12
+ [ Trait ( "Category" , "Common" ) ]
13
+ public void GetCredentialEmbeddedUrl_NoUsernameAndPassword ( )
14
+ {
15
+ // Act.
16
+ Uri result = UrlUtil . GetCredentialEmbeddedUrl ( new Uri ( "https://github.com/Microsoft/vsts-agent.git" ) , string . Empty , string . Empty ) ;
17
+ // Actual
18
+ Assert . Equal ( "https://github.com/Microsoft/vsts-agent.git" , result . AbsoluteUri ) ;
19
+ }
20
+
21
+ [ Fact ]
22
+ [ Trait ( "Level" , "L0" ) ]
23
+ [ Trait ( "Category" , "Common" ) ]
24
+ public void GetCredentialEmbeddedUrl_NoUsername ( )
25
+ {
26
+ // Act.
27
+ Uri result = UrlUtil . GetCredentialEmbeddedUrl ( new Uri ( "https://github.com/Microsoft/vsts-agent.git" ) , string . Empty , "password123" ) ;
28
+ // Actual
29
+ Assert . Equal ( "https://emptyusername:[email protected] /Microsoft/vsts-agent.git" , result . AbsoluteUri ) ;
30
+ }
31
+
32
+ [ Fact ]
33
+ [ Trait ( "Level" , "L0" ) ]
34
+ [ Trait ( "Category" , "Common" ) ]
35
+ public void GetCredentialEmbeddedUrl_NoPassword ( )
36
+ {
37
+ // Act.
38
+ Uri result = UrlUtil . GetCredentialEmbeddedUrl ( new Uri ( "https://github.com/Microsoft/vsts-agent.git" ) , "user123" , string . Empty ) ;
39
+ // Actual
40
+ Assert . Equal ( "https://[email protected] /Microsoft/vsts-agent.git" , result . AbsoluteUri ) ;
41
+ }
42
+
43
+ [ Fact ]
44
+ [ Trait ( "Level" , "L0" ) ]
45
+ [ Trait ( "Category" , "Common" ) ]
46
+ public void GetCredentialEmbeddedUrl_HasUsernameAndPassword ( )
47
+ {
48
+ // Act.
49
+ Uri result = UrlUtil . GetCredentialEmbeddedUrl ( new Uri ( "https://github.com/Microsoft/vsts-agent.git" ) , "user123" , "password123" ) ;
50
+ // Actual
51
+ Assert . Equal ( "https://user123:[email protected] /Microsoft/vsts-agent.git" , result . AbsoluteUri ) ;
52
+ }
53
+
54
+ [ Fact ]
55
+ [ Trait ( "Level" , "L0" ) ]
56
+ [ Trait ( "Category" , "Common" ) ]
57
+ public void GetCredentialEmbeddedUrl_UsernameAndPasswordEncoding ( )
58
+ {
59
+ // Act.
60
+ Uri result = UrlUtil . GetCredentialEmbeddedUrl ( new Uri ( "https://github.com/Microsoft/vsts-agent.git" ) , "user 123" , "password 123" ) ;
61
+ // Actual
62
+ Assert . Equal ( "https://user%20123:password%[email protected] /Microsoft/vsts-agent.git" , result . AbsoluteUri ) ;
63
+ }
64
+ }
65
+ }
0 commit comments