From 001c4857978e15e2ce58fb395b9ed1c0de4f489e Mon Sep 17 00:00:00 2001 From: Sebastian Villena <97059974+ruisebas@users.noreply.github.com> Date: Thu, 12 Dec 2024 14:24:52 -0500 Subject: [PATCH] fix(API): Fixing issue with CN endpoints --- .../AppSyncRealTimeClientFactory.swift | 4 +-- .../AppSyncRealTimeClientFactoryTests.swift | 36 +++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/AmplifyPlugins/API/Sources/AWSAPIPlugin/SubscriptionFactory/AppSyncRealTimeClientFactory.swift b/AmplifyPlugins/API/Sources/AWSAPIPlugin/SubscriptionFactory/AppSyncRealTimeClientFactory.swift index 9f30e88c8f..7b8d1b21c9 100644 --- a/AmplifyPlugins/API/Sources/AWSAPIPlugin/SubscriptionFactory/AppSyncRealTimeClientFactory.swift +++ b/AmplifyPlugins/API/Sources/AWSAPIPlugin/SubscriptionFactory/AppSyncRealTimeClientFactory.swift @@ -136,7 +136,7 @@ extension AppSyncRealTimeClientFactory { return url } - guard host.hasSuffix("amazonaws.com") else { + guard host.hasSuffix("amazonaws.com") || host.hasSuffix("amazonaws.com.cn") else { return url.appendingPathComponent("realtime") } @@ -163,7 +163,7 @@ extension AppSyncRealTimeClientFactory { return url } - guard host.hasSuffix("amazonaws.com") else { + guard host.hasSuffix("amazonaws.com") || host.hasSuffix("amazonaws.com.cn") else { if url.lastPathComponent == "realtime" { return url.deletingLastPathComponent() } diff --git a/AmplifyPlugins/API/Tests/AWSAPIPluginTests/SubscriptionFactory/AppSyncRealTimeClientFactoryTests.swift b/AmplifyPlugins/API/Tests/AWSAPIPluginTests/SubscriptionFactory/AppSyncRealTimeClientFactoryTests.swift index 15ca8c7858..6d3ebbd8fd 100644 --- a/AmplifyPlugins/API/Tests/AWSAPIPluginTests/SubscriptionFactory/AppSyncRealTimeClientFactoryTests.swift +++ b/AmplifyPlugins/API/Tests/AWSAPIPluginTests/SubscriptionFactory/AppSyncRealTimeClientFactoryTests.swift @@ -17,6 +17,12 @@ class AppSyncRealTimeClientFactoryTests: XCTestCase { AppSyncRealTimeClientFactory.appSyncRealTimeEndpoint(appSyncEndpoint), URL(string: "wss://abc.appsync-realtime-api.amazonaws.com/graphql") ) + + let appSyncEndpointCN = URL(string: "https://abc.appsync-api.amazonaws.com.cn/graphql")! + XCTAssertEqual( + AppSyncRealTimeClientFactory.appSyncRealTimeEndpoint(appSyncEndpointCN), + URL(string: "wss://abc.appsync-realtime-api.amazonaws.com.cn/graphql") + ) } func testAppSyncRealTimeEndpoint_withAWSAppSyncRealTimeDomain_returnTheSameDomain() { @@ -25,6 +31,12 @@ class AppSyncRealTimeClientFactoryTests: XCTestCase { AppSyncRealTimeClientFactory.appSyncRealTimeEndpoint(appSyncEndpoint), URL(string: "wss://abc.appsync-realtime-api.amazonaws.com/graphql") ) + + let appSyncEndpointCN = URL(string: "wss://abc.appsync-realtime-api.amazonaws.com.cn/graphql")! + XCTAssertEqual( + AppSyncRealTimeClientFactory.appSyncRealTimeEndpoint(appSyncEndpointCN), + URL(string: "wss://abc.appsync-realtime-api.amazonaws.com.cn/graphql") + ) } func testAppSyncRealTimeEndpoint_withCustomDomain_returnCorrectRealtimePath() { @@ -33,6 +45,12 @@ class AppSyncRealTimeClientFactoryTests: XCTestCase { AppSyncRealTimeClientFactory.appSyncRealTimeEndpoint(appSyncEndpoint), URL(string: "https://test.example.com/graphql/realtime") ) + + let appSyncEndpointCN = URL(string: "https://test.example.com.cn/graphql")! + XCTAssertEqual( + AppSyncRealTimeClientFactory.appSyncRealTimeEndpoint(appSyncEndpointCN), + URL(string: "https://test.example.com.cn/graphql/realtime") + ) } func testAppSyncApiEndpoint_withAWSAppSyncRealTimeDomain_returnCorrectApiDomain() { @@ -41,6 +59,12 @@ class AppSyncRealTimeClientFactoryTests: XCTestCase { AppSyncRealTimeClientFactory.appSyncApiEndpoint(appSyncEndpoint), URL(string: "https://abc.appsync-api.amazonaws.com/graphql") ) + + let appSyncEndpointCN = URL(string: "wss://abc.appsync-realtime-api.amazonaws.com.cn/graphql")! + XCTAssertEqual( + AppSyncRealTimeClientFactory.appSyncApiEndpoint(appSyncEndpointCN), + URL(string: "https://abc.appsync-api.amazonaws.com.cn/graphql") + ) } func testAppSyncApiEndpoint_withAWSAppSyncApiDomain_returnTheSameDomain() { @@ -49,6 +73,12 @@ class AppSyncRealTimeClientFactoryTests: XCTestCase { AppSyncRealTimeClientFactory.appSyncApiEndpoint(appSyncEndpoint), URL(string: "https://abc.appsync-api.amazonaws.com/graphql") ) + + let appSyncEndpointCN = URL(string: "https://abc.appsync-api.amazonaws.com.cn/graphql")! + XCTAssertEqual( + AppSyncRealTimeClientFactory.appSyncApiEndpoint(appSyncEndpointCN), + URL(string: "https://abc.appsync-api.amazonaws.com.cn/graphql") + ) } func testAppSyncApiEndpoint_withCustomDomain_returnCorrectRealtimePath() { @@ -57,5 +87,11 @@ class AppSyncRealTimeClientFactoryTests: XCTestCase { AppSyncRealTimeClientFactory.appSyncApiEndpoint(appSyncEndpoint), URL(string: "https://test.example.com/graphql") ) + + let appSyncEndpointCN = URL(string: "https://test.example.com.cn/graphql")! + XCTAssertEqual( + AppSyncRealTimeClientFactory.appSyncApiEndpoint(appSyncEndpointCN), + URL(string: "https://test.example.com.cn/graphql") + ) } }