mirror of
https://github.com/znc/znc.git
synced 2026-03-28 17:42:41 +01:00
- PASS [user[@identifier][/network]:]password - USER user[@identifier][/network] ... NOTE: There's a slight ambiguosity with the '@' character, which happens to be a valid character in usernames, but also acts as a marker for the identifier. Therefore, '@' is considered as part of the username if it's followed by non-word characters (as in an email address), otherwise as a marker for an identifier. This is only an enabler for #343. The rest can be done with modules: - managing client ID specific playback buffers - filtering channels based on the client ID The reason this should be part of ZNC core is that only global modules have access to OnUnknownUserRaw(), which is needed to capture USER/PASS. First of all, the aforementioned modules shouldn't be global. Furthermore, it would be possible to have only one module that parsed and removed the client ID so that ZNC core woulnd't choke.
65 lines
3.0 KiB
C++
65 lines
3.0 KiB
C++
/*
|
|
* Copyright (C) 2004-2014 ZNC, see the NOTICE file for details.
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
#include <gtest/gtest.h>
|
|
#include <znc/Client.h>
|
|
#include <znc/znc.h>
|
|
|
|
class ClientTest : public ::testing::Test {
|
|
protected:
|
|
void SetUp() { CZNC::CreateInstance(); }
|
|
void TearDown() { CZNC::DestroyInstance(); }
|
|
void testPass(const CString& sInput, const CString& sUser, const CString& sIdentifier, const CString& sNetwork, const CString& sPass) const {
|
|
CClient client;
|
|
client.ParsePass(sInput);
|
|
EXPECT_EQ(sUser, client.m_sUser);
|
|
EXPECT_EQ(sIdentifier, client.m_sIdentifier);
|
|
EXPECT_EQ(sNetwork, client.m_sNetwork);
|
|
EXPECT_EQ(sPass, client.m_sPass);
|
|
}
|
|
|
|
void testUser(const CString& sInput, const CString& sUser, const CString& sIdentifier, const CString& sNetwork) const {
|
|
CClient client;
|
|
client.ParseUser(sInput);
|
|
EXPECT_EQ(sUser, client.m_sUser);
|
|
EXPECT_EQ(sIdentifier, client.m_sIdentifier);
|
|
EXPECT_EQ(sNetwork, client.m_sNetwork);
|
|
}
|
|
};
|
|
|
|
TEST_F(ClientTest, Pass) {
|
|
testPass("p@ss#w0rd", "", "", "", "p@ss#w0rd");
|
|
testPass("user:p@ss#w0rd", "user", "", "", "p@ss#w0rd");
|
|
testPass("user/net-work:p@ss#w0rd", "user", "", "net-work", "p@ss#w0rd");
|
|
testPass("user@identifier:p@ss#w0rd", "user", "identifier", "", "p@ss#w0rd");
|
|
testPass("user@identifier/net-work:p@ss#w0rd", "user", "identifier", "net-work", "p@ss#w0rd");
|
|
|
|
testPass("user@znc.in:p@ss#w0rd", "user@znc.in", "", "", "p@ss#w0rd");
|
|
testPass("user@znc.in/net-work:p@ss#w0rd", "user@znc.in", "", "net-work", "p@ss#w0rd");
|
|
testPass("user@znc.in@identifier:p@ss#w0rd", "user@znc.in", "identifier", "", "p@ss#w0rd");
|
|
testPass("user@znc.in@identifier/net-work:p@ss#w0rd", "user@znc.in", "identifier", "net-work", "p@ss#w0rd");
|
|
}
|
|
|
|
TEST_F(ClientTest, User) {
|
|
testUser("user/net-work", "user", "", "net-work");
|
|
testUser("user@identifier", "user", "identifier", "");
|
|
testUser("user@identifier/net-work", "user", "identifier", "net-work");
|
|
|
|
testUser("user@znc.in/net-work", "user@znc.in", "", "net-work");
|
|
testUser("user@znc.in@identifier", "user@znc.in", "identifier", "");
|
|
testUser("user@znc.in@identifier/net-work", "user@znc.in", "identifier", "net-work");
|
|
}
|