mirror of
https://github.com/OpenVPN/openvpn3.git
synced 2024-09-19 19:52:15 +02:00
test_splitlines: New UT for SplitLines
Also enable UserPass UT that now passes with new SplitLines. Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
This commit is contained in:
parent
4620b1f8cd
commit
59a1d2398e
@ -59,7 +59,8 @@ add_executable(coreUnitTests
|
||||
test_randapi.cpp
|
||||
test_rc.cpp
|
||||
test_route.cpp
|
||||
test_reliable.cpp
|
||||
test_reliable.cpp
|
||||
test_splitlines.cpp
|
||||
test_statickey.cpp
|
||||
test_streq.cpp
|
||||
test_time.cpp
|
||||
|
124
test/unittests/test_splitlines.cpp
Normal file
124
test/unittests/test_splitlines.cpp
Normal file
@ -0,0 +1,124 @@
|
||||
// OpenVPN -- An application to securely tunnel IP networks
|
||||
// over a single port, with support for SSL/TLS-based
|
||||
// session authentication and key exchange,
|
||||
// packet encryption, packet authentication, and
|
||||
// packet compression.
|
||||
//
|
||||
// Copyright (C) 2012-2023 OpenVPN Inc.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License Version 3
|
||||
// as published by the Free Software Foundation.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program in the COPYING file.
|
||||
|
||||
#include "test_common.h"
|
||||
|
||||
#include <openvpn/common/splitlines.hpp>
|
||||
|
||||
using namespace openvpn;
|
||||
|
||||
const std::string short_text = "Lorem\nipsum\r\ndolor\n\r\nsit";
|
||||
const std::vector<std::string> short_lines{"Lorem\n", "ipsum\r\n", "dolor\n", "\r\n", "sit"};
|
||||
const std::vector<std::string> short_lines_trim{"Lorem", "ipsum", "dolor", "", "sit"};
|
||||
|
||||
TEST(SplitLines, no_max_length_no_trim)
|
||||
{
|
||||
SplitLines in(short_text, 0);
|
||||
size_t index = 0;
|
||||
while (in(false))
|
||||
{
|
||||
ASSERT_EQ(in.line_ref(), short_lines[index++]);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(SplitLines, next_no_max_length_no_trim)
|
||||
{
|
||||
SplitLines in(short_text, 0);
|
||||
size_t index = 0;
|
||||
std::string line;
|
||||
SplitLines::Status ret = SplitLines::S_OKAY;
|
||||
while ((ret = in.next(line, false)) != SplitLines::S_EOF)
|
||||
{
|
||||
ASSERT_EQ(ret, SplitLines::S_OKAY);
|
||||
ASSERT_EQ(line, short_lines[index++]);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(SplitLines, no_max_length_trim)
|
||||
{
|
||||
SplitLines in(short_text, 0);
|
||||
size_t index = 0;
|
||||
while (in(true))
|
||||
{
|
||||
ASSERT_FALSE(in.line_overflow());
|
||||
ASSERT_EQ(in.line_ref(), short_lines_trim[index++]);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(SplitLines, next_no_max_length_trim)
|
||||
{
|
||||
SplitLines in(short_text, 0);
|
||||
size_t index = 0;
|
||||
std::string line;
|
||||
SplitLines::Status ret = SplitLines::S_OKAY;
|
||||
while ((ret = in.next(line, true)) != SplitLines::S_EOF)
|
||||
{
|
||||
ASSERT_EQ(ret, SplitLines::S_OKAY);
|
||||
ASSERT_EQ(line, short_lines_trim[index++]);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(SplitLines, max_length)
|
||||
{
|
||||
SplitLines in(short_text, 24);
|
||||
size_t index = 0;
|
||||
while (in(true))
|
||||
{
|
||||
ASSERT_FALSE(in.line_overflow());
|
||||
ASSERT_EQ(in.line_ref(), short_lines_trim[index++]);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(SplitLines, next_max_length)
|
||||
{
|
||||
SplitLines in(short_text, 24);
|
||||
size_t index = 0;
|
||||
std::string line;
|
||||
SplitLines::Status ret = SplitLines::S_OKAY;
|
||||
while ((ret = in.next(line, true)) != SplitLines::S_EOF)
|
||||
{
|
||||
ASSERT_EQ(ret, SplitLines::S_OKAY);
|
||||
ASSERT_EQ(line, short_lines_trim[index++]);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(SplitLines, max_length_overflow)
|
||||
{
|
||||
SplitLines in(short_text, 3);
|
||||
ASSERT_TRUE(in(true));
|
||||
ASSERT_TRUE(in.line_overflow());
|
||||
ASSERT_THROW(in.line_ref(), SplitLines::splitlines_overflow_error);
|
||||
}
|
||||
|
||||
TEST(SplitLines, next_max_length_overflow)
|
||||
{
|
||||
SplitLines in(short_text, 3);
|
||||
std::string line;
|
||||
ASSERT_EQ(in.next(line, true), SplitLines::S_ERROR);
|
||||
}
|
||||
|
||||
TEST(SplitLines, moved_error)
|
||||
{
|
||||
SplitLines in(short_text);
|
||||
ASSERT_TRUE(in(true));
|
||||
ASSERT_FALSE(in.line_overflow());
|
||||
std::string line = in.line_move();
|
||||
ASSERT_THROW(in.line_ref(), SplitLines::splitlines_moved_error);
|
||||
}
|
@ -4,7 +4,7 @@
|
||||
// packet encryption, packet authentication, and
|
||||
// packet compression.
|
||||
//
|
||||
// Copyright (C) 2012-2022 OpenVPN Inc.
|
||||
// Copyright (C) 2012-2023 OpenVPN Inc.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License Version 3
|
||||
@ -362,7 +362,7 @@ TEST(UserPass, parse_file_user_pass)
|
||||
}
|
||||
}
|
||||
|
||||
TEST(DISABLED_UserPass, parse_file_overflow)
|
||||
TEST(UserPass, parse_file_overflow)
|
||||
{
|
||||
for (auto flags : flag_combos_nofile)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user