11using System ;
2- using System . Collections . Generic ;
32using WebPush . Util ;
43using Xunit ;
54
@@ -14,9 +13,9 @@ public class VapidHelperTest
1413 [ Fact ]
1514 public void TestGenerateVapidKeys ( )
1615 {
17- VapidDetails keys = VapidHelper . GenerateVapidKeys ( ) ;
18- byte [ ] publicKey = UrlBase64 . Decode ( keys . PublicKey ) ;
19- byte [ ] privateKey = UrlBase64 . Decode ( keys . PrivateKey ) ;
16+ var keys = VapidHelper . GenerateVapidKeys ( ) ;
17+ var publicKey = UrlBase64 . Decode ( keys . PublicKey ) ;
18+ var privateKey = UrlBase64 . Decode ( keys . PrivateKey ) ;
2019
2120 Assert . Equal ( 32 , privateKey . Length ) ;
2221 Assert . Equal ( 65 , publicKey . Length ) ;
@@ -25,8 +24,8 @@ public void TestGenerateVapidKeys()
2524 [ Fact ]
2625 public void TestGenerateVapidKeysNoCache ( )
2726 {
28- VapidDetails keys1 = VapidHelper . GenerateVapidKeys ( ) ;
29- VapidDetails keys2 = VapidHelper . GenerateVapidKeys ( ) ;
27+ var keys1 = VapidHelper . GenerateVapidKeys ( ) ;
28+ var keys2 = VapidHelper . GenerateVapidKeys ( ) ;
3029
3130 Assert . NotEqual ( keys1 . PublicKey , keys2 . PublicKey ) ;
3231 Assert . NotEqual ( keys1 . PrivateKey , keys2 . PrivateKey ) ;
@@ -35,76 +34,64 @@ public void TestGenerateVapidKeysNoCache()
3534 [ Fact ]
3635 public void TestGetVapidHeaders ( )
3736 {
38- string publicKey = UrlBase64 . Encode ( new byte [ 65 ] ) ;
39- string privatekey = UrlBase64 . Encode ( new byte [ 32 ] ) ;
40- Dictionary < string , string > headers = VapidHelper . GetVapidHeaders ( VALID_AUDIENCE , VALID_SUBJECT , publicKey , privatekey ) ;
37+ var publicKey = UrlBase64 . Encode ( new byte [ 65 ] ) ;
38+ var privatekey = UrlBase64 . Encode ( new byte [ 32 ] ) ;
39+ var headers = VapidHelper . GetVapidHeaders ( VALID_AUDIENCE , VALID_SUBJECT , publicKey , privatekey ) ;
4140
4241 Assert . True ( headers . ContainsKey ( "Authorization" ) ) ;
4342 Assert . True ( headers . ContainsKey ( "Crypto-Key" ) ) ;
4443 }
4544
4645 [ Fact ]
47- public void TestGetVapidHeadersWithMailToSubject ( )
46+ public void TestGetVapidHeadersAudienceNotAUrl ( )
4847 {
49- string publicKey = UrlBase64 . Encode ( new byte [ 65 ] ) ;
50- string privatekey = UrlBase64 . Encode ( new byte [ 32 ] ) ;
51- Dictionary < string , string > headers = VapidHelper . GetVapidHeaders ( VALID_AUDIENCE , VALID_SUBJECT_MAILTO , publicKey ,
52- privatekey ) ;
48+ var publicKey = UrlBase64 . Encode ( new byte [ 65 ] ) ;
49+ var privatekey = UrlBase64 . Encode ( new byte [ 32 ] ) ;
5350
54- Assert . True ( headers . ContainsKey ( "Authorization" ) ) ;
55- Assert . True ( headers . ContainsKey ( "Crypto-Key" ) ) ;
51+ Assert . Throws ( typeof ( ArgumentException ) ,
52+ delegate { VapidHelper . GetVapidHeaders ( "invalid audience" , VALID_SUBJECT , publicKey , privatekey ) ; } ) ;
5653 }
5754
5855 [ Fact ]
59- public void TestGetVapidHeadersAudienceNotAUrl ( )
56+ public void TestGetVapidHeadersInvalidPrivateKey ( )
6057 {
61- string publicKey = UrlBase64 . Encode ( new byte [ 65 ] ) ;
62- string privatekey = UrlBase64 . Encode ( new byte [ 32 ] ) ;
58+ var publicKey = UrlBase64 . Encode ( new byte [ 65 ] ) ;
59+ var privatekey = UrlBase64 . Encode ( new byte [ 1 ] ) ;
6360
6461 Assert . Throws ( typeof ( ArgumentException ) ,
65- delegate
66- {
67- VapidHelper . GetVapidHeaders ( "invalid audience" , VALID_SUBJECT , publicKey , privatekey ) ;
68- } ) ;
62+ delegate { VapidHelper . GetVapidHeaders ( VALID_AUDIENCE , VALID_SUBJECT , publicKey , privatekey ) ; } ) ;
6963 }
7064
7165 [ Fact ]
72- public void TestGetVapidHeadersSubjectNotAUrlOrMailTo ( )
66+ public void TestGetVapidHeadersInvalidPublicKey ( )
7367 {
74- string publicKey = UrlBase64 . Encode ( new byte [ 65 ] ) ;
75- string privatekey = UrlBase64 . Encode ( new byte [ 32 ] ) ;
68+ var publicKey = UrlBase64 . Encode ( new byte [ 1 ] ) ;
69+ var privatekey = UrlBase64 . Encode ( new byte [ 32 ] ) ;
7670
7771 Assert . Throws ( typeof ( ArgumentException ) ,
78- delegate
79- {
80- VapidHelper . GetVapidHeaders ( VALID_AUDIENCE , "invalid subject" , publicKey , privatekey ) ;
81- } ) ;
72+ delegate { VapidHelper . GetVapidHeaders ( VALID_AUDIENCE , VALID_SUBJECT , publicKey , privatekey ) ; } ) ;
8273 }
8374
8475 [ Fact ]
85- public void TestGetVapidHeadersInvalidPublicKey ( )
76+ public void TestGetVapidHeadersSubjectNotAUrlOrMailTo ( )
8677 {
87- string publicKey = UrlBase64 . Encode ( new byte [ 1 ] ) ;
88- string privatekey = UrlBase64 . Encode ( new byte [ 32 ] ) ;
78+ var publicKey = UrlBase64 . Encode ( new byte [ 65 ] ) ;
79+ var privatekey = UrlBase64 . Encode ( new byte [ 32 ] ) ;
8980
9081 Assert . Throws ( typeof ( ArgumentException ) ,
91- delegate
92- {
93- VapidHelper . GetVapidHeaders ( VALID_AUDIENCE , VALID_SUBJECT , publicKey , privatekey ) ;
94- } ) ;
82+ delegate { VapidHelper . GetVapidHeaders ( VALID_AUDIENCE , "invalid subject" , publicKey , privatekey ) ; } ) ;
9583 }
9684
9785 [ Fact ]
98- public void TestGetVapidHeadersInvalidPrivateKey ( )
86+ public void TestGetVapidHeadersWithMailToSubject ( )
9987 {
100- string publicKey = UrlBase64 . Encode ( new byte [ 65 ] ) ;
101- string privatekey = UrlBase64 . Encode ( new byte [ 1 ] ) ;
88+ var publicKey = UrlBase64 . Encode ( new byte [ 65 ] ) ;
89+ var privatekey = UrlBase64 . Encode ( new byte [ 32 ] ) ;
90+ var headers = VapidHelper . GetVapidHeaders ( VALID_AUDIENCE , VALID_SUBJECT_MAILTO , publicKey ,
91+ privatekey ) ;
10292
103- Assert . Throws ( typeof ( ArgumentException ) ,
104- delegate
105- {
106- VapidHelper . GetVapidHeaders ( VALID_AUDIENCE , VALID_SUBJECT , publicKey , privatekey ) ;
107- } ) ;
93+ Assert . True ( headers . ContainsKey ( "Authorization" ) ) ;
94+ Assert . True ( headers . ContainsKey ( "Crypto-Key" ) ) ;
10895 }
10996 }
11097}
0 commit comments