Rename AreAllCharactersWhitelisted to AreAllCharactersAllowlisted (#921)

* Rename AreAllCharactersWhitelisted to AreAllCharactersAllowlisted
This commit is contained in:
JeffStong 2021-08-26 15:28:29 -04:00 коммит произвёл GitHub
Родитель c12498ede1
Коммит a8b83071bd
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 27 добавлений и 27 удалений

Просмотреть файл

@ -3,7 +3,7 @@
// SPDX-License-Identifier: Apache-2.0
//
#include "CorrelationVector.hpp"
#include "utils/StringUtils.hpp" // for SplitString and AreAllCharactersWhitelisted
#include "utils/StringUtils.hpp" // for SplitString and AreAllCharactersAllowlisted
#include <vector>
#include <random>
@ -246,14 +246,14 @@ namespace MAT_NS_BEGIN
return false;
}
if (!StringUtils::AreAllCharactersWhitelisted(parts[i], s_base64CharSet))
if (!StringUtils::AreAllCharactersAllowlisted(parts[i], s_base64CharSet))
{
return false;
}
}
// all other character groups must be non-empty, decimal digits
if (i != 0 && (parts[i].length() == 0 || !StringUtils::AreAllCharactersWhitelisted(parts[i], s_base10CharSet)))
if (i != 0 && (parts[i].length() == 0 || !StringUtils::AreAllCharactersAllowlisted(parts[i], s_base10CharSet)))
{
return false;
}

Просмотреть файл

@ -31,9 +31,9 @@ namespace MAT_NS_BEGIN
}
}
bool StringUtils::AreAllCharactersWhitelisted(const string& stringToTest, const string& whitelist)
bool StringUtils::AreAllCharactersAllowlisted(const string& stringToTest, const string& allowlist)
{
return (stringToTest.find_first_not_of(whitelist) == string::npos);
return (stringToTest.find_first_not_of(allowlist) == string::npos);
}
#ifdef __clang__

Просмотреть файл

@ -17,7 +17,7 @@ namespace MAT_NS_BEGIN
namespace StringUtils
{
void SplitString(const std::string& s, const char separator, std::vector<std::string>& parts);
bool AreAllCharactersWhitelisted(const std::string& stringToTest, const std::string& whitelist);
bool AreAllCharactersAllowlisted(const std::string& stringToTest, const std::string& allowlist);
}
std::string toString(char const* value);

Просмотреть файл

@ -69,10 +69,10 @@ TEST(StringUtilsTests, SplitString)
ASSERT_EQ(parts.size() > 5 ? parts[5] : "null", "");
}
TEST(StringUtilsTests, AreAllCharactersWhitelisted)
TEST(StringUtilsTests, AreAllCharactersAllowlisted)
{
// testing method
// bool AreAllCharactersWhitelisted(const std::string& stringToTest, const std::string& whitelist);
// bool AreAllCharactersAllowlisted(const std::string& stringToTest, const std::string& allowlist);
string allAsciiChars;
@ -81,29 +81,29 @@ TEST(StringUtilsTests, AreAllCharactersWhitelisted)
allAsciiChars += ((char)i);
}
// any string is whitelisted against the full list of characters
EXPECT_TRUE(StringUtils::AreAllCharactersWhitelisted(allAsciiChars, allAsciiChars));
EXPECT_TRUE(StringUtils::AreAllCharactersWhitelisted("", allAsciiChars));
EXPECT_TRUE(StringUtils::AreAllCharactersWhitelisted("a", allAsciiChars));
EXPECT_TRUE(StringUtils::AreAllCharactersWhitelisted("aaaaaaaaaaa", allAsciiChars));
EXPECT_TRUE(StringUtils::AreAllCharactersWhitelisted(string(10000, ' '), allAsciiChars));
// any string is allowed against the full list of characters
EXPECT_TRUE(StringUtils::AreAllCharactersAllowlisted(allAsciiChars, allAsciiChars));
EXPECT_TRUE(StringUtils::AreAllCharactersAllowlisted("", allAsciiChars));
EXPECT_TRUE(StringUtils::AreAllCharactersAllowlisted("a", allAsciiChars));
EXPECT_TRUE(StringUtils::AreAllCharactersAllowlisted("aaaaaaaaaaa", allAsciiChars));
EXPECT_TRUE(StringUtils::AreAllCharactersAllowlisted(string(10000, ' '), allAsciiChars));
// any non-empty string is NOT whitelisted against an empty list of characters
EXPECT_FALSE(StringUtils::AreAllCharactersWhitelisted(allAsciiChars, ""));
EXPECT_FALSE(StringUtils::AreAllCharactersWhitelisted("a", ""));
EXPECT_FALSE(StringUtils::AreAllCharactersWhitelisted("aaaaaaaaaaa", ""));
EXPECT_FALSE(StringUtils::AreAllCharactersWhitelisted(string(10000, ' '), ""));
// any non-empty string is NOT allowed against an empty list of characters
EXPECT_FALSE(StringUtils::AreAllCharactersAllowlisted(allAsciiChars, ""));
EXPECT_FALSE(StringUtils::AreAllCharactersAllowlisted("a", ""));
EXPECT_FALSE(StringUtils::AreAllCharactersAllowlisted("aaaaaaaaaaa", ""));
EXPECT_FALSE(StringUtils::AreAllCharactersAllowlisted(string(10000, ' '), ""));
// empty string is whitelisted against any whitelist of characters
EXPECT_TRUE(StringUtils::AreAllCharactersWhitelisted("", allAsciiChars));
EXPECT_TRUE(StringUtils::AreAllCharactersWhitelisted("", ""));
EXPECT_TRUE(StringUtils::AreAllCharactersWhitelisted("", "a"));
EXPECT_TRUE(StringUtils::AreAllCharactersWhitelisted("", "aaaaaaaaaaa"));
EXPECT_TRUE(StringUtils::AreAllCharactersWhitelisted("", string(10000, ' ')));
// empty string is allowed against any list of characters
EXPECT_TRUE(StringUtils::AreAllCharactersAllowlisted("", allAsciiChars));
EXPECT_TRUE(StringUtils::AreAllCharactersAllowlisted("", ""));
EXPECT_TRUE(StringUtils::AreAllCharactersAllowlisted("", "a"));
EXPECT_TRUE(StringUtils::AreAllCharactersAllowlisted("", "aaaaaaaaaaa"));
EXPECT_TRUE(StringUtils::AreAllCharactersAllowlisted("", string(10000, ' ')));
// a few more positive and negative tests
EXPECT_TRUE(StringUtils::AreAllCharactersWhitelisted("abc123", "abcdef123456"));
EXPECT_FALSE(StringUtils::AreAllCharactersWhitelisted("abc123", "abcdef23456"));
EXPECT_TRUE(StringUtils::AreAllCharactersAllowlisted("abc123", "abcdef123456"));
EXPECT_FALSE(StringUtils::AreAllCharactersAllowlisted("abc123", "abcdef23456"));
}
TEST(StringUtilsTests, ToString)