Skip to content

Commit

Permalink
test(configuration): implement basic webserver listen address test
Browse files Browse the repository at this point in the history
  • Loading branch information
sgaist committed Oct 27, 2023
1 parent aa7dfbc commit 724ae63
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions unit_tests/falco/test_configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,34 @@ TEST(Configuration, configuration_environment_variables)
/* Clear the set environment variable after testing */
unsetenv(env_var_name.c_str());
}

TEST(Configuration, configuration_webserver_ip)
{
falco_configuration falco_config;

std::vector<std::string> valid_addresses = {"127.0.0.1", "1.127.0.1", "1.1.127.1", "1.1.1.127"};

for (const std::string &address: valid_addresses) {
std::string option = "webserver.listen_address=";
option.append(address);

std::vector<std::string> cmdline_config_options;
cmdline_config_options.push_back(option);

EXPECT_NO_THROW(falco_config.init(cmdline_config_options));

ASSERT_EQ(falco_config.m_webserver_listen_address, address);
}

std::vector<std::string> invalid_addresses = {"327.0.0.1", "1.327.0.1", "1.1.327.1", "1.1.1.327"};

for (const std::string &address: invalid_addresses) {
std::string option = "webserver.listen_address=";
option.append(address);

std::vector<std::string> cmdline_config_options;
cmdline_config_options.push_back(option);

EXPECT_ANY_THROW(falco_config.init(cmdline_config_options));
}
}

0 comments on commit 724ae63

Please sign in to comment.