Skip to content

Commit

Permalink
#24 Refactor service tests
Browse files Browse the repository at this point in the history
  • Loading branch information
securesocketfunneling committed Sep 8, 2016
1 parent 108cc7c commit 4da7d63
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 30 deletions.
10 changes: 8 additions & 2 deletions src/tests/config/config_files/services.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@
"ssf": {
"services" : {
"datagram_forwarder": { "enable": false },
"datagram_listener": { "enable": false },
"datagram_listener": {
"enable": false,
"gateway_ports": true
},
"stream_forwarder": { "enable": false },
"stream_listener": { "enable": false },
"stream_listener": {
"enable": false,
"gateway_ports": true
},
"file_copy": { "enable": true },
"shell": {
"enable": true,
Expand Down
6 changes: 6 additions & 0 deletions src/tests/config/load_config_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,12 @@ TEST_F(LoadConfigTest, DefaultValueTest) {

ASSERT_TRUE(config_.services().datagram_forwarder().enabled());
ASSERT_TRUE(config_.services().datagram_listener().enabled());
ASSERT_FALSE(config_.services().datagram_listener().gateway_ports());
ASSERT_FALSE(config_.services().file_copy().enabled());
ASSERT_TRUE(config_.services().socks().enabled());
ASSERT_TRUE(config_.services().stream_forwarder().enabled());
ASSERT_TRUE(config_.services().stream_listener().enabled());
ASSERT_FALSE(config_.services().stream_listener().gateway_ports());
ASSERT_FALSE(config_.services().process().enabled());

ASSERT_GT(config_.services().process().path().length(),
Expand Down Expand Up @@ -112,10 +114,12 @@ TEST_F(LoadConfigTest, LoadTlsCompleteFileTest) {

ASSERT_TRUE(config_.services().datagram_forwarder().enabled());
ASSERT_TRUE(config_.services().datagram_listener().enabled());
ASSERT_FALSE(config_.services().datagram_listener().gateway_ports());
ASSERT_FALSE(config_.services().file_copy().enabled());
ASSERT_TRUE(config_.services().socks().enabled());
ASSERT_TRUE(config_.services().stream_forwarder().enabled());
ASSERT_TRUE(config_.services().stream_listener().enabled());
ASSERT_FALSE(config_.services().stream_listener().gateway_ports());
ASSERT_FALSE(config_.services().process().enabled());

ASSERT_GT(config_.services().process().path().length(),
Expand Down Expand Up @@ -145,10 +149,12 @@ TEST_F(LoadConfigTest, LoadServicesFileTest) {
ASSERT_EQ(ec.value(), 0) << "Success if complete file format";
ASSERT_FALSE(config_.services().datagram_forwarder().enabled());
ASSERT_FALSE(config_.services().datagram_listener().enabled());
ASSERT_TRUE(config_.services().datagram_listener().gateway_ports());
ASSERT_TRUE(config_.services().file_copy().enabled());
ASSERT_FALSE(config_.services().socks().enabled());
ASSERT_FALSE(config_.services().stream_forwarder().enabled());
ASSERT_FALSE(config_.services().stream_listener().enabled());
ASSERT_TRUE(config_.services().stream_listener().gateway_ports());
ASSERT_TRUE(config_.services().process().enabled());

ASSERT_EQ(config_.services().process().path(), "/bin/custom_path");
Expand Down
8 changes: 4 additions & 4 deletions src/tests/services/process_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
class ProcessTest : public ProcessFixtureTest<ssf::services::Process> {
std::shared_ptr<ServiceTested> ServiceCreateServiceOptions(
boost::system::error_code& ec) override {
return ServiceTested::CreateServiceOptions("9091", ec);
return ServiceTested::CreateServiceOptions("9071", ec);
}
};

TEST_F(ProcessTest, ExecuteCmdTest) { ExecuteCmd("9091"); }
TEST_F(ProcessTest, ExecuteCmdTest) { ExecuteCmd("9071"); }

class ProcessWildcardTest : public ProcessTest {
void SetServerConfig(ssf::config::Config& config) override {
Expand Down Expand Up @@ -50,8 +50,8 @@ class ProcessWildcardTest : public ProcessTest {

std::shared_ptr<ServiceTested> ServiceCreateServiceOptions(
boost::system::error_code& ec) override {
return ServiceTested::CreateServiceOptions(":9092", ec);
return ServiceTested::CreateServiceOptions(":9072", ec);
}
};

TEST_F(ProcessWildcardTest, ExecuteCmdTest) { ExecuteCmd("9092"); }
TEST_F(ProcessWildcardTest, ExecuteCmdTest) { ExecuteCmd("9072"); }
8 changes: 4 additions & 4 deletions src/tests/services/remote_process_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ class RemoteProcessTest
: public ProcessFixtureTest<ssf::services::RemoteProcess> {
std::shared_ptr<ServiceTested> ServiceCreateServiceOptions(
boost::system::error_code& ec) override {
return ServiceTested::CreateServiceOptions("9091", ec);
return ServiceTested::CreateServiceOptions("9081", ec);
}
};

TEST_F(RemoteProcessTest, ExecuteCmdTest) { ExecuteCmd("9091"); }
TEST_F(RemoteProcessTest, ExecuteCmdTest) { ExecuteCmd("9081"); }

class RemoteProcessWildcardTest : public RemoteProcessTest {
protected:
Expand Down Expand Up @@ -52,8 +52,8 @@ class RemoteProcessWildcardTest : public RemoteProcessTest {

std::shared_ptr<ServiceTested> ServiceCreateServiceOptions(
boost::system::error_code& ec) override {
return ServiceTested::CreateServiceOptions(":9092", ec);
return ServiceTested::CreateServiceOptions(":9082", ec);
}
};

TEST_F(RemoteProcessWildcardTest, ExecuteCmdTest) { ExecuteCmd("9092"); }
TEST_F(RemoteProcessWildcardTest, ExecuteCmdTest) { ExecuteCmd("9082"); }
8 changes: 4 additions & 4 deletions src/tests/services/remote_socks_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
class RemoteSocksTest : public SocksFixtureTest<ssf::services::RemoteSocks> {
std::shared_ptr<ServiceTested> ServiceCreateServiceOptions(
boost::system::error_code& ec) override {
return ServiceTested::CreateServiceOptions(":9091", ec);
return ServiceTested::CreateServiceOptions(":9061", ec);
}
};

TEST_F(RemoteSocksTest, startStopTransmitSSFRemoteSocks) {
ASSERT_TRUE(Wait());

Run("9091", "9092");
Run("9061", "9062");
}

class RemoteSocksWildcardTest : public RemoteSocksTest {
Expand Down Expand Up @@ -52,12 +52,12 @@ class RemoteSocksWildcardTest : public RemoteSocksTest {

std::shared_ptr<ServiceTested> ServiceCreateServiceOptions(
boost::system::error_code& ec) override {
return ServiceTested::CreateServiceOptions(":9093", ec);
return ServiceTested::CreateServiceOptions(":9063", ec);
}
};

TEST_F(RemoteSocksWildcardTest, startStopTransmitSSFSocks) {
ASSERT_TRUE(Wait());

Run("9093", "9094");
Run("9063", "9064");
}
8 changes: 4 additions & 4 deletions src/tests/services/remote_udp_forwarding_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ class RemoteUdpForwardTest
: public DatagramFixtureTest<ssf::services::UdpRemotePortForwarding> {
std::shared_ptr<ServiceTested> ServiceCreateServiceOptions(
boost::system::error_code& ec) override {
return ServiceTested::CreateServiceOptions("5454:127.0.0.1:5555", ec);
return ServiceTested::CreateServiceOptions("6464:127.0.0.1:6565", ec);
}
};

TEST_F(RemoteUdpForwardTest, transferOnesOverUdp) {
ASSERT_TRUE(Wait());

Run("5454", "5555");
Run("6464", "6565");
}

class RemoteUdpForwardWildcardTest : public RemoteUdpForwardTest {
Expand Down Expand Up @@ -53,12 +53,12 @@ class RemoteUdpForwardWildcardTest : public RemoteUdpForwardTest {

std::shared_ptr<ServiceTested> ServiceCreateServiceOptions(
boost::system::error_code& ec) override {
return ServiceTested::CreateServiceOptions(":5656:127.0.0.1:5757", ec);
return ServiceTested::CreateServiceOptions(":6666:127.0.0.1:6767", ec);
}
};

TEST_F(RemoteUdpForwardWildcardTest, transferOnesOverStream) {
ASSERT_TRUE(Wait());

Run("5656", "5757");
Run("6666", "6767");
}
8 changes: 4 additions & 4 deletions src/tests/services/socks_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
class SocksTest : public SocksFixtureTest<ssf::services::Socks> {
std::shared_ptr<ServiceTested> ServiceCreateServiceOptions(
boost::system::error_code& ec) override {
return ServiceTested::CreateServiceOptions(":9091", ec);
return ServiceTested::CreateServiceOptions(":9051", ec);
}
};

TEST_F(SocksTest, startStopTransmitSSFSocks) {
ASSERT_TRUE(Wait());
Run("9091", "9092");
Run("9051", "9052");
}

class SocksWildcardTest : public SocksTest {
Expand Down Expand Up @@ -51,12 +51,12 @@ class SocksWildcardTest : public SocksTest {

std::shared_ptr<ServiceTested> ServiceCreateServiceOptions(
boost::system::error_code& ec) override {
return ServiceTested::CreateServiceOptions(":9093", ec);
return ServiceTested::CreateServiceOptions(":9053", ec);
}
};

TEST_F(SocksWildcardTest, startStopTransmitSSFSocks) {
ASSERT_TRUE(Wait());

Run("9093", "9094");
Run("9053", "9054");
}
8 changes: 4 additions & 4 deletions src/tests/services/stream_forwarding_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ class StreamForwardTest
: public StreamFixtureTest<ssf::services::PortForwarding> {
std::shared_ptr<ServiceTested> ServiceCreateServiceOptions(
boost::system::error_code& ec) override {
return ServiceTested::CreateServiceOptions("5454:127.0.0.1:5555", ec);
return ServiceTested::CreateServiceOptions("7474:127.0.0.1:7575", ec);
}
};

TEST_F(StreamForwardTest, transferOnesOverStream) {
ASSERT_TRUE(Wait());

Run("5454", "5555");
Run("7474", "7575");
}

class StreamForwardWildcardTest : public StreamForwardTest {
Expand Down Expand Up @@ -53,12 +53,12 @@ class StreamForwardWildcardTest : public StreamForwardTest {

std::shared_ptr<ServiceTested> ServiceCreateServiceOptions(
boost::system::error_code& ec) override {
return ServiceTested::CreateServiceOptions(":5656:127.0.0.1:5757", ec);
return ServiceTested::CreateServiceOptions(":7676:127.0.0.1:7777", ec);
}
};

TEST_F(StreamForwardWildcardTest, transferOnesOverStream) {
ASSERT_TRUE(Wait());

Run("5656", "5757");
Run("7676", "7777");
}
8 changes: 4 additions & 4 deletions src/tests/services/udp_forwarding_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ class UdpForwardTest
: public DatagramFixtureTest<ssf::services::UdpPortForwarding> {
std::shared_ptr<ServiceTested> ServiceCreateServiceOptions(
boost::system::error_code& ec) override {
return ServiceTested::CreateServiceOptions("5454:127.0.0.1:5555", ec);
return ServiceTested::CreateServiceOptions("8484:127.0.0.1:8585", ec);
}
};

TEST_F(UdpForwardTest, transferOnesOverUdp) {
ASSERT_TRUE(Wait());

Run("5454", "5555");
Run("8484", "8585");
}

class UdpForwardWildcardTest : public UdpForwardTest {
Expand Down Expand Up @@ -53,12 +53,12 @@ class UdpForwardWildcardTest : public UdpForwardTest {

std::shared_ptr<ServiceTested> ServiceCreateServiceOptions(
boost::system::error_code& ec) override {
return ServiceTested::CreateServiceOptions(":5656:127.0.0.1:5757", ec);
return ServiceTested::CreateServiceOptions(":8686:127.0.0.1:8787", ec);
}
};

TEST_F(UdpForwardWildcardTest, transferOnesOverStream) {
ASSERT_TRUE(Wait());

Run("5656", "5757");
Run("8686", "8787");
}

0 comments on commit 4da7d63

Please sign in to comment.