Fix anonymous users being pinged by justinfan64537 (#4698)

Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
This commit is contained in:
nerix 2023-06-20 19:42:29 +02:00 committed by GitHub
parent 53b044c476
commit 5d3e5d9312
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 70 additions and 21 deletions

View file

@ -14,6 +14,7 @@
- Bugfix: Fix spacing issue with mentions inside RTL text. (#4677) - Bugfix: Fix spacing issue with mentions inside RTL text. (#4677)
- Bugfix: Fixed a crash when opening and closing a reply thread and switching the user. (#4675) - Bugfix: Fixed a crash when opening and closing a reply thread and switching the user. (#4675)
- Bugfix: Fix visual glitches with smooth scrolling. (#4501) - Bugfix: Fix visual glitches with smooth scrolling. (#4501)
- Bugfix: Fixed pings firing for the "Your username" highlight when not signed in. (#4698)
- Dev: Added command to set Qt's logging filter/rules at runtime (`/c2-set-logging-rules`). (#4637) - Dev: Added command to set Qt's logging filter/rules at runtime (`/c2-set-logging-rules`). (#4637)
- Dev: Added the ability to see & load custom themes from the Themes directory. No stable promises are made of this feature, changes might be made that breaks custom themes without notice. (#4570) - Dev: Added the ability to see & load custom themes from the Themes directory. No stable promises are made of this feature, changes might be made that breaks custom themes without notice. (#4570)
- Dev: Added test cases for emote and tab completion. (#4644) - Dev: Added test cases for emote and tab completion. (#4644)

View file

@ -186,7 +186,8 @@ void rebuildMessageHighlights(Settings &settings,
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent(); auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
QString currentUsername = currentUser->getUserName(); QString currentUsername = currentUser->getUserName();
if (settings.enableSelfHighlight && !currentUsername.isEmpty()) if (settings.enableSelfHighlight && !currentUsername.isEmpty() &&
!currentUser->isAnon())
{ {
HighlightPhrase highlight( HighlightPhrase highlight(
currentUsername, settings.showSelfHighlightInMentions, currentUsername, settings.showSelfHighlightInMentions,

View file

@ -52,7 +52,7 @@ public:
} // namespace } // namespace
static QString DEFAULT_SETTINGS = R"!( static QString SETTINGS_DEFAULT = R"!(
{ {
"accounts": { "accounts": {
"uid117166826": { "uid117166826": {
@ -157,6 +157,10 @@ static QString DEFAULT_SETTINGS = R"!(
} }
})!"; })!";
static QString SETTINGS_ANON_EMPTY = R"!(
{
})!";
struct TestCase { struct TestCase {
// TODO: create one of these from a raw irc message? hmm xD // TODO: create one of these from a raw irc message? hmm xD
struct { struct {
@ -176,14 +180,14 @@ struct TestCase {
class HighlightControllerTest : public ::testing::Test class HighlightControllerTest : public ::testing::Test
{ {
protected: protected:
void SetUp() override void configure(const QString &settings, bool isAnon)
{ {
// Write default settings to the mock settings json file // Write default settings to the mock settings json file
this->settingsDir_ = std::make_unique<QTemporaryDir>(); this->settingsDir_ = std::make_unique<QTemporaryDir>();
QFile settingsFile(this->settingsDir_->filePath("settings.json")); QFile settingsFile(this->settingsDir_->filePath("settings.json"));
ASSERT_TRUE(settingsFile.open(QIODevice::WriteOnly | QIODevice::Text)); ASSERT_TRUE(settingsFile.open(QIODevice::WriteOnly | QIODevice::Text));
ASSERT_GT(settingsFile.write(DEFAULT_SETTINGS.toUtf8()), 0); ASSERT_GT(settingsFile.write(settings.toUtf8()), 0);
ASSERT_TRUE(settingsFile.flush()); ASSERT_TRUE(settingsFile.flush());
settingsFile.close(); settingsFile.close();
@ -192,7 +196,7 @@ protected:
initializeHelix(this->mockHelix); initializeHelix(this->mockHelix);
EXPECT_CALL(*this->mockHelix, loadBlocks).Times(Exactly(1)); EXPECT_CALL(*this->mockHelix, loadBlocks).Times(Exactly(1));
EXPECT_CALL(*this->mockHelix, update).Times(Exactly(1)); EXPECT_CALL(*this->mockHelix, update).Times(Exactly(isAnon ? 0 : 1));
this->mockApplication = std::make_unique<MockApplication>(); this->mockApplication = std::make_unique<MockApplication>();
this->settings = std::make_unique<Settings>(this->settingsDir_->path()); this->settings = std::make_unique<Settings>(this->settingsDir_->path());
@ -205,6 +209,23 @@ protected:
this->controller->initialize(*this->settings, *this->paths); this->controller->initialize(*this->settings, *this->paths);
} }
void runTests(const std::vector<TestCase> &tests)
{
for (const auto &[input, expected] : tests)
{
auto [isMatch, matchResult] = this->controller->check(
input.args, input.badges, input.senderName,
input.originalMessage, input.flags);
EXPECT_EQ(isMatch, expected.state)
<< qUtf8Printable(input.senderName) << ": "
<< qUtf8Printable(input.originalMessage);
EXPECT_EQ(matchResult, expected.result)
<< qUtf8Printable(input.senderName) << ": "
<< qUtf8Printable(input.originalMessage);
}
}
void TearDown() override void TearDown() override
{ {
this->mockApplication.reset(); this->mockApplication.reset();
@ -229,10 +250,10 @@ protected:
mock::Helix *mockHelix; mock::Helix *mockHelix;
}; };
TEST_F(HighlightControllerTest, A) TEST_F(HighlightControllerTest, LoggedInAndConfigured)
{ {
auto currentUser = configure(SETTINGS_DEFAULT, false);
this->mockApplication->getAccounts()->twitch.getCurrent();
std::vector<TestCase> tests{ std::vector<TestCase> tests{
{ {
{ {
@ -458,17 +479,43 @@ TEST_F(HighlightControllerTest, A)
}, },
}; };
for (const auto &[input, expected] : tests) this->runTests(tests);
{ }
auto [isMatch, matchResult] =
this->controller->check(input.args, input.badges, input.senderName, TEST_F(HighlightControllerTest, AnonEmpty)
input.originalMessage, input.flags); {
configure(SETTINGS_ANON_EMPTY, true);
EXPECT_EQ(isMatch, expected.state)
<< qUtf8Printable(input.senderName) << ": " std::vector<TestCase> tests{
<< qUtf8Printable(input.originalMessage); {
EXPECT_EQ(matchResult, expected.result) {
<< qUtf8Printable(input.senderName) << ": " // input
<< qUtf8Printable(input.originalMessage); MessageParseArgs{}, // no special args
} {}, // no badges
"pajlada2", // sender name
"hello!", // original message
},
{
// expected
false, // state
HighlightResult::emptyResult(), // result
},
},
{
// anonymous default username
{
MessageParseArgs{}, // no special args
{}, // no badges
"pajlada2", // sender name
"justinfan64537", // original message
},
{
// expected
false, // state
HighlightResult::emptyResult(), // result
},
},
};
this->runTests(tests);
} }