Skip to content

Commit ee6065d

Browse files
Peer to peer topology tests (#303)
* Added code for peer to peer mesh topology test * Added peer to peer loop topology test case * Added the markdown files for the p2p topology tests * Batched documents to avoid payload too large error * Added disableTLS support in test servers * Updated api spec for startListener endpoint
1 parent 7996320 commit ee6065d

14 files changed

Lines changed: 447 additions & 12 deletions

File tree

client/src/cbltest/api/listener.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ class Listener:
1717
"""A class representing the passive side of a replication inside of a test server"""
1818

1919
def __init__(
20-
self, database: Database, collections: list[str], port: int | None = None
20+
self,
21+
database: Database,
22+
collections: list[str],
23+
port: int | None = None,
24+
disable_tls: bool = False,
2125
):
2226
self.database = database
2327
"""The database that the listener will be serving"""
@@ -34,6 +38,9 @@ def __init__(
3438
value
3539
"""
3640

41+
self.disable_tls = disable_tls
42+
"""If True, TLS will be disabled for the listener"""
43+
3744
self.__original_port = port
3845
self.__index = database._index
3946
self.__request_factory = database._request_factory
@@ -48,7 +55,7 @@ async def start(self) -> None:
4855
"""Start listening for incoming connections"""
4956
with self.__tracer.start_as_current_span("start_listener"):
5057
payload = PostStartListenerRequestBody(
51-
self.database.name, self.collections, self.port
58+
self.database.name, self.collections, self.port, self.disable_tls
5259
)
5360
request = self.__request_factory.create_request(
5461
TestServerRequestType.START_LISTENER, payload

client/src/cbltest/api/testserver.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from typing import cast
2-
from urllib.parse import urljoin
2+
from urllib.parse import urljoin, urlparse
33

44
from opentelemetry.trace import get_tracer
55

@@ -135,5 +135,13 @@ def replication_url(self, db_name: str, port: int):
135135
ws_scheme = "ws://" # For now not using secure
136136

137137
_assert_not_null(db_name, "db_name")
138-
replication_url = f"{ws_scheme}{self.url}:{port}"
138+
139+
parsed = urlparse(self.url)
140+
if parsed.hostname:
141+
hostname = parsed.hostname
142+
elif parsed.netloc:
143+
hostname = parsed.netloc.split(":")[0]
144+
else:
145+
hostname = self.url.split("://")[-1].split(":")[0]
146+
replication_url = f"{ws_scheme}{hostname}:{port}"
139147
return urljoin(replication_url, db_name)

client/src/cbltest/v1/requests.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -711,11 +711,23 @@ def port(self) -> int | None:
711711
"""The desired port to listen on (if None, the OS will choose)"""
712712
return self.__port
713713

714-
def __init__(self, db: str, collections: list[str], port: int | None = None):
714+
@property
715+
def disableTLS(self) -> bool:
716+
"""If True, TLS will be disabled for the listener"""
717+
return self.__disable_tls
718+
719+
def __init__(
720+
self,
721+
db: str,
722+
collections: list[str],
723+
port: int | None = None,
724+
disable_tls: bool = False,
725+
):
715726
super().__init__(1)
716727
self.__database = db
717728
self.__collections = collections
718729
self.__port = port
730+
self.__disable_tls = disable_tls
719731

720732
def to_json(self) -> Any:
721733
json: dict[str, Any] = {
@@ -726,6 +738,9 @@ def to_json(self) -> Any:
726738
if self.__port is not None:
727739
json["port"] = self.__port
728740

741+
if self.__disable_tls:
742+
json["disableTLS"] = self.__disable_tls
743+
729744
return json
730745

731746

servers/c/src/cbl/CBLManager.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ namespace ts::cbl {
536536

537537
/// URLEndpointListener
538538

539-
string CBLManager::startListener(const string &database, const vector<std::string>&collNames, int port) {
539+
string CBLManager::startListener(const string &database, const vector<std::string>&collNames, int port, bool disableTLS) {
540540
lock_guard <mutex> lock(_mutex);
541541

542542
CBLError error{};
@@ -562,6 +562,7 @@ namespace ts::cbl {
562562
config.collections = collections.data();
563563
config.collectionCount = collections.size();
564564
config.port = port;
565+
config.disableTLS = disableTLS;
565566

566567
auto listener = CBLURLEndpointListener_Create(&config, &error);
567568
if (!listener) {

servers/c/src/cbl/CBLManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ namespace ts::cbl {
8383

8484
/// Listener
8585

86-
std::string startListener(const std::string &database, const std::vector<std::string>&collections, int port);
86+
std::string startListener(const std::string &database, const std::vector<std::string>&collections, int port, bool disableTLS = false);
8787

8888
CBLURLEndpointListener *listener(const std::string &id);
8989

servers/c/src/dispatcher/PostStartListener.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ int Dispatcher::handlePOSTStartListener(Request &request, Session *session) {
1212
}
1313

1414
auto port = GetValue<int>(body, "port", 0);
15+
auto disableTLS = GetValue<bool>(body, "disableTLS", false);
1516

16-
string id = session->cblManager()->startListener(database, collections, port);
17+
string id = session->cblManager()->startListener(database, collections, port, disableTLS);
1718

1819
json result;
1920
result["id"] = id;

servers/dotnet/testserver.logic/Handlers/StartListenerHandler.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ internal readonly record struct StartListenerBody
1616
public required string[] collections { get; init; }
1717

1818
public ushort port { get; init; }
19+
20+
public bool disableTLS { get; init; } = false;
1921
}
2022

2123
[HttpHandler("startListener")]
@@ -48,7 +50,8 @@ public static Task StartListenerHandler(int version, Session session, JsonDocume
4850

4951
var listenerConfig = new URLEndpointListenerConfiguration(collectionObjects)
5052
{
51-
Port = deserializedBody.port
53+
Port = deserializedBody.port,
54+
DisableTLS = deserializedBody.disableTLS
5255
};
5356
(var listener, var id) = session.ObjectManager.RegisterObject(() => new URLEndpointListener(listenerConfig));
5457
listener.Start();

servers/ios/TestServer/ContentTypes/StartListenerRequest.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ extension ContentTypes {
1212
let database: String
1313
let collections: [String]
1414
let port: UInt16?
15+
let disableTLS: Bool?
1516

1617
public var description: String {
1718
var result: String = "Endpoint Listener Configuration:\n"
1819
result += "\tdatabase: \(database)\n"
1920
result += "\tcollection: \(collections.joined(separator: ", "))\n"
2021
result += "\tport: \(port ?? 0)\n"
22+
result += "\tdisableTLS: \(disableTLS ?? false)\n"
2123
return result
2224
}
2325
}

servers/ios/TestServer/Handlers/StartListener.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ extension Handlers {
1616
Log.log(level: .debug, message: "Starting Listener with config: \(listenerStartRq.description)")
1717

1818
let dbManager = req.databaseManager
19-
let id = try dbManager.startListener(dbName: listenerStartRq.database, collections: listenerStartRq.collections, port: listenerStartRq.port)
19+
let disableTLS = listenerStartRq.disableTLS ?? false
20+
let id = try dbManager.startListener(dbName: listenerStartRq.database, collections: listenerStartRq.collections, port: listenerStartRq.port, disableTLS: disableTLS)
2021

2122
return ContentTypes.Listener(id: id, port: listenerStartRq.port)
2223
}

servers/ios/TestServer/Utils/DatabaseManager.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class DatabaseManager {
8585
}
8686
}
8787

88-
public func startListener(dbName: String, collections: [String], port: UInt16?) throws -> UUID {
88+
public func startListener(dbName: String, collections: [String], port: UInt16?, disableTLS: Bool = false) throws -> UUID {
8989
var collectionsArr: [Collection] = []
9090

9191
guard let database = databases[dbName]
@@ -105,6 +105,7 @@ class DatabaseManager {
105105

106106
var listenerConfig = URLEndpointListenerConfiguration(collections: collectionsArr)
107107
listenerConfig.port = port
108+
listenerConfig.disableTLS = disableTLS
108109

109110
let listener = URLEndpointListener(config: listenerConfig)
110111

0 commit comments

Comments
 (0)