1
1
using System ;
2
- using System . Collections . Generic ;
3
2
using WebPush . Util ;
4
3
using Xunit ;
5
4
@@ -14,9 +13,9 @@ public class VapidHelperTest
14
13
[ Fact ]
15
14
public void TestGenerateVapidKeys ( )
16
15
{
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 ) ;
20
19
21
20
Assert . Equal ( 32 , privateKey . Length ) ;
22
21
Assert . Equal ( 65 , publicKey . Length ) ;
@@ -25,8 +24,8 @@ public void TestGenerateVapidKeys()
25
24
[ Fact ]
26
25
public void TestGenerateVapidKeysNoCache ( )
27
26
{
28
- VapidDetails keys1 = VapidHelper . GenerateVapidKeys ( ) ;
29
- VapidDetails keys2 = VapidHelper . GenerateVapidKeys ( ) ;
27
+ var keys1 = VapidHelper . GenerateVapidKeys ( ) ;
28
+ var keys2 = VapidHelper . GenerateVapidKeys ( ) ;
30
29
31
30
Assert . NotEqual ( keys1 . PublicKey , keys2 . PublicKey ) ;
32
31
Assert . NotEqual ( keys1 . PrivateKey , keys2 . PrivateKey ) ;
@@ -35,76 +34,64 @@ public void TestGenerateVapidKeysNoCache()
35
34
[ Fact ]
36
35
public void TestGetVapidHeaders ( )
37
36
{
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 ) ;
41
40
42
41
Assert . True ( headers . ContainsKey ( "Authorization" ) ) ;
43
42
Assert . True ( headers . ContainsKey ( "Crypto-Key" ) ) ;
44
43
}
45
44
46
45
[ Fact ]
47
- public void TestGetVapidHeadersWithMailToSubject ( )
46
+ public void TestGetVapidHeadersAudienceNotAUrl ( )
48
47
{
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 ] ) ;
53
50
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 ) ; } ) ;
56
53
}
57
54
58
55
[ Fact ]
59
- public void TestGetVapidHeadersAudienceNotAUrl ( )
56
+ public void TestGetVapidHeadersInvalidPrivateKey ( )
60
57
{
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 ] ) ;
63
60
64
61
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 ) ; } ) ;
69
63
}
70
64
71
65
[ Fact ]
72
- public void TestGetVapidHeadersSubjectNotAUrlOrMailTo ( )
66
+ public void TestGetVapidHeadersInvalidPublicKey ( )
73
67
{
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 ] ) ;
76
70
77
71
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 ) ; } ) ;
82
73
}
83
74
84
75
[ Fact ]
85
- public void TestGetVapidHeadersInvalidPublicKey ( )
76
+ public void TestGetVapidHeadersSubjectNotAUrlOrMailTo ( )
86
77
{
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 ] ) ;
89
80
90
81
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 ) ; } ) ;
95
83
}
96
84
97
85
[ Fact ]
98
- public void TestGetVapidHeadersInvalidPrivateKey ( )
86
+ public void TestGetVapidHeadersWithMailToSubject ( )
99
87
{
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 ) ;
102
92
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" ) ) ;
108
95
}
109
96
}
110
97
}
0 commit comments