Skip to content

Commit 42c5b54

Browse files
fixes invalid url crash (#69)
1 parent 7082aa2 commit 42c5b54

File tree

5 files changed

+115
-1
lines changed

5 files changed

+115
-1
lines changed

Package.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,17 @@ let package = Package(
104104
.testTarget(name: "RSocketWSTransportTests", dependencies: [
105105
"RSocketWSTransport"
106106
]),
107-
107+
.testTarget(name: "RSocketNIOChannelTests", dependencies: [
108+
"RSocketNIOChannel",
109+
"RSocketWSTransport",
110+
"RSocketTestUtilities"
111+
]),
112+
.testTarget(name: "RSocketTSChannelTests", dependencies: [
113+
"RSocketTSChannel",
114+
"RSocketWSTransport",
115+
"RSocketTestUtilities",
116+
"RSocketCore"
117+
]),
108118
// Examples
109119
.executableTarget(
110120
name: "TimerClientExample",

Sources/RSocketNIOChannel/ClientBootstrap.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ extension ClientBootstrap: RSocketCore.ClientBootstrap {
8888
}
8989
}
9090
.connect(host: endpoint.host, port: endpoint.port)
91+
connectFuture.cascadeFailure(to: requesterPromise)
9192
return connectFuture.flatMap { channel in
9293
requesterPromise.futureResult.map { socket in
9394
// initializing core client using channel object

Sources/RSocketTSChannel/ClientBootstrap.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ extension ClientBootstrap: RSocketCore.ClientBootstrap {
8282
}
8383
}
8484
.connect(host: endpoint.host, port: endpoint.port)
85+
connectFuture.cascadeFailure(to: requesterPromise)
8586
return connectFuture.flatMap { channel in
8687
requesterPromise.futureResult.map { socket in
8788
// initializing core client using channel object
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright 2015-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import XCTest
18+
@testable import RSocketNIOChannel
19+
import RSocketWSTransport
20+
import RSocketTestUtilities
21+
import RSocketCore
22+
class RSocketNIOChannelTests: XCTestCase {
23+
var clientBootStrap: RSocketNIOChannel.ClientBootstrap<WSTransport>?
24+
override func setUp() {
25+
clientBootStrap = ClientBootstrap(
26+
transport: WSTransport(),
27+
config: .mobileToServer
28+
.set(\.encoding.metadata, to: .messageXRSocketRoutingV0)
29+
.set(\.encoding.data, to: .applicationJson)
30+
)
31+
}
32+
/// test case for invalid url
33+
func testInvalidUrlErrorCatch() {
34+
let invalidUrlErrorCatch = expectation(description: "invalid url error catch")
35+
let headerDict: [String: String] = ["": ""]
36+
let uri = URL(string: "http://127.0.0.1/V1/Mock")!
37+
// creating connection with invalid url
38+
let bootstrap = clientBootStrap?.connect(to: WSTransport.Endpoint(url: uri, additionalHTTPHeader: headerDict),
39+
payload: Payload(metadata: "", data: ""), responder: TestRSocket())
40+
// catch error on future fails
41+
bootstrap?.whenFailure({ _ in
42+
invalidUrlErrorCatch.fulfill()
43+
})
44+
self.wait(for: [invalidUrlErrorCatch], timeout: 0.1)
45+
}
46+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright 2015-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
#if canImport(Network)
17+
18+
import XCTest
19+
@testable import RSocketTSChannel
20+
import RSocketTestUtilities
21+
import RSocketCore
22+
import RSocketWSTransport
23+
import NIOTransportServices
24+
25+
@available(OSX 10.14, iOS 12.0, tvOS 12.0, watchOS 6.0, *)
26+
class RSocketTSChannelTests: XCTestCase {
27+
var clientBootStrap: RSocketTSChannel.ClientBootstrap<WSTransport>?
28+
override func setUp() {
29+
clientBootStrap = ClientBootstrap(
30+
transport: WSTransport(),
31+
config: .mobileToServer
32+
.set(\.encoding.metadata, to: .messageXRSocketRoutingV0)
33+
.set(\.encoding.data, to: .applicationJson)
34+
)
35+
}
36+
/// test case for invalid url
37+
func testInvalidUrlErrorCatch() {
38+
let invalidUrlErrorCatch = expectation(description: "invalid url error catch")
39+
let headerDict: [String: String] = ["": ""]
40+
let uri = URL(string: "http://127.0.0.1/V1/Mock")!
41+
clientBootStrap?.configure {
42+
$0.channelOption(NIOTSChannelOptions.waitForActivity, value: false)
43+
}
44+
// creating connection with invalid url
45+
let bootstrap = clientBootStrap?.connect(to: WSTransport.Endpoint(url: uri, additionalHTTPHeader: headerDict),
46+
payload: Payload(metadata: "", data: ""), responder: TestRSocket())
47+
// catch error on future fails
48+
bootstrap?.whenFailure({ _ in
49+
invalidUrlErrorCatch.fulfill()
50+
})
51+
self.wait(for: [invalidUrlErrorCatch], timeout: 0.1)
52+
}
53+
54+
}
55+
56+
#endif

0 commit comments

Comments
 (0)