@@ -33,7 +33,7 @@ class EncodeTests: XCTestCase {
33
33
class PayloadTests : XCTestCase {
34
34
func testIssuer( ) {
35
35
_ = JWT . encode ( . none) { builder in
36
- builder. issuer = " fuller.li "
36
+ builder. issuer = " fuller.li "
37
37
XCTAssertEqual ( builder. issuer, " fuller.li " )
38
38
XCTAssertEqual ( builder [ " iss " ] as? String , " fuller.li " )
39
39
}
@@ -106,26 +106,26 @@ class DecodeTests: XCTestCase {
106
106
107
107
func testDisablingVerify( ) {
108
108
let jwt = " eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e30.2_8pWJfyPup0YwOXK7g9Dn0cF1E3pdn299t4hSeJy5w "
109
- assertSuccess ( try decode ( jwt, algorithm: . none, verify: false , issuer: " fuller.li " ) )
109
+ assertSuccess ( try decode ( jwt, algorithm: . none, verify: false , issuer: " fuller.li " ) )
110
110
}
111
111
112
112
// MARK: Issuer claim
113
113
114
114
func testSuccessfulIssuerValidation( ) {
115
115
let jwt = " eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJmdWxsZXIubGkifQ.d7B7PAQcz1E6oNhrlxmHxHXHgg39_k7X7wWeahl8kSQ "
116
- assertSuccess ( try decode ( jwt, algorithm: . hs256( " secret " . data ( using: . utf8) !) , issuer: " fuller.li " ) ) { payload in
116
+ assertSuccess ( try decode ( jwt, algorithm: . hs256( " secret " . data ( using: . utf8) !) , issuer: " fuller.li " ) ) { payload in
117
117
XCTAssertEqual ( payload as! [ String : String ] , [ " iss " : " fuller.li " ] )
118
118
}
119
119
}
120
120
121
121
func testIncorrectIssuerValidation( ) {
122
122
let jwt = " eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJmdWxsZXIubGkifQ.wOhJ9_6lx-3JGJPmJmtFCDI3kt7uMAMmhHIslti7ryI "
123
- assertFailure ( try decode ( jwt, algorithm: . hs256( " secret " . data ( using: . utf8) !) , issuer: " querykit.org " ) )
123
+ assertFailure ( try decode ( jwt, algorithm: . hs256( " secret " . data ( using: . utf8) !) , issuer: " querykit.org " ) )
124
124
}
125
125
126
126
func testMissingIssuerValidation( ) {
127
127
let jwt = " eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e30.2_8pWJfyPup0YwOXK7g9Dn0cF1E3pdn299t4hSeJy5w "
128
- assertFailure ( try decode ( jwt, algorithm: . hs256( " secret " . data ( using: . utf8) !) , issuer: " fuller.li " ) )
128
+ assertFailure ( try decode ( jwt, algorithm: . hs256( " secret " . data ( using: . utf8) !) , issuer: " fuller.li " ) )
129
129
}
130
130
131
131
// MARK: Expiration claim
@@ -147,7 +147,7 @@ class DecodeTests: XCTestCase {
147
147
XCTAssertEqual ( payload as! [ String : Int ] , [ " exp " : 1728188491 ] )
148
148
}
149
149
}
150
-
150
+
151
151
func testUnexpiredClaimString( ) {
152
152
// If this just started failing, hello 2024!
153
153
let jwt = " eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOiIxNzI4MTg4NDkxIn0.y4w7lNLrfRRPzuNUfM-ZvPkoOtrTU_d8ZVYasLdZGpk "
@@ -164,7 +164,7 @@ class DecodeTests: XCTestCase {
164
164
XCTAssertEqual ( payload as! [ String : Int ] , [ " nbf " : 1428189720 ] )
165
165
}
166
166
}
167
-
167
+
168
168
func testNotBeforeClaimString( ) {
169
169
let jwt = " eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOiIxNDI4MTg5NzIwIn0.qZsj36irdmIAeXv6YazWDSFbpuxHtEh4Deof5YTpnVI "
170
170
assertSuccess ( try decode ( jwt, algorithm: . hs256( " secret " . data ( using: . utf8) !) ) ) { payload in
@@ -215,34 +215,34 @@ class DecodeTests: XCTestCase {
215
215
216
216
func testAudiencesClaim( ) {
217
217
let jwt = " eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOlsibWF4aW5lIiwia2F0aWUiXX0.-PKvdNLCClrWG7CvesHP6PB0-vxu-_IZcsYhJxBy5JM "
218
- assertSuccess ( try decode ( jwt, algorithm: . hs256( " secret " . data ( using: . utf8) !) , audience: " maxine " ) ) { payload in
218
+ assertSuccess ( try decode ( jwt, algorithm: . hs256( " secret " . data ( using: . utf8) !) , audience: " maxine " ) ) { payload in
219
219
XCTAssertEqual ( payload. count, 1 )
220
220
XCTAssertEqual ( payload [ " aud " ] as! [ String ] , [ " maxine " , " katie " ] )
221
221
}
222
222
}
223
223
224
224
func testAudienceClaim( ) {
225
225
let jwt = " eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJreWxlIn0.dpgH4JOwueReaBoanLSxsGTc7AjKUvo7_M1sAfy_xVE "
226
- assertSuccess ( try decode ( jwt, algorithm: . hs256( " secret " . data ( using: . utf8) !) , audience: " kyle " ) ) { payload in
226
+ assertSuccess ( try decode ( jwt, algorithm: . hs256( " secret " . data ( using: . utf8) !) , audience: " kyle " ) ) { payload in
227
227
XCTAssertEqual ( payload as! [ String : String ] , [ " aud " : " kyle " ] )
228
228
}
229
229
}
230
230
231
231
func testMismatchAudienceClaim( ) {
232
232
let jwt = " eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJreWxlIn0.VEB_n06pTSLlTXPFkc46ARADJ9HXNUBUPo3VhL9RDe4 " // kyle
233
- assertFailure ( try decode ( jwt, algorithm: . hs256( " secret " . data ( using: . utf8) !) , audience: " maxine " ) )
233
+ assertFailure ( try decode ( jwt, algorithm: . hs256( " secret " . data ( using: . utf8) !) , audience: " maxine " ) )
234
234
}
235
235
236
236
func testMissingAudienceClaim( ) {
237
237
let jwt = " eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e30.2_8pWJfyPup0YwOXK7g9Dn0cF1E3pdn299t4hSeJy5w "
238
- assertFailure ( try decode ( jwt, algorithm: . hs256( " secret " . data ( using: . utf8) !) , audience: " kyle " ) )
238
+ assertFailure ( try decode ( jwt, algorithm: . hs256( " secret " . data ( using: . utf8) !) , audience: " kyle " ) )
239
239
}
240
240
241
241
// MARK: Signature verification
242
242
243
243
func testNoneAlgorithm( ) {
244
244
let jwt = " eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.eyJ0ZXN0IjoiaW5nIn0. "
245
- assertSuccess ( try decode ( jwt, algorithm: . none) ) { payload in
245
+ assertSuccess ( try decode ( jwt, algorithm: . none) ) { payload in
246
246
XCTAssertEqual ( payload as! [ String : String ] , [ " test " : " ing " ] )
247
247
}
248
248
}
@@ -274,7 +274,7 @@ class DecodeTests: XCTestCase {
274
274
275
275
// MARK: Helpers
276
276
277
- func assertSuccess( _ decoder: @autoclosure ( ) throws -> Payload , closure: ( ( Payload ) -> ( ) ) ? = nil ) {
277
+ func assertSuccess( _ decoder: @autoclosure ( ) throws -> Payload , closure: ( ( Payload ) -> Void ) ? = nil ) {
278
278
do {
279
279
let payload = try decoder ( )
280
280
closure ? ( payload)
@@ -283,7 +283,7 @@ func assertSuccess(_ decoder: @autoclosure () throws -> Payload, closure:((Paylo
283
283
}
284
284
}
285
285
286
- func assertFailure( _ decoder: @autoclosure ( ) throws -> Payload , closure: ( ( InvalidToken ) -> ( ) ) ? = nil ) {
286
+ func assertFailure( _ decoder: @autoclosure ( ) throws -> Payload , closure: ( ( InvalidToken ) -> Void ) ? = nil ) {
287
287
do {
288
288
_ = try decoder ( )
289
289
XCTFail ( " Decoding succeeded, expected a failure. " )
@@ -294,7 +294,7 @@ func assertFailure(_ decoder: @autoclosure () throws -> Payload, closure:((Inval
294
294
}
295
295
}
296
296
297
- func assertDecodeError( _ decoder: @autoclosure ( ) throws -> Payload , error: String ) {
297
+ func assertDecodeError( _ decoder: @autoclosure ( ) throws -> Payload , error: String ) {
298
298
assertFailure ( try decoder ( ) ) { failure in
299
299
switch failure {
300
300
case . decodeError( let decodeError) :
0 commit comments