@@ -17,30 +17,30 @@ class EncodeTests: XCTestCase {
17
17
}
18
18
19
19
assertSuccess ( try JWT . decode ( jwt, algorithm: algorithm) ) { payload in
20
- XCTAssertEqual ( payload as NSDictionary , [ " iss " : " fuller.li " ] )
20
+ XCTAssertEqual ( payload as! [ String : String ] , [ " iss " : " fuller.li " ] )
21
21
}
22
22
}
23
23
}
24
24
25
25
class PayloadTests : XCTestCase {
26
26
func testIssuer( ) {
27
- JWT . encode ( . none) { builder in
27
+ _ = JWT . encode ( . none) { builder in
28
28
builder. issuer = " fuller.li "
29
29
XCTAssertEqual ( builder. issuer, " fuller.li " )
30
30
XCTAssertEqual ( builder [ " iss " ] as? String , " fuller.li " )
31
31
}
32
32
}
33
33
34
34
func testAudience( ) {
35
- JWT . encode ( . none) { builder in
35
+ _ = JWT . encode ( . none) { builder in
36
36
builder. audience = " cocoapods "
37
37
XCTAssertEqual ( builder. audience, " cocoapods " )
38
38
XCTAssertEqual ( builder [ " aud " ] as? String , " cocoapods " )
39
39
}
40
40
}
41
41
42
42
func testExpiration( ) {
43
- JWT . encode ( . none) { builder in
43
+ _ = JWT . encode ( . none) { builder in
44
44
let date = Date ( timeIntervalSince1970: Date ( ) . timeIntervalSince1970)
45
45
builder. expiration = date
46
46
XCTAssertEqual ( builder. expiration, date)
@@ -49,7 +49,7 @@ class PayloadTests: XCTestCase {
49
49
}
50
50
51
51
func testNotBefore( ) {
52
- JWT . encode ( . none) { builder in
52
+ _ = JWT . encode ( . none) { builder in
53
53
let date = Date ( timeIntervalSince1970: Date ( ) . timeIntervalSince1970)
54
54
builder. notBefore = date
55
55
XCTAssertEqual ( builder. notBefore, date)
@@ -58,7 +58,7 @@ class PayloadTests: XCTestCase {
58
58
}
59
59
60
60
func testIssuedAt( ) {
61
- JWT . encode ( . none) { builder in
61
+ _ = JWT . encode ( . none) { builder in
62
62
let date = Date ( timeIntervalSince1970: Date ( ) . timeIntervalSince1970)
63
63
builder. issuedAt = date
64
64
XCTAssertEqual ( builder. issuedAt, date)
@@ -67,7 +67,7 @@ class PayloadTests: XCTestCase {
67
67
}
68
68
69
69
func testCustomAttributes( ) {
70
- JWT . encode ( . none) { builder in
70
+ _ = JWT . encode ( . none) { builder in
71
71
builder [ " user " ] = " kyle "
72
72
XCTAssertEqual ( builder [ " user " ] as? String , " kyle " )
73
73
}
@@ -79,7 +79,7 @@ class DecodeTests: XCTestCase {
79
79
let jwt = " eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiS3lsZSJ9.zxm7xcp1eZtZhp4t-nlw09ATQnnFKIiSN83uG8u6cAg "
80
80
81
81
assertSuccess ( try JWT . decode ( jwt, algorithm: . hs256( " secret " . data ( using: . utf8) !) ) ) { payload in
82
- XCTAssertEqual ( payload as NSDictionary , [ " name " : " Kyle " ] )
82
+ XCTAssertEqual ( payload as! [ String : String ] , [ " name " : " Kyle " ] )
83
83
}
84
84
}
85
85
@@ -99,7 +99,7 @@ class DecodeTests: XCTestCase {
99
99
func testSuccessfulIssuerValidation( ) {
100
100
let jwt = " eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJmdWxsZXIubGkifQ.d7B7PAQcz1E6oNhrlxmHxHXHgg39_k7X7wWeahl8kSQ "
101
101
assertSuccess ( try decode ( jwt, algorithm: . hs256( " secret " . data ( using: . utf8) !) , issuer: " fuller.li " ) ) { payload in
102
- XCTAssertEqual ( payload as NSDictionary , [ " iss " : " fuller.li " ] )
102
+ XCTAssertEqual ( payload as! [ String : String ] , [ " iss " : " fuller.li " ] )
103
103
}
104
104
}
105
105
@@ -129,15 +129,15 @@ class DecodeTests: XCTestCase {
129
129
// If this just started failing, hello 2024!
130
130
let jwt = " eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MjgxODg0OTF9.EW7k-8Mvnv0GpvOKJalFRLoCB3a3xGG3i7hAZZXNAz0 "
131
131
assertSuccess ( try decode ( jwt, algorithm: . hs256( " secret " . data ( using: . utf8) !) ) ) { payload in
132
- XCTAssertEqual ( payload as NSDictionary , [ " exp " : 1728188491 ] )
132
+ XCTAssertEqual ( payload as! [ String : Int ] , [ " exp " : 1728188491 ] )
133
133
}
134
134
}
135
135
136
136
func testUnexpiredClaimString( ) {
137
137
// If this just started failing, hello 2024!
138
138
let jwt = " eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOiIxNzI4MTg4NDkxIn0.y4w7lNLrfRRPzuNUfM-ZvPkoOtrTU_d8ZVYasLdZGpk "
139
139
assertSuccess ( try decode ( jwt, algorithm: . hs256( " secret " . data ( using: . utf8) !) ) ) { payload in
140
- XCTAssertEqual ( payload as NSDictionary , [ " exp " : " 1728188491 " ] )
140
+ XCTAssertEqual ( payload as! [ String : String ] , [ " exp " : " 1728188491 " ] )
141
141
}
142
142
}
143
143
@@ -146,14 +146,14 @@ class DecodeTests: XCTestCase {
146
146
func testNotBeforeClaim( ) {
147
147
let jwt = " eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE0MjgxODk3MjB9.jFT0nXAJvEwyG6R7CMJlzNJb7FtZGv30QRZpYam5cvs "
148
148
assertSuccess ( try decode ( jwt, algorithm: . hs256( " secret " . data ( using: . utf8) !) ) ) { payload in
149
- XCTAssertEqual ( payload as NSDictionary , [ " nbf " : 1428189720 ] )
149
+ XCTAssertEqual ( payload as! [ String : Int ] , [ " nbf " : 1428189720 ] )
150
150
}
151
151
}
152
152
153
153
func testNotBeforeClaimString( ) {
154
154
let jwt = " eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOiIxNDI4MTg5NzIwIn0.qZsj36irdmIAeXv6YazWDSFbpuxHtEh4Deof5YTpnVI "
155
155
assertSuccess ( try decode ( jwt, algorithm: . hs256( " secret " . data ( using: . utf8) !) ) ) { payload in
156
- XCTAssertEqual ( payload as NSDictionary , [ " nbf " : " 1428189720 " ] )
156
+ XCTAssertEqual ( payload as! [ String : String ] , [ " nbf " : " 1428189720 " ] )
157
157
}
158
158
}
159
159
@@ -173,14 +173,14 @@ class DecodeTests: XCTestCase {
173
173
func testIssuedAtClaimInThePast( ) {
174
174
let jwt = " eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE0MjgxODk3MjB9.I_5qjRcCUZVQdABLwG82CSuu2relSdIyJOyvXWUAJh4 "
175
175
assertSuccess ( try decode ( jwt, algorithm: . hs256( " secret " . data ( using: . utf8) !) ) ) { payload in
176
- XCTAssertEqual ( payload as NSDictionary , [ " iat " : 1428189720 ] )
176
+ XCTAssertEqual ( payload as! [ String : Int ] , [ " iat " : 1428189720 ] )
177
177
}
178
178
}
179
179
180
180
func testIssuedAtClaimInThePastString( ) {
181
181
let jwt = " eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOiIxNDI4MTg5NzIwIn0.M8veWtsY52oBwi7LRKzvNnzhjK0QBS8Su1r0atlns2k "
182
182
assertSuccess ( try decode ( jwt, algorithm: . hs256( " secret " . data ( using: . utf8) !) ) ) { payload in
183
- XCTAssertEqual ( payload as NSDictionary , [ " iat " : " 1428189720 " ] )
183
+ XCTAssertEqual ( payload as! [ String : String ] , [ " iat " : " 1428189720 " ] )
184
184
}
185
185
}
186
186
@@ -201,14 +201,15 @@ class DecodeTests: XCTestCase {
201
201
func testAudiencesClaim( ) {
202
202
let jwt = " eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOlsibWF4aW5lIiwia2F0aWUiXX0.-PKvdNLCClrWG7CvesHP6PB0-vxu-_IZcsYhJxBy5JM "
203
203
assertSuccess ( try decode ( jwt, algorithm: . hs256( " secret " . data ( using: . utf8) !) , audience: " maxine " ) ) { payload in
204
- XCTAssertEqual ( payload as NSDictionary , [ " aud " : [ " maxine " , " katie " ] ] )
204
+ XCTAssertEqual ( payload. count, 1 )
205
+ XCTAssertEqual ( payload [ " aud " ] as! [ String ] , [ " maxine " , " katie " ] )
205
206
}
206
207
}
207
208
208
209
func testAudienceClaim( ) {
209
210
let jwt = " eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJreWxlIn0.dpgH4JOwueReaBoanLSxsGTc7AjKUvo7_M1sAfy_xVE "
210
211
assertSuccess ( try decode ( jwt, algorithm: . hs256( " secret " . data ( using: . utf8) !) , audience: " kyle " ) ) { payload in
211
- XCTAssertEqual ( payload as NSDictionary , [ " aud " : " kyle " ] )
212
+ XCTAssertEqual ( payload as! [ String : String ] , [ " aud " : " kyle " ] )
212
213
}
213
214
}
214
215
@@ -227,7 +228,7 @@ class DecodeTests: XCTestCase {
227
228
func testNoneAlgorithm( ) {
228
229
let jwt = " eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.eyJ0ZXN0IjoiaW5nIn0. "
229
230
assertSuccess ( try decode ( jwt, algorithm: . none) ) { payload in
230
- XCTAssertEqual ( payload as NSDictionary , [ " test " : " ing " ] )
231
+ XCTAssertEqual ( payload as! [ String : String ] , [ " test " : " ing " ] )
231
232
}
232
233
}
233
234
@@ -244,14 +245,14 @@ class DecodeTests: XCTestCase {
244
245
func testHS384Algorithm( ) {
245
246
let jwt = " eyJhbGciOiJIUzM4NCIsInR5cCI6IkpXVCJ9.eyJzb21lIjoicGF5bG9hZCJ9.lddiriKLoo42qXduMhCTKZ5Lo3njXxOC92uXyvbLyYKzbq4CVVQOb3MpDwnI19u4 "
246
247
assertSuccess ( try decode ( jwt, algorithm: . hs384( " secret " . data ( using: . utf8) !) ) ) { payload in
247
- XCTAssertEqual ( payload as NSDictionary , [ " some " : " payload " ] )
248
+ XCTAssertEqual ( payload as! [ String : String ] , [ " some " : " payload " ] )
248
249
}
249
250
}
250
251
251
252
func testHS512Algorithm( ) {
252
253
let jwt = " eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJzb21lIjoicGF5bG9hZCJ9.WTzLzFO079PduJiFIyzrOah54YaM8qoxH9fLMQoQhKtw3_fMGjImIOokijDkXVbyfBqhMo2GCNu4w9v7UXvnpA "
253
254
assertSuccess ( try decode ( jwt, algorithm: . hs512( " secret " . data ( using: . utf8) !) ) ) { payload in
254
- XCTAssertEqual ( payload as NSDictionary , [ " some " : " payload " ] )
255
+ XCTAssertEqual ( payload as! [ String : String ] , [ " some " : " payload " ] )
255
256
}
256
257
}
257
258
}
0 commit comments