@@ -10,22 +10,19 @@ import Crypto
10
10
import Foundation
11
11
import Testing
12
12
@testable import WebPush
13
+ import WebPushTesting
13
14
14
15
@Suite ( " VAPID Configuration Tests " )
15
16
struct VAPIDConfigurationTests {
16
17
@Suite
17
18
struct Initialization {
18
- let key1 = try ! VAPID . Key ( base64URLEncoded: " FniTgSrf0l+BdfeC6LiblKXBbY4LQm0S+4STNCoJI+0= " )
19
- let key2 = try ! VAPID . Key ( base64URLEncoded: " wyQaGWNwvXKzVmPIhkqVQvQ+FKx1SNqHJ+re8n2ORrk= " )
20
- let key3 = try ! VAPID . Key ( base64URLEncoded: " bcZgo/p2WFqXaKFzmYaDKO/gARjWvGi3oXyHM2QNlfE= " )
21
-
22
19
@Test func primaryKeyOnly( ) {
23
20
let config = VAPID . Configuration (
24
- key: key1 ,
21
+ key: . mockedKey1 ,
25
22
contactInformation: . email( " test@email.com " )
26
23
)
27
- #expect( config. primaryKey == key1 )
28
- #expect( config. keys == [ key1 ] )
24
+ #expect( config. primaryKey == . mockedKey1 )
25
+ #expect( config. keys == [ . mockedKey1 ] )
29
26
#expect( config. deprecatedKeys == nil )
30
27
#expect( config. contactInformation == . email( " test@email.com " ) )
31
28
#expect( config. expirationDuration == . hours( 22 ) )
@@ -34,14 +31,14 @@ struct VAPIDConfigurationTests {
34
31
35
32
@Test func emptyDeprecatedKeys( ) {
36
33
let config = VAPID . Configuration (
37
- key: key1 ,
34
+ key: . mockedKey1 ,
38
35
deprecatedKeys: [ ] ,
39
36
contactInformation: . url( URL ( string: " https://example.com " ) !) ,
40
37
expirationDuration: . hours( 24 ) ,
41
38
validityDuration: . hours( 12 )
42
39
)
43
- #expect( config. primaryKey == key1 )
44
- #expect( config. keys == [ key1 ] )
40
+ #expect( config. primaryKey == . mockedKey1 )
41
+ #expect( config. keys == [ . mockedKey1 ] )
45
42
#expect( config. deprecatedKeys == nil )
46
43
#expect( config. contactInformation == . url( URL ( string: " https://example.com " ) !) )
47
44
#expect( config. expirationDuration == . hours( 24 ) )
@@ -50,29 +47,29 @@ struct VAPIDConfigurationTests {
50
47
51
48
@Test func deprecatedKeys( ) {
52
49
let config = VAPID . Configuration (
53
- key: key1 ,
54
- deprecatedKeys: [ key2 , key3 ] ,
50
+ key: . mockedKey1 ,
51
+ deprecatedKeys: [ . mockedKey2 , . mockedKey3 ] ,
55
52
contactInformation: . email( " test@email.com " )
56
53
)
57
- #expect( config. primaryKey == key1 )
58
- #expect( config. keys == [ key1 ] )
59
- #expect( config. deprecatedKeys == [ key2 , key3 ] )
54
+ #expect( config. primaryKey == . mockedKey1 )
55
+ #expect( config. keys == [ . mockedKey1 ] )
56
+ #expect( config. deprecatedKeys == [ . mockedKey2 , . mockedKey3 ] )
60
57
#expect( config. contactInformation == . email( " test@email.com " ) )
61
58
#expect( config. expirationDuration == . hours( 22 ) )
62
59
#expect( config. validityDuration == . hours( 20 ) )
63
60
}
64
61
65
62
@Test func deprecatedAndPrimaryKeys( ) {
66
63
let config = VAPID . Configuration (
67
- key: key1 ,
68
- deprecatedKeys: [ key2 , key3 , key1 ] ,
64
+ key: . mockedKey1 ,
65
+ deprecatedKeys: [ . mockedKey2 , . mockedKey3 , . mockedKey1 ] ,
69
66
contactInformation: . url( URL ( string: " https://example.com " ) !) ,
70
67
expirationDuration: . hours( 24 ) ,
71
68
validityDuration: . hours( 12 )
72
69
)
73
- #expect( config. primaryKey == key1 )
74
- #expect( config. keys == [ key1 ] )
75
- #expect( config. deprecatedKeys == [ key2 , key3 ] )
70
+ #expect( config. primaryKey == . mockedKey1 )
71
+ #expect( config. keys == [ . mockedKey1 ] )
72
+ #expect( config. deprecatedKeys == [ . mockedKey2 , . mockedKey3 ] )
76
73
#expect( config. contactInformation == . url( URL ( string: " https://example.com " ) !) )
77
74
#expect( config. expirationDuration == . hours( 24 ) )
78
75
#expect( config. validityDuration == . hours( 12 ) )
@@ -81,12 +78,12 @@ struct VAPIDConfigurationTests {
81
78
@Test func multipleKeys( ) throws {
82
79
let config = try VAPID . Configuration (
83
80
primaryKey: nil ,
84
- keys: [ key1 , key2 ] ,
81
+ keys: [ . mockedKey1 , . mockedKey2 ] ,
85
82
deprecatedKeys: nil ,
86
83
contactInformation: . email( " test@email.com " )
87
84
)
88
85
#expect( config. primaryKey == nil )
89
- #expect( config. keys == [ key1 , key2 ] )
86
+ #expect( config. keys == [ . mockedKey1 , . mockedKey2 ] )
90
87
#expect( config. deprecatedKeys == nil )
91
88
#expect( config. contactInformation == . email( " test@email.com " ) )
92
89
#expect( config. expirationDuration == . hours( 22 ) )
@@ -98,7 +95,7 @@ struct VAPIDConfigurationTests {
98
95
try VAPID . Configuration (
99
96
primaryKey: nil ,
100
97
keys: [ ] ,
101
- deprecatedKeys: [ key2 , key3 ] ,
98
+ deprecatedKeys: [ . mockedKey2 , . mockedKey3 ] ,
102
99
contactInformation: . email( " test@email.com " )
103
100
)
104
101
}
@@ -107,12 +104,12 @@ struct VAPIDConfigurationTests {
107
104
@Test func multipleAndDeprecatedKeys( ) throws {
108
105
let config = try VAPID . Configuration (
109
106
primaryKey: nil ,
110
- keys: [ key1 , key2 ] ,
111
- deprecatedKeys: [ key2 ] ,
107
+ keys: [ . mockedKey1 , . mockedKey2 ] ,
108
+ deprecatedKeys: [ . mockedKey2 ] ,
112
109
contactInformation: . email( " test@email.com " )
113
110
)
114
111
#expect( config. primaryKey == nil )
115
- #expect( config. keys == [ key1 , key2 ] )
112
+ #expect( config. keys == [ . mockedKey1 , . mockedKey2 ] )
116
113
#expect( config. deprecatedKeys == nil )
117
114
#expect( config. contactInformation == . email( " test@email.com " ) )
118
115
#expect( config. expirationDuration == . hours( 22 ) )
@@ -121,16 +118,16 @@ struct VAPIDConfigurationTests {
121
118
122
119
@Test func multipleAndPrimaryKeys( ) throws {
123
120
let config = try VAPID . Configuration (
124
- primaryKey: key1 ,
125
- keys: [ key2 ] ,
126
- deprecatedKeys: [ key2 , key3 , key1 ] ,
121
+ primaryKey: . mockedKey1 ,
122
+ keys: [ . mockedKey2 ] ,
123
+ deprecatedKeys: [ . mockedKey2 , . mockedKey3 , . mockedKey1 ] ,
127
124
contactInformation: . url( URL ( string: " https://example.com " ) !) ,
128
125
expirationDuration: . hours( 24 ) ,
129
126
validityDuration: . hours( 12 )
130
127
)
131
- #expect( config. primaryKey == key1 )
132
- #expect( config. keys == [ key1 , key2 ] )
133
- #expect( config. deprecatedKeys == [ key3 ] )
128
+ #expect( config. primaryKey == . mockedKey1 )
129
+ #expect( config. keys == [ . mockedKey1 , . mockedKey2 ] )
130
+ #expect( config. deprecatedKeys == [ . mockedKey3 ] )
134
131
#expect( config. contactInformation == . url( URL ( string: " https://example.com " ) !) )
135
132
#expect( config. expirationDuration == . hours( 24 ) )
136
133
#expect( config. validityDuration == . hours( 12 ) )
@@ -139,81 +136,73 @@ struct VAPIDConfigurationTests {
139
136
140
137
@Suite
141
138
struct Updates {
142
- let key1 = try ! VAPID . Key ( base64URLEncoded: " FniTgSrf0l+BdfeC6LiblKXBbY4LQm0S+4STNCoJI+0= " )
143
- let key2 = try ! VAPID . Key ( base64URLEncoded: " wyQaGWNwvXKzVmPIhkqVQvQ+FKx1SNqHJ+re8n2ORrk= " )
144
- let key3 = try ! VAPID . Key ( base64URLEncoded: " bcZgo/p2WFqXaKFzmYaDKO/gARjWvGi3oXyHM2QNlfE= " )
145
-
146
139
@Test func primaryKeyOnly( ) throws {
147
- var config = VAPID . Configuration ( key: key1 , contactInformation: . email( " test@email.com " ) )
140
+ var config = VAPID . Configuration ( key: . mockedKey1 , contactInformation: . email( " test@email.com " ) )
148
141
149
- try config. updateKeys ( primaryKey: key2 , keys: [ ] , deprecatedKeys: nil )
150
- #expect( config. primaryKey == key2 )
151
- #expect( config. keys == [ key2 ] )
142
+ try config. updateKeys ( primaryKey: . mockedKey2 , keys: [ ] , deprecatedKeys: nil )
143
+ #expect( config. primaryKey == . mockedKey2 )
144
+ #expect( config. keys == [ . mockedKey2 ] )
152
145
#expect( config. deprecatedKeys == nil )
153
146
}
154
147
155
148
@Test func noKeys( ) throws {
156
- var config = VAPID . Configuration ( key: key1 , contactInformation: . email( " test@email.com " ) )
149
+ var config = VAPID . Configuration ( key: . mockedKey1 , contactInformation: . email( " test@email.com " ) )
157
150
#expect( throws: VAPID . ConfigurationError. keysNotProvided) {
158
151
try config. updateKeys ( primaryKey: nil , keys: [ ] , deprecatedKeys: nil )
159
152
}
160
153
#expect( throws: VAPID . ConfigurationError. keysNotProvided) {
161
154
try config. updateKeys ( primaryKey: nil , keys: [ ] , deprecatedKeys: [ ] )
162
155
}
163
156
#expect( throws: VAPID . ConfigurationError. keysNotProvided) {
164
- try config. updateKeys ( primaryKey: nil , keys: [ ] , deprecatedKeys: [ key1 ] )
157
+ try config. updateKeys ( primaryKey: nil , keys: [ ] , deprecatedKeys: [ . mockedKey1 ] )
165
158
}
166
159
}
167
160
168
161
@Test func multipleKeys( ) throws {
169
- var config = VAPID . Configuration ( key: key1 , contactInformation: . email( " test@email.com " ) )
162
+ var config = VAPID . Configuration ( key: . mockedKey1 , contactInformation: . email( " test@email.com " ) )
170
163
171
- try config. updateKeys ( primaryKey: nil , keys: [ key2 ] , deprecatedKeys: nil )
164
+ try config. updateKeys ( primaryKey: nil , keys: [ . mockedKey2 ] , deprecatedKeys: nil )
172
165
#expect( config. primaryKey == nil )
173
- #expect( config. keys == [ key2 ] )
166
+ #expect( config. keys == [ . mockedKey2 ] )
174
167
#expect( config. deprecatedKeys == nil )
175
168
176
- try config. updateKeys ( primaryKey: nil , keys: [ key2 , key3 ] , deprecatedKeys: nil )
169
+ try config. updateKeys ( primaryKey: nil , keys: [ . mockedKey2 , . mockedKey3 ] , deprecatedKeys: nil )
177
170
#expect( config. primaryKey == nil )
178
- #expect( config. keys == [ key2 , key3 ] )
171
+ #expect( config. keys == [ . mockedKey2 , . mockedKey3 ] )
179
172
#expect( config. deprecatedKeys == nil )
180
173
}
181
174
182
175
@Test func multipleAndDeprecatedKeys( ) throws {
183
- var config = VAPID . Configuration ( key: key1 , contactInformation: . email( " test@email.com " ) )
176
+ var config = VAPID . Configuration ( key: . mockedKey1 , contactInformation: . email( " test@email.com " ) )
184
177
185
- try config. updateKeys ( primaryKey: nil , keys: [ key2 ] , deprecatedKeys: [ key2 , key3 ] )
178
+ try config. updateKeys ( primaryKey: nil , keys: [ . mockedKey2 ] , deprecatedKeys: [ . mockedKey2 , . mockedKey3 ] )
186
179
#expect( config. primaryKey == nil )
187
- #expect( config. keys == [ key2 ] )
188
- #expect( config. deprecatedKeys == [ key3 ] )
180
+ #expect( config. keys == [ . mockedKey2 ] )
181
+ #expect( config. deprecatedKeys == [ . mockedKey3 ] )
189
182
190
- try config. updateKeys ( primaryKey: nil , keys: [ key2 , key3 ] , deprecatedKeys: [ key2 , key3 ] )
183
+ try config. updateKeys ( primaryKey: nil , keys: [ . mockedKey2 , . mockedKey3 ] , deprecatedKeys: [ . mockedKey2 , . mockedKey3 ] )
191
184
#expect( config. primaryKey == nil )
192
- #expect( config. keys == [ key2 , key3 ] )
185
+ #expect( config. keys == [ . mockedKey2 , . mockedKey3 ] )
193
186
#expect( config. deprecatedKeys == nil )
194
187
}
195
188
196
189
@Test func multipleAndPrimaryKeys( ) throws {
197
- var config = VAPID . Configuration ( key: key1 , contactInformation: . email( " test@email.com " ) )
190
+ var config = VAPID . Configuration ( key: . mockedKey1 , contactInformation: . email( " test@email.com " ) )
198
191
199
- try config. updateKeys ( primaryKey: key2 , keys: [ key3 ] , deprecatedKeys: [ key1 , key2 , key3 ] )
200
- #expect( config. primaryKey == key2 )
201
- #expect( config. keys == [ key2 , key3 ] )
202
- #expect( config. deprecatedKeys == [ key1 ] )
192
+ try config. updateKeys ( primaryKey: . mockedKey2 , keys: [ . mockedKey3 ] , deprecatedKeys: [ . mockedKey1 , . mockedKey2 , . mockedKey3 ] )
193
+ #expect( config. primaryKey == . mockedKey2 )
194
+ #expect( config. keys == [ . mockedKey2 , . mockedKey3 ] )
195
+ #expect( config. deprecatedKeys == [ . mockedKey1 ] )
203
196
204
- try config. updateKeys ( primaryKey: key2 , keys: [ key3 ] , deprecatedKeys: [ key2 , key3 ] )
205
- #expect( config. primaryKey == key2 )
206
- #expect( config. keys == [ key2 , key3 ] )
197
+ try config. updateKeys ( primaryKey: . mockedKey2 , keys: [ . mockedKey3 ] , deprecatedKeys: [ . mockedKey2 , . mockedKey3 ] )
198
+ #expect( config. primaryKey == . mockedKey2 )
199
+ #expect( config. keys == [ . mockedKey2 , . mockedKey3 ] )
207
200
#expect( config. deprecatedKeys == nil )
208
201
}
209
202
}
210
203
211
204
@Suite
212
205
struct Coding {
213
- let key1 = try ! VAPID . Key ( base64URLEncoded: " FniTgSrf0l+BdfeC6LiblKXBbY4LQm0S+4STNCoJI+0= " )
214
- let key2 = try ! VAPID . Key ( base64URLEncoded: " wyQaGWNwvXKzVmPIhkqVQvQ+FKx1SNqHJ+re8n2ORrk= " )
215
- let key3 = try ! VAPID . Key ( base64URLEncoded: " bcZgo/p2WFqXaKFzmYaDKO/gARjWvGi3oXyHM2QNlfE= " )
216
-
217
206
func encode( _ configuration: VAPID . Configuration ) throws -> String {
218
207
let encoder = JSONEncoder ( )
219
208
encoder. outputFormatting = [ . prettyPrinted, . sortedKeys, . withoutEscapingSlashes]
@@ -222,7 +211,7 @@ struct VAPIDConfigurationTests {
222
211
223
212
@Test func encodesPrimaryKeyOnly( ) async throws {
224
213
#expect(
225
- try encode ( . init( key: key1 , contactInformation: . email( " test@example.com " ) ) ) ==
214
+ try encode ( . init( key: . mockedKey1 , contactInformation: . email( " test@example.com " ) ) ) ==
226
215
"""
227
216
{
228
217
" contactInformation " : " mailto:test@example.com " ,
@@ -237,9 +226,9 @@ struct VAPIDConfigurationTests {
237
226
@Test func encodesMultipleKeysWithoutDuplicates( ) async throws {
238
227
#expect(
239
228
try encode ( . init(
240
- primaryKey: key1 ,
241
- keys: [ key2 ] ,
242
- deprecatedKeys: [ key1 , key2 , key3 ] ,
229
+ primaryKey: . mockedKey1 ,
230
+ keys: [ . mockedKey2 ] ,
231
+ deprecatedKeys: [ . mockedKey1 , . mockedKey2 , . mockedKey3 ] ,
243
232
contactInformation: . email( " test@example.com " ) ,
244
233
expirationDuration: . hours( 1 ) ,
245
234
validityDuration: . hours( 10 )
@@ -274,7 +263,7 @@ struct VAPIDConfigurationTests {
274
263
""" . utf8
275
264
) ) ==
276
265
VAPID . Configuration (
277
- key: key1 ,
266
+ key: . mockedKey1 ,
278
267
contactInformation: . email( " test@example.com " )
279
268
)
280
269
)
@@ -299,9 +288,9 @@ struct VAPIDConfigurationTests {
299
288
""" . utf8
300
289
) ) ==
301
290
VAPID . Configuration (
302
- primaryKey: key1 ,
303
- keys: [ key2 ] ,
304
- deprecatedKeys: [ key1 , key2 , key3 ] ,
291
+ primaryKey: . mockedKey1 ,
292
+ keys: [ . mockedKey2 ] ,
293
+ deprecatedKeys: [ . mockedKey1 , . mockedKey2 , . mockedKey3 ] ,
305
294
contactInformation: . email( " test@example.com " ) ,
306
295
expirationDuration: . hours( 1 ) ,
307
296
validityDuration: . hours( 10 )
0 commit comments