703rc/fix port size (#802)

* validate port numbers in client

* validate port numbers created at virtual servers and receiver process as tcp ports
This commit is contained in:
2023-09-18 08:59:53 +02:00
committed by GitHub
parent b367b7e431
commit 48759f440e
12 changed files with 148 additions and 11 deletions

View File

@ -11,6 +11,31 @@ namespace sls {
using test::GET;
using test::PUT;
void test_valid_port(const std::string &command,
const std::vector<std::string> &arguments, int detector_id,
int action, int port_number) {
Detector det;
CmdProxy proxy(&det);
std::string string_port_number = std::to_string(port_number);
REQUIRE_THROWS_WITH(proxy.Call(command, arguments, detector_id, action),
"Invalid port number " + string_port_number +
". It must be in range 1 - 65535");
}
void test_valid_port(const std::string &command,
const std::vector<std::string> &arguments, int detector_id,
int action) {
std::vector<std::string> arg(arguments);
arg.push_back("0");
int test_values[2] = {77797, -1};
for (int i = 0; i != 2; ++i) {
int port_number = test_values[i];
arg[arg.size() - 1] = std::to_string(port_number);
test_valid_port(command, arg, detector_id, action, port_number);
}
}
void test_dac(defs::dacIndex index, const std::string &dacname, int dacvalue) {
Detector det;
CmdProxy proxy(&det);

View File

@ -5,6 +5,14 @@
namespace sls {
void test_valid_port(const std::string &command,
const std::vector<std::string> &arguments, int detector_id,
int action, int port_number);
void test_valid_port(const std::string &command,
const std::vector<std::string> &arguments, int detector_id,
int action);
void test_dac(slsDetectorDefs::dacIndex index, const std::string &dacname,
int dacvalue);
void test_onchip_dac(slsDetectorDefs::dacIndex index,

View File

@ -5,6 +5,7 @@
#include "sls/Detector.h"
#include "sls/Version.h"
#include "sls/sls_detector_defs.h"
#include "test-CmdProxy-global.h"
#include <sstream>
#include "sls/versionAPI.h"
@ -237,6 +238,22 @@ TEST_CASE("rx_tcpport", "[.cmd][.rx]") {
proxy.Call("rx_tcpport", {}, i, GET, oss);
REQUIRE(oss.str() == "rx_tcpport " + std::to_string(port + i) + '\n');
}
test_valid_port("rx_tcpport", {}, -1, PUT);
test_valid_port("rx_tcpport", {}, 0, PUT);
// should fail for the second module
if (det.size() > 1) {
test_valid_port("rx_tcpport", {"65535"}, -1, PUT, 65536);
auto rxHostname = det.getRxHostname().squash("none");
if (rxHostname != "none") {
std::ostringstream oss;
for (int i = 0; i != det.size(); ++i) {
oss << rxHostname << ":" << 65536 + i << "+";
}
test_valid_port("rx_hostname", {oss.str()}, -1, PUT, 65536);
}
}
for (int i = 0; i != det.size(); ++i) {
det.setRxPort(prev_val[i], i);
}
@ -828,6 +845,12 @@ TEST_CASE("rx_zmqport", "[.cmd][.rx]") {
std::to_string(port + i * socketsperdetector) +
'\n');
}
test_valid_port("rx_zmqport", {}, -1, PUT);
test_valid_port("rx_zmqport", {}, 0, PUT);
// should fail for the second module
if (det.size() > 1) {
test_valid_port("rx_zmqport", {"65535"}, -1, PUT, 65536);
}
for (int i = 0; i != det.size(); ++i) {
det.setRxZmqPort(prev_val_zmqport[i], i);
}

View File

@ -5,6 +5,7 @@
#include "sls/Detector.h"
#include "sls/file_utils.h"
#include "sls/sls_detector_defs.h"
#include "test-CmdProxy-global.h"
#include <chrono>
#include <sstream>
@ -76,7 +77,13 @@ TEST_CASE("hostname", "[.cmd]") {
REQUIRE_NOTHROW(proxy.Call("hostname", {}, -1, GET));
}
// virtual: not testing
TEST_CASE("virtual", "[.cmd]") {
Detector det;
CmdProxy proxy(&det);
REQUIRE_THROWS(proxy.Call("virtual", {}, -1, GET));
test_valid_port("virtual", {"1"}, -1, PUT);
test_valid_port("virtual", {"3", "65534"}, -1, PUT, 65536);
}
TEST_CASE("versions", "[.cmd]") {
Detector det;
@ -2618,6 +2625,13 @@ TEST_CASE("udp_dstport", "[.cmd]") {
proxy.Call("udp_dstport", {"50084"}, -1, PUT, oss);
REQUIRE(oss.str() == "udp_dstport 50084\n");
}
test_valid_port("udp_dstport", {}, -1, PUT);
test_valid_port("udp_dstport", {}, 0, PUT);
// should fail for the second module
if (det.size() > 1) {
test_valid_port("udp_dstport", {"65535"}, -1, PUT, 65536);
}
for (int i = 0; i != det.size(); ++i) {
det.setDestinationUDPPort(prev_val[i], {i});
}
@ -2702,8 +2716,18 @@ TEST_CASE("udp_dstport2", "[.cmd]") {
proxy.Call("udp_dstport2", {"50084"}, -1, PUT, oss);
REQUIRE(oss.str() == "udp_dstport2 50084\n");
}
test_valid_port("udp_dstport2", {}, -1, PUT);
test_valid_port("udp_dstport2", {}, 0, PUT);
// should fail for the second module
if (det.size() > 1) {
test_valid_port("udp_dstport2", {"65535"}, -1, PUT, 65536);
}
for (int i = 0; i != det.size(); ++i) {
det.setDestinationUDPPort2(prev_val[i], {i});
if (prev_val[i] != 0) {
det.setDestinationUDPPort2(prev_val[i], {i});
}
}
} else {
REQUIRE_THROWS(proxy.Call("udp_dstport2", {}, -1, GET));
@ -2922,6 +2946,13 @@ TEST_CASE("zmqport", "[.cmd]") {
std::to_string(port + i * socketsperdetector) +
'\n');
}
test_valid_port("zmqport", {}, -1, PUT);
test_valid_port("zmqport", {}, 0, PUT);
// should fail for the second module
if (det.size() > 1) {
test_valid_port("zmqport", {"65535"}, -1, PUT, 65536);
}
if (det_type == defs::JUNGFRAU) {
det.setNumberofUDPInterfaces(prev);
}
@ -3266,6 +3297,13 @@ TEST_CASE("port", "[.cmd]") {
proxy.Call("port", {}, 0, GET, oss);
REQUIRE(oss.str() == "port 1942\n");
}
test_valid_port("port", {}, -1, PUT);
test_valid_port("port", {}, 0, PUT);
// should fail for the second module
if (det.size() > 1) {
test_valid_port("port", {"65536"}, -1, PUT, 65536);
}
det.setControlPort(prev_val, {0});
}
@ -3283,6 +3321,12 @@ TEST_CASE("stopport", "[.cmd]") {
proxy.Call("stopport", {}, 0, GET, oss);
REQUIRE(oss.str() == "stopport 1942\n");
}
test_valid_port("stopport", {}, -1, PUT);
test_valid_port("stopport", {}, 0, PUT);
// should fail for the second module
if (det.size() > 1) {
test_valid_port("stopport", {"65536"}, -1, PUT, 65536);
}
det.setStopPort(prev_val, {0});
}