@@ -171,7 +171,7 @@ class APIGatewayLambdaAuthorizerTests: XCTestCase {
171
171
XCTAssertNoThrow ( data = try JSONEncoder ( ) . encode ( resp) )
172
172
173
173
var stringData : String ?
174
- XCTAssertNoThrow ( stringData = String ( data: try XCTUnwrap ( data) , encoding: . utf8) )
174
+ XCTAssertNoThrow ( stringData = try String ( data: XCTUnwrap ( data) , encoding: . utf8) )
175
175
176
176
data = stringData? . data ( using: . utf8)
177
177
XCTAssertNoThrow ( resp = try JSONDecoder ( ) . decode ( APIGatewayLambdaAuthorizerSimpleResponse . self, from: XCTUnwrap ( data) ) )
@@ -194,14 +194,46 @@ class APIGatewayLambdaAuthorizerTests: XCTestCase {
194
194
XCTAssertNoThrow ( data = try JSONEncoder ( ) . encode ( resp) )
195
195
196
196
var stringData : String ?
197
- XCTAssertNoThrow ( stringData = String ( data: try XCTUnwrap ( data) , encoding: . utf8) )
197
+ XCTAssertNoThrow ( stringData = try String ( data: XCTUnwrap ( data) , encoding: . utf8) )
198
198
199
199
data = stringData? . data ( using: . utf8)
200
200
XCTAssertNoThrow ( resp = try JSONDecoder ( ) . decode ( APIGatewayLambdaAuthorizerPolicyResponse . self, from: XCTUnwrap ( data) ) )
201
201
202
202
XCTAssertEqual ( resp. principalId, " John Appleseed " )
203
203
XCTAssertEqual ( resp. policyDocument. statement. count, 1 )
204
- XCTAssertEqual ( resp. policyDocument. statement [ 0 ] . action, " s3:getObject " )
204
+ XCTAssertEqual ( resp. policyDocument. statement [ 0 ] . action, [ " s3:getObject " ] )
205
+ XCTAssertEqual ( resp. context? . count, 2 )
206
+ XCTAssertEqual ( resp. context ? [ " abc1 " ] , " xyz1 " )
207
+ }
208
+
209
+ func testDecodingLambdaAuthorizerPolicyResponseWithMultipleResources( ) {
210
+ let statement = APIGatewayLambdaAuthorizerPolicyResponse . PolicyDocument. Statement ( action: [ " execute-api:Invoke " ] ,
211
+ effect: . allow,
212
+ resource: [
213
+ " arn:aws:execute-api:*:*:*/*/GET/v1/user/0123 " ,
214
+ " arn:aws:execute-api:*:*:*/*/POST/v1/user " ,
215
+ ] )
216
+ let policy = APIGatewayLambdaAuthorizerPolicyResponse . PolicyDocument ( statement: [ statement] )
217
+ var resp = APIGatewayLambdaAuthorizerPolicyResponse ( principalId: " John Appleseed " ,
218
+ policyDocument: policy,
219
+ context: [ " abc1 " : " xyz1 " , " abc2 " : " xyz2 " ] )
220
+
221
+ var data : Data ?
222
+ XCTAssertNoThrow ( data = try JSONEncoder ( ) . encode ( resp) )
223
+
224
+ var stringData : String ?
225
+ XCTAssertNoThrow ( stringData = try String ( data: XCTUnwrap ( data) , encoding: . utf8) )
226
+
227
+ data = stringData? . data ( using: . utf8)
228
+ XCTAssertNoThrow ( resp = try JSONDecoder ( ) . decode ( APIGatewayLambdaAuthorizerPolicyResponse . self, from: XCTUnwrap ( data) ) )
229
+
230
+ XCTAssertEqual ( resp. principalId, " John Appleseed " )
231
+ XCTAssertEqual ( resp. policyDocument. statement. count, 1 )
232
+ XCTAssertEqual ( resp. policyDocument. statement [ 0 ] . action, [ " execute-api:Invoke " ] )
233
+ XCTAssertEqual ( resp. policyDocument. statement [ 0 ] . resource, [
234
+ " arn:aws:execute-api:*:*:*/*/GET/v1/user/0123 " ,
235
+ " arn:aws:execute-api:*:*:*/*/POST/v1/user " ,
236
+ ] )
205
237
XCTAssertEqual ( resp. context? . count, 2 )
206
238
XCTAssertEqual ( resp. context ? [ " abc1 " ] , " xyz1 " )
207
239
}
0 commit comments