From 1173f4e8cecc7705e4d6007192b74071dca62bde Mon Sep 17 00:00:00 2001 From: Alessio Buratti <9006089+Buratti@users.noreply.github.com> Date: Tue, 28 May 2024 14:34:36 +0200 Subject: [PATCH 1/7] Add support for multi-resource statements --- .../APIGatewayLambdaAuthorizers.swift | 10 ++++-- .../APIGatewayLambdaAuthorizerTest.swift | 34 ++++++++++++++++++- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/Sources/AWSLambdaEvents/APIGatewayLambdaAuthorizers.swift b/Sources/AWSLambdaEvents/APIGatewayLambdaAuthorizers.swift index 25a0ed3..b91911f 100644 --- a/Sources/AWSLambdaEvents/APIGatewayLambdaAuthorizers.swift +++ b/Sources/AWSLambdaEvents/APIGatewayLambdaAuthorizers.swift @@ -81,11 +81,17 @@ public struct APIGatewayLambdaAuthorizerPolicyResponse: Codable { case deny = "Deny" } - public let action: String + public let action: [String] public let effect: Effect - public let resource: String + public let resource: [String] public init(action: String, effect: Effect, resource: String) { + self.action = [action] + self.effect = effect + self.resource = [resource] + } + + public init(action: [String], effect: Effect, resource: [String]) { self.action = action self.effect = effect self.resource = resource diff --git a/Tests/AWSLambdaEventsTests/APIGatewayLambdaAuthorizerTest.swift b/Tests/AWSLambdaEventsTests/APIGatewayLambdaAuthorizerTest.swift index ea4dcc6..fc1bda0 100644 --- a/Tests/AWSLambdaEventsTests/APIGatewayLambdaAuthorizerTest.swift +++ b/Tests/AWSLambdaEventsTests/APIGatewayLambdaAuthorizerTest.swift @@ -201,7 +201,39 @@ class APIGatewayLambdaAuthorizerTests: XCTestCase { XCTAssertEqual(resp.principalId, "John Appleseed") XCTAssertEqual(resp.policyDocument.statement.count, 1) - XCTAssertEqual(resp.policyDocument.statement[0].action, "s3:getObject") + XCTAssertEqual(resp.policyDocument.statement[0].action, ["s3:getObject"]) + XCTAssertEqual(resp.context?.count, 2) + XCTAssertEqual(resp.context?["abc1"], "xyz1") + } + + func testDecodingLambdaAuthorizerPolicyResponseWithMultipleResources() { + let statement = APIGatewayLambdaAuthorizerPolicyResponse.PolicyDocument.Statement(action: ["execute-api:Invoke"], + effect: .allow, + resource: [ + "arn:aws:execute-api:*:*:*/*/GET/v1/user/0123", + "arn:aws:execute-api:*:*:*/*/POST/v1/user", + ]) + let policy = APIGatewayLambdaAuthorizerPolicyResponse.PolicyDocument(statement: [statement]) + var resp = APIGatewayLambdaAuthorizerPolicyResponse(principalId: "John Appleseed", + policyDocument: policy, + context: ["abc1": "xyz1", "abc2": "xyz2"]) + + var data: Data? + XCTAssertNoThrow(data = try JSONEncoder().encode(resp)) + + var stringData: String? + XCTAssertNoThrow(stringData = String(data: try XCTUnwrap(data), encoding: .utf8)) + + data = stringData?.data(using: .utf8) + XCTAssertNoThrow(resp = try JSONDecoder().decode(APIGatewayLambdaAuthorizerPolicyResponse.self, from: XCTUnwrap(data))) + + XCTAssertEqual(resp.principalId, "John Appleseed") + XCTAssertEqual(resp.policyDocument.statement.count, 1) + XCTAssertEqual(resp.policyDocument.statement[0].action, ["execute-api:Invoke"]) + XCTAssertEqual(resp.policyDocument.statement[0].resource, [ + "arn:aws:execute-api:*:*:*/*/GET/v1/user/0123", + "arn:aws:execute-api:*:*:*/*/POST/v1/user", + ]) XCTAssertEqual(resp.context?.count, 2) XCTAssertEqual(resp.context?["abc1"], "xyz1") } From 9b732b76eda0f017f4ef74253620c0f2bf6af76d Mon Sep 17 00:00:00 2001 From: Alessio Buratti <9006089+Buratti@users.noreply.github.com> Date: Tue, 28 May 2024 20:28:20 +0200 Subject: [PATCH 2/7] Removes duplicated code of APIGatewayLambdaAuthorizerPolicyResponse.init --- Sources/AWSLambdaEvents/Cloudwatch.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/AWSLambdaEvents/Cloudwatch.swift b/Sources/AWSLambdaEvents/Cloudwatch.swift index e2160c2..9739bea 100644 --- a/Sources/AWSLambdaEvents/Cloudwatch.swift +++ b/Sources/AWSLambdaEvents/Cloudwatch.swift @@ -63,7 +63,7 @@ public struct CloudwatchEvent: Decodable { self.id = try container.decode(String.self, forKey: .id) self.source = try container.decode(String.self, forKey: .source) self.accountId = try container.decode(String.self, forKey: .accountId) - self.time = (try container.decode(ISO8601Coding.self, forKey: .time)).wrappedValue + self.time = try (container.decode(ISO8601Coding.self, forKey: .time)).wrappedValue self.region = try container.decode(AWSRegion.self, forKey: .region) self.resources = try container.decode([String].self, forKey: .resources) From 09080514e7fd654a8c62883746c44691f520dd3c Mon Sep 17 00:00:00 2001 From: Alessio Buratti <9006089+Buratti@users.noreply.github.com> Date: Tue, 28 May 2024 20:28:27 +0200 Subject: [PATCH 3/7] Run swiftformat --- .../APIGatewayLambdaAuthorizers.swift | 10 ++++++---- Sources/AWSLambdaEvents/DynamoDB.swift | 4 ++-- Sources/AWSLambdaEvents/Utils/HTTP.swift | 4 ++-- .../APIGatewayLambdaAuthorizerTest.swift | 14 +++++++------- .../AWSLambdaEventsTests/CloudFormationTests.swift | 2 +- 5 files changed, 18 insertions(+), 16 deletions(-) diff --git a/Sources/AWSLambdaEvents/APIGatewayLambdaAuthorizers.swift b/Sources/AWSLambdaEvents/APIGatewayLambdaAuthorizers.swift index b91911f..7f699d8 100644 --- a/Sources/AWSLambdaEvents/APIGatewayLambdaAuthorizers.swift +++ b/Sources/AWSLambdaEvents/APIGatewayLambdaAuthorizers.swift @@ -86,11 +86,13 @@ public struct APIGatewayLambdaAuthorizerPolicyResponse: Codable { public let resource: [String] public init(action: String, effect: Effect, resource: String) { - self.action = [action] - self.effect = effect - self.resource = [resource] + self.init( + action: [action], + effect: effect, + resource: [resource] + ) } - + public init(action: [String], effect: Effect, resource: [String]) { self.action = action self.effect = effect diff --git a/Sources/AWSLambdaEvents/DynamoDB.swift b/Sources/AWSLambdaEvents/DynamoDB.swift index 71ff22e..f595210 100644 --- a/Sources/AWSLambdaEvents/DynamoDB.swift +++ b/Sources/AWSLambdaEvents/DynamoDB.swift @@ -234,7 +234,7 @@ extension DynamoDBEvent.AttributeValue: Decodable { switch key { case .binary: let encoded = try container.decode(String.self, forKey: .binary) - self = .binary(try encoded.base64decoded()) + self = try .binary(encoded.base64decoded()) case .bool: let value = try container.decode(Bool.self, forKey: .bool) @@ -324,7 +324,7 @@ extension DynamoDBEvent { } } - @usableFromInline internal struct _DecoderImpl: Swift.Decoder { + @usableFromInline struct _DecoderImpl: Swift.Decoder { @usableFromInline let codingPath: [CodingKey] @usableFromInline let userInfo: [CodingUserInfoKey: Any] diff --git a/Sources/AWSLambdaEvents/Utils/HTTP.swift b/Sources/AWSLambdaEvents/Utils/HTTP.swift index f37fa17..6e5843d 100644 --- a/Sources/AWSLambdaEvents/Utils/HTTP.swift +++ b/Sources/AWSLambdaEvents/Utils/HTTP.swift @@ -35,7 +35,7 @@ extension HTTPHeaders { } extension String { - internal func isEqualCaseInsensitiveASCIIBytes(to: String) -> Bool { + func isEqualCaseInsensitiveASCIIBytes(to: String) -> Bool { self.utf8.compareCaseInsensitiveASCIIBytes(to: to.utf8) } } @@ -48,7 +48,7 @@ extension String.UTF8View { /// /// - Parameter bytes: The string constant in the form of a collection of `UInt8` /// - Returns: Whether the collection contains **EXACTLY** this array or no, but by ignoring case. - internal func compareCaseInsensitiveASCIIBytes(to: String.UTF8View) -> Bool { + func compareCaseInsensitiveASCIIBytes(to: String.UTF8View) -> Bool { // fast path: we can get the underlying bytes of both let maybeMaybeResult = self.withContiguousStorageIfAvailable { lhsBuffer -> Bool? in to.withContiguousStorageIfAvailable { rhsBuffer in diff --git a/Tests/AWSLambdaEventsTests/APIGatewayLambdaAuthorizerTest.swift b/Tests/AWSLambdaEventsTests/APIGatewayLambdaAuthorizerTest.swift index fc1bda0..c141c57 100644 --- a/Tests/AWSLambdaEventsTests/APIGatewayLambdaAuthorizerTest.swift +++ b/Tests/AWSLambdaEventsTests/APIGatewayLambdaAuthorizerTest.swift @@ -171,7 +171,7 @@ class APIGatewayLambdaAuthorizerTests: XCTestCase { XCTAssertNoThrow(data = try JSONEncoder().encode(resp)) var stringData: String? - XCTAssertNoThrow(stringData = String(data: try XCTUnwrap(data), encoding: .utf8)) + XCTAssertNoThrow(stringData = try String(data: XCTUnwrap(data), encoding: .utf8)) data = stringData?.data(using: .utf8) XCTAssertNoThrow(resp = try JSONDecoder().decode(APIGatewayLambdaAuthorizerSimpleResponse.self, from: XCTUnwrap(data))) @@ -194,7 +194,7 @@ class APIGatewayLambdaAuthorizerTests: XCTestCase { XCTAssertNoThrow(data = try JSONEncoder().encode(resp)) var stringData: String? - XCTAssertNoThrow(stringData = String(data: try XCTUnwrap(data), encoding: .utf8)) + XCTAssertNoThrow(stringData = try String(data: XCTUnwrap(data), encoding: .utf8)) data = stringData?.data(using: .utf8) XCTAssertNoThrow(resp = try JSONDecoder().decode(APIGatewayLambdaAuthorizerPolicyResponse.self, from: XCTUnwrap(data))) @@ -205,13 +205,13 @@ class APIGatewayLambdaAuthorizerTests: XCTestCase { XCTAssertEqual(resp.context?.count, 2) XCTAssertEqual(resp.context?["abc1"], "xyz1") } - + func testDecodingLambdaAuthorizerPolicyResponseWithMultipleResources() { let statement = APIGatewayLambdaAuthorizerPolicyResponse.PolicyDocument.Statement(action: ["execute-api:Invoke"], effect: .allow, resource: [ - "arn:aws:execute-api:*:*:*/*/GET/v1/user/0123", - "arn:aws:execute-api:*:*:*/*/POST/v1/user", + "arn:aws:execute-api:*:*:*/*/GET/v1/user/0123", + "arn:aws:execute-api:*:*:*/*/POST/v1/user", ]) let policy = APIGatewayLambdaAuthorizerPolicyResponse.PolicyDocument(statement: [statement]) var resp = APIGatewayLambdaAuthorizerPolicyResponse(principalId: "John Appleseed", @@ -222,7 +222,7 @@ class APIGatewayLambdaAuthorizerTests: XCTestCase { XCTAssertNoThrow(data = try JSONEncoder().encode(resp)) var stringData: String? - XCTAssertNoThrow(stringData = String(data: try XCTUnwrap(data), encoding: .utf8)) + XCTAssertNoThrow(stringData = try String(data: XCTUnwrap(data), encoding: .utf8)) data = stringData?.data(using: .utf8) XCTAssertNoThrow(resp = try JSONDecoder().decode(APIGatewayLambdaAuthorizerPolicyResponse.self, from: XCTUnwrap(data))) @@ -233,7 +233,7 @@ class APIGatewayLambdaAuthorizerTests: XCTestCase { XCTAssertEqual(resp.policyDocument.statement[0].resource, [ "arn:aws:execute-api:*:*:*/*/GET/v1/user/0123", "arn:aws:execute-api:*:*:*/*/POST/v1/user", - ]) + ]) XCTAssertEqual(resp.context?.count, 2) XCTAssertEqual(resp.context?["abc1"], "xyz1") } diff --git a/Tests/AWSLambdaEventsTests/CloudFormationTests.swift b/Tests/AWSLambdaEventsTests/CloudFormationTests.swift index 8343248..390fb9e 100644 --- a/Tests/AWSLambdaEventsTests/CloudFormationTests.swift +++ b/Tests/AWSLambdaEventsTests/CloudFormationTests.swift @@ -178,7 +178,7 @@ class CloudFormationTests: XCTestCase { XCTAssertNoThrow(data = try encoder.encode(resp)) var stringData: String? - XCTAssertNoThrow(stringData = String(data: try XCTUnwrap(data), encoding: .utf8)) + XCTAssertNoThrow(stringData = try String(data: XCTUnwrap(data), encoding: .utf8)) print(stringData ?? "") From 71b2a01604df4ad05bf4b44e2876576b132c1d68 Mon Sep 17 00:00:00 2001 From: Alessio Buratti <9006089+Buratti@users.noreply.github.com> Date: Wed, 29 May 2024 19:01:27 +0200 Subject: [PATCH 4/7] Revert "Run swiftformat" This reverts commit 09080514e7fd654a8c62883746c44691f520dd3c. --- .../APIGatewayLambdaAuthorizers.swift | 10 ++++------ Sources/AWSLambdaEvents/DynamoDB.swift | 4 ++-- Sources/AWSLambdaEvents/Utils/HTTP.swift | 4 ++-- .../APIGatewayLambdaAuthorizerTest.swift | 14 +++++++------- .../AWSLambdaEventsTests/CloudFormationTests.swift | 2 +- 5 files changed, 16 insertions(+), 18 deletions(-) diff --git a/Sources/AWSLambdaEvents/APIGatewayLambdaAuthorizers.swift b/Sources/AWSLambdaEvents/APIGatewayLambdaAuthorizers.swift index fab1679..e8ee80b 100644 --- a/Sources/AWSLambdaEvents/APIGatewayLambdaAuthorizers.swift +++ b/Sources/AWSLambdaEvents/APIGatewayLambdaAuthorizers.swift @@ -86,13 +86,11 @@ public struct APIGatewayLambdaAuthorizerPolicyResponse: Codable, Sendable { public let resource: [String] public init(action: String, effect: Effect, resource: String) { - self.init( - action: [action], - effect: effect, - resource: [resource] - ) + self.action = [action] + self.effect = effect + self.resource = [resource] } - + public init(action: [String], effect: Effect, resource: [String]) { self.action = action self.effect = effect diff --git a/Sources/AWSLambdaEvents/DynamoDB.swift b/Sources/AWSLambdaEvents/DynamoDB.swift index 9d788e0..438b920 100644 --- a/Sources/AWSLambdaEvents/DynamoDB.swift +++ b/Sources/AWSLambdaEvents/DynamoDB.swift @@ -234,7 +234,7 @@ extension DynamoDBEvent.AttributeValue: Decodable { switch key { case .binary: let encoded = try container.decode(String.self, forKey: .binary) - self = try .binary(encoded.base64decoded()) + self = .binary(try encoded.base64decoded()) case .bool: let value = try container.decode(Bool.self, forKey: .bool) @@ -324,7 +324,7 @@ extension DynamoDBEvent { } } - @usableFromInline struct _DecoderImpl: Swift.Decoder { + @usableFromInline internal struct _DecoderImpl: Swift.Decoder { @usableFromInline let codingPath: [CodingKey] @usableFromInline let userInfo: [CodingUserInfoKey: Any] diff --git a/Sources/AWSLambdaEvents/Utils/HTTP.swift b/Sources/AWSLambdaEvents/Utils/HTTP.swift index 6e5843d..f37fa17 100644 --- a/Sources/AWSLambdaEvents/Utils/HTTP.swift +++ b/Sources/AWSLambdaEvents/Utils/HTTP.swift @@ -35,7 +35,7 @@ extension HTTPHeaders { } extension String { - func isEqualCaseInsensitiveASCIIBytes(to: String) -> Bool { + internal func isEqualCaseInsensitiveASCIIBytes(to: String) -> Bool { self.utf8.compareCaseInsensitiveASCIIBytes(to: to.utf8) } } @@ -48,7 +48,7 @@ extension String.UTF8View { /// /// - Parameter bytes: The string constant in the form of a collection of `UInt8` /// - Returns: Whether the collection contains **EXACTLY** this array or no, but by ignoring case. - func compareCaseInsensitiveASCIIBytes(to: String.UTF8View) -> Bool { + internal func compareCaseInsensitiveASCIIBytes(to: String.UTF8View) -> Bool { // fast path: we can get the underlying bytes of both let maybeMaybeResult = self.withContiguousStorageIfAvailable { lhsBuffer -> Bool? in to.withContiguousStorageIfAvailable { rhsBuffer in diff --git a/Tests/AWSLambdaEventsTests/APIGatewayLambdaAuthorizerTest.swift b/Tests/AWSLambdaEventsTests/APIGatewayLambdaAuthorizerTest.swift index c141c57..fc1bda0 100644 --- a/Tests/AWSLambdaEventsTests/APIGatewayLambdaAuthorizerTest.swift +++ b/Tests/AWSLambdaEventsTests/APIGatewayLambdaAuthorizerTest.swift @@ -171,7 +171,7 @@ class APIGatewayLambdaAuthorizerTests: XCTestCase { XCTAssertNoThrow(data = try JSONEncoder().encode(resp)) var stringData: String? - XCTAssertNoThrow(stringData = try String(data: XCTUnwrap(data), encoding: .utf8)) + XCTAssertNoThrow(stringData = String(data: try XCTUnwrap(data), encoding: .utf8)) data = stringData?.data(using: .utf8) XCTAssertNoThrow(resp = try JSONDecoder().decode(APIGatewayLambdaAuthorizerSimpleResponse.self, from: XCTUnwrap(data))) @@ -194,7 +194,7 @@ class APIGatewayLambdaAuthorizerTests: XCTestCase { XCTAssertNoThrow(data = try JSONEncoder().encode(resp)) var stringData: String? - XCTAssertNoThrow(stringData = try String(data: XCTUnwrap(data), encoding: .utf8)) + XCTAssertNoThrow(stringData = String(data: try XCTUnwrap(data), encoding: .utf8)) data = stringData?.data(using: .utf8) XCTAssertNoThrow(resp = try JSONDecoder().decode(APIGatewayLambdaAuthorizerPolicyResponse.self, from: XCTUnwrap(data))) @@ -205,13 +205,13 @@ class APIGatewayLambdaAuthorizerTests: XCTestCase { XCTAssertEqual(resp.context?.count, 2) XCTAssertEqual(resp.context?["abc1"], "xyz1") } - + func testDecodingLambdaAuthorizerPolicyResponseWithMultipleResources() { let statement = APIGatewayLambdaAuthorizerPolicyResponse.PolicyDocument.Statement(action: ["execute-api:Invoke"], effect: .allow, resource: [ - "arn:aws:execute-api:*:*:*/*/GET/v1/user/0123", - "arn:aws:execute-api:*:*:*/*/POST/v1/user", + "arn:aws:execute-api:*:*:*/*/GET/v1/user/0123", + "arn:aws:execute-api:*:*:*/*/POST/v1/user", ]) let policy = APIGatewayLambdaAuthorizerPolicyResponse.PolicyDocument(statement: [statement]) var resp = APIGatewayLambdaAuthorizerPolicyResponse(principalId: "John Appleseed", @@ -222,7 +222,7 @@ class APIGatewayLambdaAuthorizerTests: XCTestCase { XCTAssertNoThrow(data = try JSONEncoder().encode(resp)) var stringData: String? - XCTAssertNoThrow(stringData = try String(data: XCTUnwrap(data), encoding: .utf8)) + XCTAssertNoThrow(stringData = String(data: try XCTUnwrap(data), encoding: .utf8)) data = stringData?.data(using: .utf8) XCTAssertNoThrow(resp = try JSONDecoder().decode(APIGatewayLambdaAuthorizerPolicyResponse.self, from: XCTUnwrap(data))) @@ -233,7 +233,7 @@ class APIGatewayLambdaAuthorizerTests: XCTestCase { XCTAssertEqual(resp.policyDocument.statement[0].resource, [ "arn:aws:execute-api:*:*:*/*/GET/v1/user/0123", "arn:aws:execute-api:*:*:*/*/POST/v1/user", - ]) + ]) XCTAssertEqual(resp.context?.count, 2) XCTAssertEqual(resp.context?["abc1"], "xyz1") } diff --git a/Tests/AWSLambdaEventsTests/CloudFormationTests.swift b/Tests/AWSLambdaEventsTests/CloudFormationTests.swift index 390fb9e..8343248 100644 --- a/Tests/AWSLambdaEventsTests/CloudFormationTests.swift +++ b/Tests/AWSLambdaEventsTests/CloudFormationTests.swift @@ -178,7 +178,7 @@ class CloudFormationTests: XCTestCase { XCTAssertNoThrow(data = try encoder.encode(resp)) var stringData: String? - XCTAssertNoThrow(stringData = try String(data: XCTUnwrap(data), encoding: .utf8)) + XCTAssertNoThrow(stringData = String(data: try XCTUnwrap(data), encoding: .utf8)) print(stringData ?? "") From 4d0bfc88ee4b0a733a617f8d3eba310692759aa2 Mon Sep 17 00:00:00 2001 From: Alessio Buratti <9006089+Buratti@users.noreply.github.com> Date: Wed, 29 May 2024 19:01:42 +0200 Subject: [PATCH 5/7] Revert "Removes duplicated code of APIGatewayLambdaAuthorizerPolicyResponse.init" This reverts commit 9b732b76eda0f017f4ef74253620c0f2bf6af76d. --- Sources/AWSLambdaEvents/Cloudwatch.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/AWSLambdaEvents/Cloudwatch.swift b/Sources/AWSLambdaEvents/Cloudwatch.swift index f696dcc..d814266 100644 --- a/Sources/AWSLambdaEvents/Cloudwatch.swift +++ b/Sources/AWSLambdaEvents/Cloudwatch.swift @@ -64,7 +64,7 @@ public struct CloudwatchEvent: Decodable, Sendable { self.id = try container.decode(String.self, forKey: .id) self.source = try container.decode(String.self, forKey: .source) self.accountId = try container.decode(String.self, forKey: .accountId) - self.time = try (container.decode(ISO8601Coding.self, forKey: .time)).wrappedValue + self.time = (try container.decode(ISO8601Coding.self, forKey: .time)).wrappedValue self.region = try container.decode(AWSRegion.self, forKey: .region) self.resources = try container.decode([String].self, forKey: .resources) From f6e1421f597e3411d962bb8a449ff23aa60cf7fa Mon Sep 17 00:00:00 2001 From: Alessio Buratti <9006089+Buratti@users.noreply.github.com> Date: Wed, 29 May 2024 19:03:15 +0200 Subject: [PATCH 6/7] Removes duplicated initializers implementation --- Sources/AWSLambdaEvents/APIGatewayLambdaAuthorizers.swift | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Sources/AWSLambdaEvents/APIGatewayLambdaAuthorizers.swift b/Sources/AWSLambdaEvents/APIGatewayLambdaAuthorizers.swift index e8ee80b..1a2ed50 100644 --- a/Sources/AWSLambdaEvents/APIGatewayLambdaAuthorizers.swift +++ b/Sources/AWSLambdaEvents/APIGatewayLambdaAuthorizers.swift @@ -86,9 +86,11 @@ public struct APIGatewayLambdaAuthorizerPolicyResponse: Codable, Sendable { public let resource: [String] public init(action: String, effect: Effect, resource: String) { - self.action = [action] - self.effect = effect - self.resource = [resource] + self.init( + action: [action], + effect: effect, + resource: [resource] + ) } public init(action: [String], effect: Effect, resource: [String]) { From bde0aa50bb7f60fe2654fa0a34acacae1cd15c24 Mon Sep 17 00:00:00 2001 From: Alessio Buratti <9006089+Buratti@users.noreply.github.com> Date: Wed, 29 May 2024 19:53:04 +0200 Subject: [PATCH 7/7] Run swiftformat on changed files --- .../APIGatewayLambdaAuthorizers.swift | 2 +- .../APIGatewayLambdaAuthorizerTest.swift | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Sources/AWSLambdaEvents/APIGatewayLambdaAuthorizers.swift b/Sources/AWSLambdaEvents/APIGatewayLambdaAuthorizers.swift index 1a2ed50..fab1679 100644 --- a/Sources/AWSLambdaEvents/APIGatewayLambdaAuthorizers.swift +++ b/Sources/AWSLambdaEvents/APIGatewayLambdaAuthorizers.swift @@ -92,7 +92,7 @@ public struct APIGatewayLambdaAuthorizerPolicyResponse: Codable, Sendable { resource: [resource] ) } - + public init(action: [String], effect: Effect, resource: [String]) { self.action = action self.effect = effect diff --git a/Tests/AWSLambdaEventsTests/APIGatewayLambdaAuthorizerTest.swift b/Tests/AWSLambdaEventsTests/APIGatewayLambdaAuthorizerTest.swift index fc1bda0..c141c57 100644 --- a/Tests/AWSLambdaEventsTests/APIGatewayLambdaAuthorizerTest.swift +++ b/Tests/AWSLambdaEventsTests/APIGatewayLambdaAuthorizerTest.swift @@ -171,7 +171,7 @@ class APIGatewayLambdaAuthorizerTests: XCTestCase { XCTAssertNoThrow(data = try JSONEncoder().encode(resp)) var stringData: String? - XCTAssertNoThrow(stringData = String(data: try XCTUnwrap(data), encoding: .utf8)) + XCTAssertNoThrow(stringData = try String(data: XCTUnwrap(data), encoding: .utf8)) data = stringData?.data(using: .utf8) XCTAssertNoThrow(resp = try JSONDecoder().decode(APIGatewayLambdaAuthorizerSimpleResponse.self, from: XCTUnwrap(data))) @@ -194,7 +194,7 @@ class APIGatewayLambdaAuthorizerTests: XCTestCase { XCTAssertNoThrow(data = try JSONEncoder().encode(resp)) var stringData: String? - XCTAssertNoThrow(stringData = String(data: try XCTUnwrap(data), encoding: .utf8)) + XCTAssertNoThrow(stringData = try String(data: XCTUnwrap(data), encoding: .utf8)) data = stringData?.data(using: .utf8) XCTAssertNoThrow(resp = try JSONDecoder().decode(APIGatewayLambdaAuthorizerPolicyResponse.self, from: XCTUnwrap(data))) @@ -205,13 +205,13 @@ class APIGatewayLambdaAuthorizerTests: XCTestCase { XCTAssertEqual(resp.context?.count, 2) XCTAssertEqual(resp.context?["abc1"], "xyz1") } - + func testDecodingLambdaAuthorizerPolicyResponseWithMultipleResources() { let statement = APIGatewayLambdaAuthorizerPolicyResponse.PolicyDocument.Statement(action: ["execute-api:Invoke"], effect: .allow, resource: [ - "arn:aws:execute-api:*:*:*/*/GET/v1/user/0123", - "arn:aws:execute-api:*:*:*/*/POST/v1/user", + "arn:aws:execute-api:*:*:*/*/GET/v1/user/0123", + "arn:aws:execute-api:*:*:*/*/POST/v1/user", ]) let policy = APIGatewayLambdaAuthorizerPolicyResponse.PolicyDocument(statement: [statement]) var resp = APIGatewayLambdaAuthorizerPolicyResponse(principalId: "John Appleseed", @@ -222,7 +222,7 @@ class APIGatewayLambdaAuthorizerTests: XCTestCase { XCTAssertNoThrow(data = try JSONEncoder().encode(resp)) var stringData: String? - XCTAssertNoThrow(stringData = String(data: try XCTUnwrap(data), encoding: .utf8)) + XCTAssertNoThrow(stringData = try String(data: XCTUnwrap(data), encoding: .utf8)) data = stringData?.data(using: .utf8) XCTAssertNoThrow(resp = try JSONDecoder().decode(APIGatewayLambdaAuthorizerPolicyResponse.self, from: XCTUnwrap(data))) @@ -233,7 +233,7 @@ class APIGatewayLambdaAuthorizerTests: XCTestCase { XCTAssertEqual(resp.policyDocument.statement[0].resource, [ "arn:aws:execute-api:*:*:*/*/GET/v1/user/0123", "arn:aws:execute-api:*:*:*/*/POST/v1/user", - ]) + ]) XCTAssertEqual(resp.context?.count, 2) XCTAssertEqual(resp.context?["abc1"], "xyz1") }