Add websocket port argument ()

This commit is contained in:
Jure Bajic 2022-02-17 10:27:24 +01:00 committed by Antonio Andelic
parent 1d88893715
commit 3fb7e5378d
5 changed files with 31 additions and 15 deletions

View File

@ -132,8 +132,15 @@ std::optional<Enum> StringToEnum(const auto &value, const auto &mappings) {
// Bolt server flags.
DEFINE_string(bolt_address, "0.0.0.0", "IP address on which the Bolt server should listen.");
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
DEFINE_string(monitoring_address, "0.0.0.0",
"IP address on which the websocket server for Memgraph monitoring should listen.");
DEFINE_VALIDATED_int32(bolt_port, 7687, "Port on which the Bolt server should listen.",
FLAG_IN_RANGE(0, std::numeric_limits<uint16_t>::max()));
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
DEFINE_VALIDATED_int32(monitoring_port, 7444,
"Port on which the websocket server for Memgraph monitoring should listen.",
FLAG_IN_RANGE(0, std::numeric_limits<uint16_t>::max()));
DEFINE_VALIDATED_int32(bolt_num_workers, std::max(std::thread::hardware_concurrency(), 1U),
"Number of workers used by the Bolt server. By default, this will be the "
"number of processing units available on the machine.",
@ -1216,7 +1223,8 @@ int main(int argc, char **argv) {
}
communication::websocket::SafeAuth websocket_auth{&auth};
communication::websocket::Server websocket_server{{"0.0.0.0", 7444}, &context, websocket_auth};
communication::websocket::Server websocket_server{
{FLAGS_monitoring_address, static_cast<uint16_t>(FLAGS_monitoring_port)}, &context, websocket_auth};
AddLoggerSink(websocket_server.GetLoggingSink());
// Handler for regular termination signals

View File

@ -238,10 +238,10 @@ inline void AssertLogMessage(const std::string &log_message) {
}
template <typename TWebsocketClient>
void TestWebsocketWithoutAnyUsers(std::unique_ptr<mg::Client> &mg_client) {
void TestWebsocketWithoutAnyUsers(std::unique_ptr<mg::Client> &mg_client, const std::string_view monitoring_port) {
spdlog::info("Starting websocket connection without any users.");
auto websocket_client = TWebsocketClient();
websocket_client.Connect("127.0.0.1", "7444");
websocket_client.Connect("127.0.0.1", monitoring_port);
RunQueries(mg_client);
std::this_thread::sleep_for(std::chrono::seconds(1));
@ -257,12 +257,12 @@ void TestWebsocketWithoutAnyUsers(std::unique_ptr<mg::Client> &mg_client) {
}
template <typename TWebsocketClient>
void TestWebsocketWithAuthentication(std::unique_ptr<mg::Client> &mg_client) {
void TestWebsocketWithAuthentication(std::unique_ptr<mg::Client> &mg_client, const std::string_view monitoring_port) {
spdlog::info("Starting websocket connection with users.");
AddUser(mg_client);
std::this_thread::sleep_for(std::chrono::seconds(1));
auto websocket_client = TWebsocketClient({"test", "testing"});
websocket_client.Connect("127.0.0.1", "7444");
websocket_client.Connect("127.0.0.1", monitoring_port);
RunQueries(mg_client);
std::this_thread::sleep_for(std::chrono::seconds(1));
@ -279,11 +279,12 @@ void TestWebsocketWithAuthentication(std::unique_ptr<mg::Client> &mg_client) {
}
template <typename TWebsocketClient>
void TestWebsocketWithoutBeingAuthorized(std::unique_ptr<mg::Client> &mg_client) {
void TestWebsocketWithoutBeingAuthorized(std::unique_ptr<mg::Client> &mg_client,
const std::string_view monitoring_port) {
spdlog::info("Starting websocket connection with users but without being authenticated.");
std::this_thread::sleep_for(std::chrono::seconds(1));
auto websocket_client = TWebsocketClient({"wrong", "credentials"});
websocket_client.Connect("127.0.0.1", "7444");
websocket_client.Connect("127.0.0.1", monitoring_port);
RunQueries(mg_client);
std::this_thread::sleep_for(std::chrono::seconds(1));
@ -302,8 +303,8 @@ void TestWebsocketWithoutBeingAuthorized(std::unique_ptr<mg::Client> &mg_client)
}
template <typename TWebsocketClient>
void RunTestCases(std::unique_ptr<mg::Client> &mg_client) {
TestWebsocketWithoutAnyUsers<TWebsocketClient>(mg_client);
TestWebsocketWithAuthentication<TWebsocketClient>(mg_client);
TestWebsocketWithoutBeingAuthorized<TWebsocketClient>(mg_client);
void RunTestCases(std::unique_ptr<mg::Client> &mg_client, const std::string_view monitoring_port) {
TestWebsocketWithoutAnyUsers<TWebsocketClient>(mg_client, monitoring_port);
TestWebsocketWithAuthentication<TWebsocketClient>(mg_client, monitoring_port);
TestWebsocketWithoutBeingAuthorized<TWebsocketClient>(mg_client, monitoring_port);
}

View File

@ -24,6 +24,7 @@
#include "utils/logging.hpp"
DEFINE_uint64(bolt_port, 7687, "Bolt port");
DEFINE_uint64(monitoring_port, 7444, "Monitoring port");
class WebsocketClient {
public:
@ -57,12 +58,13 @@ int main(int argc, char **argv) {
google::SetUsageMessage("Memgraph E2E websocket!");
gflags::ParseCommandLineFlags(&argc, &argv, true);
MG_ASSERT(FLAGS_bolt_port != 0);
MG_ASSERT(FLAGS_monitoring_port != 0);
logging::RedirectToStderr();
mg::Client::Init();
auto mg_client = GetBoltClient(static_cast<uint16_t>(FLAGS_bolt_port), false);
RunTestCases<WebsocketClient>(mg_client);
RunTestCases<WebsocketClient>(mg_client, std::to_string(FLAGS_monitoring_port));
return 0;
}

View File

@ -30,6 +30,7 @@
#include "utils/logging.hpp"
DEFINE_uint64(bolt_port, 7687, "Bolt port");
DEFINE_uint64(monitoring_port, 7444, "Monitoring port");
class WebsocketSSLClient {
public:
@ -65,12 +66,13 @@ int main(int argc, char **argv) {
google::SetUsageMessage("Memgraph E2E websocket SSL!");
gflags::ParseCommandLineFlags(&argc, &argv, true);
MG_ASSERT(FLAGS_bolt_port != 0);
MG_ASSERT(FLAGS_monitoring_port != 0);
logging::RedirectToStderr();
auto mg_client = GetBoltClient(static_cast<uint16_t>(FLAGS_bolt_port), true);
mg::Client::Init();
RunTestCases<WebsocketSSLClient>(mg_client);
RunTestCases<WebsocketSSLClient>(mg_client, std::to_string(FLAGS_monitoring_port));
return 0;
}

View File

@ -1,6 +1,7 @@
cert_file: &cert_file "$PROJECT_DIR/tests/e2e/websocket/memgraph-selfsigned.crt"
key_file: &key_file "$PROJECT_DIR/tests/e2e/websocket/memgraph-selfsigned.key"
bolt_port: &bolt_port "7687"
monitoring_port: &monitoring_port "7444"
template_cluster: &template_cluster
cluster:
websocket:
@ -13,6 +14,8 @@ template_cluster_ssl: &template_cluster_ssl
[
"--bolt-port",
*bolt_port,
"--monitoring-port",
*monitoring_port,
"--log-level=TRACE",
"--bolt-cert-file",
*cert_file,
@ -26,9 +29,9 @@ template_cluster_ssl: &template_cluster_ssl
workloads:
- name: "Websocket"
binary: "tests/e2e/websocket/memgraph__e2e__websocket"
args: ["--bolt-port", *bolt_port]
args: ["--bolt-port", *bolt_port, "--monitoring-port", *monitoring_port]
<<: *template_cluster
- name: "Websocket SSL"
binary: "tests/e2e/websocket/memgraph__e2e__websocket_ssl"
args: ["--bolt-port", *bolt_port]
args: ["--bolt-port", *bolt_port, "--monitoring-port", *monitoring_port]
<<: *template_cluster_ssl