1
1
using System ;
2
- using System . Collections . Generic ;
3
2
using System . Threading . Tasks ;
4
3
using Xunit ;
5
4
@@ -9,11 +8,11 @@ public class CredentialTests
9
8
{
10
9
private const string Namespace = "test" ;
11
10
12
- public static object [ ] [ ] CredentialData
11
+ public static object [ ] [ ] CredentialData
13
12
{
14
13
get
15
14
{
16
- List < object [ ] > data = new List < object [ ] > ( )
15
+ return new object [ ] [ ]
17
16
{
18
17
new object [ ] { false , "http://dummy.url/for/testing" , "username" , "password" , false } ,
19
18
new object [ ] { false , "http://dummy.url/for/testing?with=params" , "username" , "password" , false } ,
@@ -32,17 +31,30 @@ public static object[][] CredentialData
32
31
new object [ ] { true , "http://dummy.url/for/testing" , "null_passwords_are_legal" , null , false } ,
33
32
new object [ ] { true , "http://dummy.url/for/testing" , "blank_passwords_are_legal" , "" , false } ,
34
33
new object [ ] { true , "http://dummy.url:999/for/testing" , "username" , "password" , false } ,
35
- } ;
36
34
37
- return data . ToArray ( ) ;
35
+ new object [ ] { false , "http://[email protected] /for/testing" , "username" , "password" , false } ,
36
+ new object [ ] { false , "http://[email protected] /for/testing?with=params" , "username" , "password" , false } ,
37
+ new object [ ] { false , "http://[email protected] /for/testing" , null , "null_usernames_are_illegal" , true } ,
38
+ new object [ ] { false , "http://[email protected] /for/testing" , "" , "blank_usernames_are_legal" , false } ,
39
+ new object [ ] { false , "http://[email protected] /for/testing" , "null_passwords_are_legal" , null , false } ,
40
+ new object [ ] { false , "http://[email protected] /for/testing" , "blank_passwords_are_legal" , "" , false } ,
41
+ new object [ ] { false , "http://[email protected] :999/for/testing" , "username" , "password" , false } ,
42
+
43
+ new object [ ] { true , "http://[email protected] /for/testing" , "username" , "password" , false } ,
44
+ new object [ ] { true , "http://[email protected] /for/testing?with=params" , "username" , "password" , false } ,
45
+ new object [ ] { true , "http://[email protected] /for/testing" , null , "null_usernames_are_illegal" , true } ,
46
+ new object [ ] { true , "http://[email protected] /for/testing" , "" , "blank_usernames_are_legal" , false } ,
47
+ new object [ ] { true , "http://[email protected] /for/testing" , "null_passwords_are_legal" , null , false } ,
48
+ new object [ ] { true , "http://[email protected] /for/testing" , "blank_passwords_are_legal" , "" , false } ,
49
+ new object [ ] { true , "http://[email protected] :999/for/testing" , "username" , "password" , false } ,
50
+ } ;
38
51
}
39
52
}
40
53
41
- [ Theory ]
42
- [ MemberData ( nameof ( CredentialData ) , DisableDiscoveryEnumeration = true ) ]
43
- public void Credential_WriteDelete ( bool useCache , string url , string username , string password , bool throws )
54
+ [ Theory , MemberData ( nameof ( CredentialData ) , DisableDiscoveryEnumeration = false ) ]
55
+ public async Task Credential_WriteDelete ( bool useCache , string url , string username , string password , bool throws )
44
56
{
45
- var task = Task . Run ( async ( ) =>
57
+ try
46
58
{
47
59
var uri = new TargetUri ( url ) ;
48
60
var writeCreds = new Credential ( username , password ) ;
@@ -60,35 +72,45 @@ public void Credential_WriteDelete(bool useCache, string url, string username, s
60
72
61
73
await credentialStore . DeleteCredentials ( uri ) ;
62
74
63
- Assert . Null ( readCreds = await credentialStore . ReadCredentials ( uri ) ) ;
64
- } ) ;
75
+ readCreds = await credentialStore . ReadCredentials ( uri ) ;
76
+ Assert . Null ( readCreds ) ;
77
+ }
78
+ catch ( ArgumentNullException ) when ( throws )
79
+ {
80
+ /* We expected the exception */
81
+ }
82
+ }
65
83
66
- if ( throws )
84
+ [ Theory , MemberData ( nameof ( CredentialData ) , DisableDiscoveryEnumeration = false ) ]
85
+ public async Task Credential_WriteRead ( bool useCache , string url , string username , string password , bool throws )
86
+ {
87
+ try
67
88
{
68
- Assert . Throws < ArgumentNullException > ( ( ) =>
69
- {
70
- try
71
- {
72
- task . Wait ( ) ;
73
- }
74
- catch ( System . AggregateException exception )
75
- {
76
- exception = exception . Flatten ( ) ;
77
- throw exception . InnerException ;
78
- }
79
- } ) ;
89
+ var uri = new TargetUri ( url ) ;
90
+ var writeCreds = new Credential ( username , password ) ;
91
+ var credentialStore = useCache
92
+ ? new SecretCache ( RuntimeContext . Default , "test" , Secret . UriToName ) as ICredentialStore
93
+ : new SecretStore ( RuntimeContext . Default , "test" , null , null , Secret . UriToName ) as ICredentialStore ;
94
+ Credential readCreds = null ;
95
+
96
+ await credentialStore . WriteCredentials ( uri , writeCreds ) ;
97
+
98
+ readCreds = await credentialStore . ReadCredentials ( uri ) ;
99
+ Assert . NotNull ( readCreds ) ;
100
+ Assert . Equal ( writeCreds . Password , readCreds . Password ) ;
101
+ Assert . Equal ( writeCreds . Username , readCreds . Username ) ;
80
102
}
81
- else
103
+ catch ( ArgumentNullException ) when ( throws )
82
104
{
83
- task . Wait ( ) ;
105
+ /* We expected the exception */
84
106
}
85
107
}
86
108
87
- public static object [ ] [ ] UriToNameData
109
+ public static object [ ] [ ] UriToNameData
88
110
{
89
111
get
90
112
{
91
- return new object [ ] [ ]
113
+ return new object [ ] [ ]
92
114
{
93
115
new object [ ] { "https://microsoft.visualstudio.com" , null } ,
94
116
new object [ ] { "https://www.github.com" , null } ,
@@ -111,8 +133,7 @@ public static object[][] UriToNameData
111
133
}
112
134
}
113
135
114
- [ Theory ]
115
- [ MemberData ( nameof ( UriToNameData ) , DisableDiscoveryEnumeration = true ) ]
136
+ [ Theory , MemberData ( nameof ( UriToNameData ) , DisableDiscoveryEnumeration = true ) ]
116
137
public void UriToNameTest ( string original , string expected )
117
138
{
118
139
var uri = new Uri ( original ) ;
@@ -123,11 +144,11 @@ public void UriToNameTest(string original, string expected)
123
144
Assert . Equal ( expected , actual , StringComparer . Ordinal ) ;
124
145
}
125
146
126
- public static object [ ] [ ] UriToIdentityNameData
147
+ public static object [ ] [ ] UriToIdentityNameData
127
148
{
128
149
get
129
150
{
130
- return new object [ ] [ ]
151
+ return new object [ ] [ ]
131
152
{
132
153
new object [ ] { "https://microsoft.visualstudio.com" , null } ,
133
154
new object [ ] { "https://www.github.com" , null } ,
@@ -150,8 +171,7 @@ public static object[][] UriToIdentityNameData
150
171
}
151
172
}
152
173
153
- [ Theory ]
154
- [ MemberData ( nameof ( UriToIdentityNameData ) , DisableDiscoveryEnumeration = true ) ]
174
+ [ Theory , MemberData ( nameof ( UriToIdentityNameData ) , DisableDiscoveryEnumeration = true ) ]
155
175
public void UriToIdentityNameTest ( string original , string expected )
156
176
{
157
177
var uri = new Uri ( original ) ;
0 commit comments