Skip to content

Commit

Permalink
Don't create NIOSSLClientTLSProvider is SSL disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-fowler committed Aug 12, 2021
1 parent 98be336 commit 6fe49a0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
8 changes: 5 additions & 3 deletions Sources/MQTTNIO/MQTTConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,13 @@ final class MQTTConnection {
default:
tlsConfiguration = TLSConfiguration.makeClientConfiguration()
}
let sslContext = try NIOSSLContext(configuration: tlsConfiguration)
let tlsProvider = try NIOSSLClientTLSProvider<ClientBootstrap>(context: sslContext, serverHostname: serverName)
bootstrap = NIOClientTCPBootstrap(clientBootstrap, tls: tlsProvider)
if client.configuration.useSSL {
let sslContext = try NIOSSLContext(configuration: tlsConfiguration)
let tlsProvider = try NIOSSLClientTLSProvider<ClientBootstrap>(context: sslContext, serverHostname: serverName)
bootstrap = NIOClientTCPBootstrap(clientBootstrap, tls: tlsProvider)
return bootstrap.enableTLS()
} else {
bootstrap = NIOClientTCPBootstrap(clientBootstrap,tls: NIOInsecureNoTLS())
}
return bootstrap
}
Expand Down
20 changes: 20 additions & 0 deletions Tests/MQTTNIOTests/MQTTNIOTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,26 @@ final class MQTTNIOTests: XCTestCase {
try client.syncShutdownGracefully()
}

func testRawIPConnect() throws {
#if os(macOS)
if ProcessInfo.processInfo.environment["CI"] != nil {
return
}
let elg = MultiThreadedEventLoopGroup(numberOfThreads: 2)
defer { XCTAssertNoThrow(try elg.syncShutdownGracefully()) }
let client = MQTTClient(
host: "127.0.0.1",
identifier: "test/raw-ip",
eventLoopGroupProvider: .shared(elg),
logger: self.logger
)
_ = try client.connect().wait()
_ = try client.ping().wait()
try client.disconnect().wait()
try client.syncShutdownGracefully()
#endif
}

// MARK: Helper variables and functions

func createClient(identifier: String, configuration: MQTTClient.Configuration = .init()) -> MQTTClient {
Expand Down

0 comments on commit 6fe49a0

Please sign in to comment.