From 8c983564e8f34b3694b2b5ecce39d7dca5665a53 Mon Sep 17 00:00:00 2001 From: Alexey Sokolov Date: Thu, 31 Jul 2025 23:47:26 +0100 Subject: [PATCH] Add test for modperl SCString functions. Pass CClient to the OnClientGetSASLMechanisms callback. See #1970 --- src/Client.cpp | 5 ++-- test/integration/tests/scripting.cpp | 38 ++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src/Client.cpp b/src/Client.cpp index 4da46f34..0f60f9a1 100644 --- a/src/Client.cpp +++ b/src/Client.cpp @@ -1361,8 +1361,9 @@ void CClient::AcceptSASLLogin(CUser& User) { SCString CClient::EnumerateSASLMechanisms() const { SCString ssMechanisms; - // FIXME Currently GetClient()==nullptr due to const - GLOBALMODULECALL(OnClientGetSASLMechanisms(ssMechanisms), NOTHING); + // FIXME Fix this const_cast + _GLOBALMODULECALL(OnClientGetSASLMechanisms(ssMechanisms), nullptr, nullptr, + const_cast(this), NOTHING); return ssMechanisms; } diff --git a/test/integration/tests/scripting.cpp b/test/integration/tests/scripting.cpp index 442c2092..6cd51d4f 100644 --- a/test/integration/tests/scripting.cpp +++ b/test/integration/tests/scripting.cpp @@ -581,5 +581,43 @@ TEST_F(ZNCTest, ModperlSaslAuth) { "in as user"); } +TEST_F(ZNCTest, ModperlStringSet) { +#ifndef WANT_PERL + GTEST_SKIP() << "Modperl is disabled"; +#endif + auto znc = Run(); + znc->CanLeak(); + + InstallModule("sasltest.pm", R"( + package sasltest; + use base 'ZNC::Module'; + sub module_types { $ZNC::CModInfo::GlobalModule } + + sub OnClientGetSASLMechanisms { + my $self = shift; + my $mechs = shift; + $mechs->insert('FOO'); + $self->GetClient->PutClientRaw("Test1: <" . + $mechs->has_key('AAA') . '/' . + $mechs->has_key('FOO') . '>'); + $self->GetClient->PutClientRaw("Test2: " . + join('+', $mechs->keys) . '.'); + } + + 1; +)"); + + auto ircd = ConnectIRCd(); + auto client = LoginClient(); + client.Write("znc loadmod modperl"); + client.Write("znc loadmod sasltest"); + client.ReadUntil("Loaded"); + + auto client2 = ConnectClient(); + client2.Write("CAP LS 302"); + client2.ReadUntil("Test1: "); + client2.ReadUntil("Test2: FOO+PLAIN."); +} + } // namespace } // namespace znc_inttest