-
Notifications
You must be signed in to change notification settings - Fork 571
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ConfigPackageUtility::ValidateName: replace broken regex
The old validation regex matched if the name consists only of invalid character, not that it does not contain them, i.e. something like "foo/bar" was considered valid. This commit replaces the regex with a check that all characters in the name are allowed characters.
- Loading branch information
1 parent
02fc01b
commit c40b18e
Showing
3 changed files
with
31 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* Icinga 2 | (c) 2021 Icinga GmbH | GPLv2+ */ | ||
|
||
#include "remote/configpackageutility.hpp" | ||
#include <vector> | ||
#include <string> | ||
#include <BoostTestTargetConfig.h> | ||
|
||
using namespace icinga; | ||
|
||
BOOST_AUTO_TEST_SUITE(remote_configpackageutility) | ||
|
||
BOOST_AUTO_TEST_CASE(ValidateName) | ||
{ | ||
std::vector<std::string> validNames {"foo", "foo-bar", "FooBar", "Foo123", "_Foo-", "123bar"}; | ||
for (const std::string& n : validNames) { | ||
BOOST_CHECK_MESSAGE(ConfigPackageUtility::ValidateName(n), "'" << n << "' should be valid"); | ||
} | ||
|
||
std::vector<std::string> invalidNames {"", ".", "..", "foo.bar", "foo/../bar", "foo/bar", "foo:bar"}; | ||
for (const std::string& n : invalidNames) { | ||
BOOST_CHECK_MESSAGE(!ConfigPackageUtility::ValidateName(n), "'" << n << "' should not be valid"); | ||
} | ||
} | ||
|
||
BOOST_AUTO_TEST_SUITE_END() |