Skip to content

Commit 8dfdb5b

Browse files
committed
chore: update IAMAuthorizer and integration tests
1 parent 0bdfc21 commit 8dfdb5b

File tree

6 files changed

+248
-18
lines changed

6 files changed

+248
-18
lines changed

Sources/AWSAppSyncApolloExtensions/Authorizers/IAMAuthorizer.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ public class IAMAuthorizer: AppSyncAuthorizer {
1717
}
1818

1919
public func getHttpAuthorizationHeaders(request: URLRequest) async throws -> [String: String] {
20-
try await signRequest(request).allHTTPHeaderFields ?? [:]
20+
var urlRequest = request
21+
urlRequest.setValue(urlRequest.url?.host, forHTTPHeaderField: "host")
22+
return try await signRequest(urlRequest).allHTTPHeaderFields ?? [:]
2123
}
2224

2325
public func getWebsocketConnectionHeaders(endpoint: URL) async throws -> [String: String] {
@@ -49,6 +51,7 @@ public class IAMAuthorizer: AppSyncAuthorizer {
4951
urlRequest.setValue("application/json, text/javascript", forHTTPHeaderField: "accept")
5052
urlRequest.setValue("amz-1.0", forHTTPHeaderField: "content-encoding")
5153
urlRequest.setValue("application/json; charset=UTF-8", forHTTPHeaderField: "Content-Type")
54+
urlRequest.setValue(url.host, forHTTPHeaderField: "host")
5255

5356
urlRequest.httpBody = httpBody
5457
return urlRequest

Tests/AWSAppSyncApolloExtensionsTests/Authorizers/IAMAuthorizerTests.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,27 @@ final class IAMAuthorizerTests: XCTestCase {
1818

1919
func testGetHttpAuthorizationHeaders() async throws {
2020
let headers = try await authorizer.getHttpAuthorizationHeaders(request: APIKeyAuthorizerTests.urlRequest)
21-
XCTAssertEqual(headers.count, 0)
21+
XCTAssertEqual(headers.count, 1)
22+
XCTAssertEqual(headers["Host"], APIKeyAuthorizerTests.urlRequest.url?.host())
2223
}
2324

2425
func testGetWebsocketConnectionHeaders() async throws {
2526
let headers = try await authorizer.getWebsocketConnectionHeaders(endpoint: APIKeyAuthorizerTests.endpoint)
2627

27-
XCTAssertEqual(headers.count, 3)
28+
XCTAssertEqual(headers.count, 4)
2829
XCTAssertEqual(headers["Accept"], "application/json, text/javascript")
2930
XCTAssertEqual(headers["Content-Encoding"], "amz-1.0")
3031
XCTAssertEqual(headers["Content-Type"], "application/json; charset=UTF-8")
32+
XCTAssertEqual(headers["Host"], APIKeyAuthorizerTests.endpoint.host())
3133
}
3234

3335
func testGetWebSocketSubscriptionPayload() async throws {
3436
let headers = try await authorizer.getWebSocketSubscriptionPayload(request: APIKeyAuthorizerTests.urlRequest)
3537

36-
XCTAssertEqual(headers.count, 3)
38+
XCTAssertEqual(headers.count, 4)
3739
XCTAssertEqual(headers["Accept"], "application/json, text/javascript")
3840
XCTAssertEqual(headers["Content-Encoding"], "amz-1.0")
3941
XCTAssertEqual(headers["Content-Type"], "application/json; charset=UTF-8")
42+
XCTAssertEqual(headers["Host"], APIKeyAuthorizerTests.endpoint.host())
4043
}
4144
}

Tests/IntegrationTestApp/IntegrationTestApp.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -581,15 +581,15 @@
581581
repositoryURL = "https://github.com/aws-amplify/amplify-swift.git";
582582
requirement = {
583583
kind = upToNextMajorVersion;
584-
minimumVersion = 2.39.0;
584+
minimumVersion = 2.51.1;
585585
};
586586
};
587587
218CFDFB2C5AD4BB009D70B9 /* XCRemoteSwiftPackageReference "amplify-ui-swift-authenticator" */ = {
588588
isa = XCRemoteSwiftPackageReference;
589589
repositoryURL = "https://github.com/aws-amplify/amplify-ui-swift-authenticator";
590590
requirement = {
591591
kind = upToNextMajorVersion;
592-
minimumVersion = 1.1.5;
592+
minimumVersion = 1.2.3;
593593
};
594594
};
595595
/* End XCRemoteSwiftPackageReference section */

Tests/IntegrationTestApp/IntegrationTestApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 228 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Tests/IntegrationTestApp/IntegrationTestAppTests/AuthTokenTests.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ import XCTest
1818

1919
final class AuthTokenTests: IntegrationTestBase {
2020

21+
override func tearDown() async throws {
22+
await AuthSignInHelper.signOut()
23+
}
24+
2125
func testAuthTokenApolloClientMutation() async throws {
2226
try await signIn()
2327
let completed = expectation(description: "mutation completed")

Tests/IntegrationTestApp/IntegrationTestAppTests/IAMTests.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ import XCTest
1212

1313
final class IAMTests: IntegrationTestBase {
1414

15+
override func tearDown() async throws {
16+
await AuthSignInHelper.signOut()
17+
}
18+
1519
func testAuthTokenApolloClientMutation() async throws {
1620
try await signIn()
1721
let completed = expectation(description: "mutation completed")

0 commit comments

Comments
 (0)