Skip to content

Commit 96e7500

Browse files
committed
Uri: make sure all local URIs are absolute
Some platforms like QNX have problems with relative local sockets. To be consistent across all platforms we make sure all local URIs are represented/treated as absolute paths. Issues: SILKIT-1779 Signed-off-by: Jan Kraemer <jan.kraemer@vector.com>
1 parent 8f2ed19 commit 96e7500

3 files changed

Lines changed: 82 additions & 25 deletions

File tree

SilKit/source/core/vasio/Test_ConnectKnownParticipants.cpp

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,6 @@ TEST_F(Test_ConnectKnownParticipants, direct_connect_fallback_to_remote_connect_
221221
ioContext.Run();
222222
}
223223

224-
225224
TEST_F(Test_ConnectKnownParticipants, remote_connect_timer_expiry_fallback_to_proxy)
226225
{
227226
auto MakeFailingConnectPeer{[this](const VAsioPeerInfo& peerInfo) { return MakeConnectPeerThatFails(peerInfo); }};
@@ -272,6 +271,47 @@ TEST_F(Test_ConnectKnownParticipants, remote_connect_timer_expiry_fallback_to_pr
272271
ioContext.Run();
273272
}
274273

274+
TEST_F(Test_ConnectKnownParticipants, direct_connect_failure_qnx_with_windows_paths)
275+
{
276+
auto MakeFailingConnectPeer{[this](const VAsioPeerInfo& peerInfo) { return MakeConnectPeerThatFails(peerInfo); }};
277+
278+
VAsioPeerInfo peerInfo;
279+
peerInfo.participantName = "A";
280+
peerInfo.participantId = SilKit::Util::Hash::Hash(peerInfo.participantName);
281+
peerInfo.acceptorUris.emplace_back("local://C:\\\\tmp\\win.sock");
282+
peerInfo.capabilities = "";
283+
284+
// Arrange
285+
286+
Sequence s1;
287+
288+
StrictMock<MockConnectionMethods> connectionMethods;
289+
MockConnectKnownParticipantsListener listener;
290+
291+
EXPECT_CALL(connectionMethods, MakeConnectPeer(WithParticipantName(peerInfo.participantName)))
292+
.InSequence(s1)
293+
.WillOnce(MakeFailingConnectPeer);
294+
295+
EXPECT_CALL(connectionMethods, TryRemoteConnectRequest(WithParticipantName(peerInfo.participantName)))
296+
.InSequence(s1)
297+
.WillOnce(Return(false));
298+
299+
EXPECT_CALL(connectionMethods, TryProxyConnect(WithParticipantName(peerInfo.participantName)))
300+
.InSequence(s1)
301+
.WillOnce(Return(false));
302+
303+
EXPECT_CALL(listener, OnConnectKnownParticipantsFailure).Times(1).InSequence(s1);
304+
305+
// Act
306+
307+
ConnectKnownParticipants connectKnownParticipants{ioContext, connectionMethods, listener, settings};
308+
connectKnownParticipants.SetLogger(logger);
309+
310+
connectKnownParticipants.SetKnownParticipants({peerInfo});
311+
connectKnownParticipants.StartConnecting();
312+
313+
ioContext.Run();
314+
}
275315

276316
TEST_F(Test_ConnectKnownParticipants, remote_connect_waits_for_replies_after_connecting_and_announcement_notifications)
277317
{

SilKit/source/util/Uri.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
#include "Uri.hpp"
66

77
#include <cctype>
8+
#include <filesystem>
89

910
#include "silkit/participant/exception.hpp"
1011

1112
#include "fmt/format.h"
1213

14+
namespace fs = std::filesystem;
1315

1416
namespace {
1517

@@ -154,8 +156,22 @@ auto Uri::Parse(std::string rawUri) -> Uri
154156

155157
if (uri.Type() == UriType::Local)
156158
{
159+
#if defined(__QNX__)
157160
//must be a path, might contain ':' (currently not quoted)
161+
if(!rawUri.empty() && !fs::path(rawUri).is_absolute())
162+
{
163+
// Make sure we always get a proper absolute Path
164+
// Treat all relative paths as relative from CWD
165+
uri._path = fs::current_path() / rawUri;
166+
}
167+
else
168+
{
169+
uri._path = rawUri;
170+
}
171+
#else
158172
uri._path = rawUri;
173+
#endif
174+
159175
}
160176
else
161177
{

SilKit/source/util/tests/Test_Uri.cpp

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,29 @@ void CheckLocalUri(const std::string& uriString, const std::string& path)
8080
}
8181

8282

83+
#if defined(_WIN32)
84+
void CheckPlatformLocalPath()
85+
{
86+
//Windows local paths (contains C:\)
87+
auto uri = Uri::Parse(R"aw(local://C:\\temp\hello\ world")aw");
88+
ASSERT_EQ(uri.Scheme(), "local");
89+
ASSERT_EQ(uri.Host(), "");
90+
ASSERT_EQ(uri.Port(), 0);
91+
ASSERT_EQ(uri.Path(), R"aw(C:\\temp\hello\ world")aw");
92+
93+
// Check forward slash Paths
94+
CheckLocalUri("local:///", "/");
95+
}
96+
#else
97+
// Assume Unix/Posix like local Paths
98+
void CheckPlatformLocalPath()
99+
{
100+
CheckLocalUri("local:///one/two/three", "/one/two/three");
101+
CheckLocalUri("local:///", "/");
102+
}
103+
#endif
104+
105+
83106
TEST(Test_Uri, parse_silkit_scheme)
84107
{
85108
CheckSilKitUri("silkit://localhost:8500", "localhost", 8500);
@@ -143,23 +166,6 @@ TEST(Test_Uri, parse_tcp_scheme)
143166
8500);
144167
}
145168

146-
147-
TEST(Test_Uri, parse_local_scheme_posix_path)
148-
{
149-
CheckLocalUri("local:///one/two/three", "/one/two/three");
150-
CheckLocalUri("local:///", "/");
151-
}
152-
153-
154-
TEST(Test_Uri, parse_local_scheme_windows_path_slash)
155-
{
156-
CheckLocalUri("local:///", "/");
157-
}
158-
159-
160-
TEST(Test_Uri, parse_local_scheme_windows_path_backslash) {}
161-
162-
163169
TEST(Test_Uri, parse_uris)
164170
{
165171
auto uri = Uri::Parse("silkit://hostname:1234/path");
@@ -200,13 +206,6 @@ TEST(Test_Uri, parse_uris)
200206
ASSERT_EQ(uri.Port(), 3456);
201207
ASSERT_EQ(uri.Path(), "");
202208

203-
//Windows local paths (contains C:\)
204-
uri = Uri::Parse(R"aw(local://C:\\temp\hello\ world")aw");
205-
ASSERT_EQ(uri.Scheme(), "local");
206-
ASSERT_EQ(uri.Host(), "");
207-
ASSERT_EQ(uri.Port(), 0);
208-
ASSERT_EQ(uri.Path(), R"aw(C:\\temp\hello\ world")aw");
209-
210209
// No Port given results in default port
211210
uri = Uri::Parse("silkit://localhost");
212211
ASSERT_EQ(uri.Scheme(), "silkit");
@@ -219,6 +218,8 @@ TEST(Test_Uri, parse_uris)
219218
ASSERT_EQ(uri.Host(), "localhost");
220219
ASSERT_EQ(uri.Port(), 0);
221220
ASSERT_EQ(uri.Path(), "");
221+
222+
CheckPlatformLocalPath();
222223
}
223224

224225

0 commit comments

Comments
 (0)