Skip to content

Commit f4d6cdb

Browse files
committed
add failure tests for httpproxy on iOS and tvOS
1 parent aeacf0a commit f4d6cdb

2 files changed

Lines changed: 63 additions & 0 deletions

File tree

Test/AwsCommonRuntimeKitTests/http/HTTPProxyTests.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,21 @@ class HTTPProxyTests: XCBaseTestCase {
7878
try await doProxyTest(type: ProxyTestType.tunnelingHTTPS, authType: .basic)
7979
}
8080

81+
func testHttpProxyFailureOnApple() async throws {
82+
#if !os(iOS) && !os(tvOS)
83+
throw XCTSkip("Http proxy config should only fail on iOS or tvOS")
84+
#endif
85+
try skipIfEnvironmentNotSetup()
86+
var expectionThrow = false
87+
do {
88+
try await doProxyTest(type: ProxyTestType.forwarding, authType: .none)
89+
} catch {
90+
expectionThrow = true
91+
XCTAssertEqual(aws_last_error(), Int32(AWS_ERROR_PLATFORM_NOT_SUPPORTED.rawValue))
92+
}
93+
XCTAssertTrue(expectionThrow)
94+
}
95+
8196
enum ProxyTestType: CaseIterable {
8297
case forwarding
8398
case tunnelingHTTP

Test/AwsCommonRuntimeKitTests/mqtt/Mqtt5ClientTests.swift

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,54 @@ class Mqtt5ClientTests: XCBaseTestCase, @unchecked Sendable {
511511
try await disconnectClientCleanup(client: client, testContext: testContext)
512512
}
513513

514+
/*
515+
* [ConnDC-UC5-1] HttpProxy options failed on iOS
516+
*/
517+
func testMqtt5HttpProxyFailedOnApple() async throws {
518+
#if !os(iOS) && !os(tvOS)
519+
throw XCTSkip("Http proxy config should only fail on iOS or tvOS")
520+
#endif
521+
let inputHost = try getEnvironmentVarOrSkipTest(
522+
environmentVarName: "AWS_TEST_MQTT5_DIRECT_MQTT_TLS_HOST")
523+
let inputPort = try getEnvironmentVarOrSkipTest(
524+
environmentVarName: "AWS_TEST_MQTT5_DIRECT_MQTT_TLS_PORT")
525+
let inputProxyHost = try getEnvironmentVarOrSkipTest(
526+
environmentVarName: "AWS_TEST_MQTT5_PROXY_HOST")
527+
let inputProxyPort = try getEnvironmentVarOrSkipTest(
528+
environmentVarName: "AWS_TEST_MQTT5_PROXY_PORT")
529+
530+
let tlsOptions = TLSContextOptions()
531+
tlsOptions.setVerifyPeer(false)
532+
let tlsContext = try TLSContext(options: tlsOptions, mode: .client)
533+
534+
let httpProxyOptions = HTTPProxyOptions(
535+
hostName: inputProxyHost,
536+
port: UInt32(inputProxyPort)!,
537+
connectionType: HTTPProxyConnectionType.tunnel)
538+
539+
let clientOptions = MqttClientOptions(
540+
hostName: inputHost,
541+
port: UInt32(inputPort)!,
542+
tlsCtx: tlsContext,
543+
httpProxyOptions: httpProxyOptions)
544+
545+
let testContext = MqttTestContext()
546+
let client = try createClient(clientOptions: clientOptions, testContext: testContext)
547+
548+
try client.start()
549+
await awaitExpectation([testContext.connectionFailureExpectation], 5)
550+
551+
if let failureData = testContext.lifecycleConnectionFailureData {
552+
XCTAssertEqual(failureData.crtError.code, Int32(AWS_ERROR_PLATFORM_NOT_SUPPORTED.rawValue))
553+
} else {
554+
XCTFail("lifecycleConnectionFailureData Missing")
555+
return
556+
}
557+
558+
try await stopClient(client: client, testContext: testContext)
559+
560+
}
561+
514562
/*
515563
* [ConnDC-UC6] Direct Connection with all options set
516564
*/

0 commit comments

Comments
 (0)