Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restored TLS CI tests #197

Merged
merged 31 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
ffddeba
Restored TLS tests & rework
anarthal Mar 31, 2024
3e945e9
Fixed unused variable warning in connection_base
anarthal Mar 31, 2024
1be2c07
get_server_hostname utility function
anarthal Mar 31, 2024
ccfed82
Test TLS files
anarthal Apr 1, 2024
01bd35a
Remove debug statement in test_conn_tls
anarthal Apr 1, 2024
ec0d80f
CI with Docker compose
anarthal Apr 1, 2024
f858c0b
sudo removal
anarthal Apr 1, 2024
de24f9e
Missing backslashes in ci.yml
anarthal Apr 1, 2024
49fe967
Debugging compose
anarthal Apr 1, 2024
6bc6fd7
Add git
anarthal Apr 1, 2024
77316b4
Missing ca-certificates
anarthal Apr 1, 2024
70be9df
Permission change
anarthal Apr 1, 2024
a91cf59
Docker compose with build step
anarthal Apr 1, 2024
dd07fa4
ca-certificates
anarthal Apr 1, 2024
fae456d
Missing git
anarthal Apr 1, 2024
af6cd33
Missing packages
anarthal Apr 1, 2024
155cdcb
make instead of ninja
anarthal Apr 1, 2024
700c371
Include cleanup
anarthal Apr 1, 2024
7eeb5b7
Missing ports in docker-compose
anarthal Apr 1, 2024
2c0b1a0
Attempt to run without container
anarthal Apr 1, 2024
0b4172e
missing sudo
anarthal Apr 1, 2024
6e66421
Container service
anarthal Apr 1, 2024
d30326d
Removed sudo
anarthal Apr 1, 2024
69ec0c1
Removed external service
anarthal Apr 1, 2024
f7cea86
Removed need
anarthal Apr 1, 2024
5047b89
Removed interactive flag
anarthal Apr 1, 2024
9ee5de8
Incorrect directory for docker-compose
anarthal Apr 1, 2024
d627804
Correct volume mount
anarthal Apr 1, 2024
eaa54bb
Missing package & env var
anarthal Apr 1, 2024
5baf372
docker-compose without build
anarthal Apr 1, 2024
bcbeac8
Leftovers cleanup
anarthal Apr 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 28 additions & 35 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
CMAKE_BUILD_PARALLEL_LEVEL: 4
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup Boost
run: python3 tools/ci.py setup-boost --source-dir=$(pwd)
Expand Down Expand Up @@ -106,7 +106,7 @@ jobs:
OPENSSL_ROOT: "C:\\Program Files\\OpenSSL"
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup user-config.jam
run: cp tools/user-config.jam "${HOMEDRIVE}${HOMEPATH}/"
Expand Down Expand Up @@ -134,55 +134,48 @@ jobs:
- toolset: gcc-11
install: g++-11
os: ubuntu-latest
container: ubuntu:22.04
cxxstd: '17'
build-type: 'Debug'
ldflags: ''

- toolset: gcc-11
install: g++-11
os: ubuntu-latest
container: ubuntu:22.04
cxxstd: '20'
build-type: 'Release'
ldflags: ''

- toolset: clang-11
install: clang-11
os: ubuntu-latest
container: ubuntu:22.04
cxxstd: '17'
build-type: 'Debug'
ldflags: ''

- toolset: clang-11
install: clang-11
os: ubuntu-latest
container: ubuntu:22.04
cxxstd: '20'
build-type: 'Debug'
ldflags: ''

- toolset: clang-13
install: clang-13
os: ubuntu-latest
container: ubuntu:22.04
cxxstd: '17'
build-type: 'Release'
ldflags: ''

- toolset: clang-13
install: clang-13
os: ubuntu-latest
container: ubuntu:22.04
cxxstd: '20'
build-type: 'Release'
ldflags: ''

- toolset: clang-14
install: 'clang-14 libc++-14-dev libc++abi-14-dev'
os: ubuntu-latest
container: ubuntu:22.04
cxxstd: '17'
build-type: 'Debug'
cxxflags: '-stdlib=libc++'
Expand All @@ -191,83 +184,83 @@ jobs:
- toolset: clang-14
install: 'clang-14 libc++-14-dev libc++abi-14-dev'
os: ubuntu-latest
container: ubuntu:22.04
cxxstd: '20'
build-type: 'Release'
cxxflags: '-stdlib=libc++'
ldflags: '-lc++'

runs-on: ${{ matrix.os }}
container: ${{matrix.container}}
env:
CXXFLAGS: ${{matrix.cxxflags}} -Wall -Wextra
LDFLAGS: ${{matrix.ldflags}}
CMAKE_BUILD_PARALLEL_LEVEL: 4
BOOST_REDIS_TEST_SERVER: redis

services:
redis:
image: redis


steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup container environment
if: matrix.container
uses: actions/checkout@v4

- name: Set up the required containers
run: |
apt-get update
apt-get -y install sudo python3 git g++ libssl-dev protobuf-compiler redis-server

docker compose -f tools/docker-compose.yml up -d --wait || (docker compose logs; exit 1)

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get -y install cmake protobuf-compiler redis-server python3 ${{ matrix.install }}
docker exec builder apt-get update
docker exec builder apt-get -y --no-install-recommends install \
git \
g++ \
libssl-dev \
make \
ca-certificates \
cmake \
protobuf-compiler \
python3 \
${{ matrix.install }}

- name: Setup Boost
run: ./tools/ci.py setup-boost --source-dir=$(pwd)
run: docker exec builder /boost-redis/tools/ci.py setup-boost --source-dir=/boost-redis

- name: Build a Boost distribution using B2
run: |
./tools/ci.py build-b2-distro \
docker exec builder /boost-redis/tools/ci.py build-b2-distro \
--toolset ${{ matrix.toolset }}

- name: Build a Boost distribution using CMake
run: |
./tools/ci.py build-cmake-distro \
docker exec builder /boost-redis/tools/ci.py build-cmake-distro \
--build-type ${{ matrix.build-type }} \
--cxxstd ${{ matrix.cxxstd }} \
--toolset ${{ matrix.toolset }}

- name: Build the project tests
run: |
./tools/ci.py build-cmake-standalone-tests \
docker exec builder /boost-redis/tools/ci.py build-cmake-standalone-tests \
--build-type ${{ matrix.build-type }} \
--cxxstd ${{ matrix.cxxstd }} \
--toolset ${{ matrix.toolset }}

- name: Run the project tests
run: |
./tools/ci.py run-cmake-standalone-tests \
docker exec builder /boost-redis/tools/ci.py run-cmake-standalone-tests \
--build-type ${{ matrix.build-type }}

- name: Run add_subdirectory tests
run: |
./tools/ci.py run-cmake-add-subdirectory-tests \
docker exec builder /boost-redis/tools/ci.py run-cmake-add-subdirectory-tests \
--build-type ${{ matrix.build-type }} \
--cxxstd ${{ matrix.cxxstd }} \
--toolset ${{ matrix.toolset }}

- name: Run find_package tests with the built cmake distribution
run: |
./tools/ci.py run-cmake-find-package-tests \
docker exec builder /boost-redis/tools/ci.py run-cmake-find-package-tests \
--build-type ${{ matrix.build-type }} \
--cxxstd ${{ matrix.cxxstd }} \
--toolset ${{ matrix.toolset }}

- name: Run find_package tests with the built b2 distribution
run: |
./tools/ci.py run-cmake-b2-find-package-tests \
docker exec builder /boost-redis/tools/ci.py run-cmake-b2-find-package-tests \
--build-type ${{ matrix.build-type }} \
--cxxstd ${{ matrix.cxxstd }} \
--toolset ${{ matrix.toolset }}
Expand Down Expand Up @@ -296,7 +289,7 @@ jobs:
container: ${{matrix.container}}
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup container environment
if: matrix.container
Expand Down
2 changes: 1 addition & 1 deletion include/boost/redis/detail/connection_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ struct exec_op {
asio::coroutine coro{};

template <class Self>
void operator()(Self& self , system::error_code ec = {}, std::size_t = 0)
void operator()(Self& self , system::error_code = {}, std::size_t = 0)
{
BOOST_ASIO_CORO_REENTER (coro)
{
Expand Down
3 changes: 1 addition & 2 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ macro(make_test TEST_NAME STANDARD)
endmacro()

make_test(test_conn_quit 17)
# TODO: Configure a Redis server with TLS in the CI and reenable this test.
#make_test(test_conn_tls 17)
make_test(test_conn_tls 17)
make_test(test_low_level 17)
make_test(test_conn_exec_retry 17)
make_test(test_conn_exec_error 17)
Expand Down
9 changes: 7 additions & 2 deletions test/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ run(
conn->async_run(cfg, {l}, run_callback{conn, op, ec});
}

std::string safe_getenv(const char* name, const char* default_value)
static std::string safe_getenv(const char* name, const char* default_value)
{
// MSVC doesn't like getenv
#ifdef BOOST_MSVC
Expand All @@ -43,10 +43,15 @@ std::string safe_getenv(const char* name, const char* default_value)
return res ? res : default_value;
}

std::string get_server_hostname()
{
return safe_getenv("BOOST_REDIS_TEST_SERVER", "localhost");
}

boost::redis::config make_test_config()
{
boost::redis::config cfg;
cfg.addr.host = safe_getenv("BOOST_REDIS_TEST_SERVER", "localhost");
cfg.addr.host = get_server_hostname();
return cfg;
}

Expand Down
1 change: 1 addition & 0 deletions test/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ auto start(boost::asio::awaitable<void> op) -> int;
#endif // BOOST_ASIO_HAS_CO_AWAIT

boost::redis::config make_test_config();
std::string get_server_hostname();

void
run(
Expand Down
108 changes: 53 additions & 55 deletions test/test_conn_tls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
* accompanying file LICENSE.txt)
*/

#include <boost/asio/ssl/host_name_verification.hpp>
#include <boost/system/error_code.hpp>
#include <boost/redis/connection.hpp>
#define BOOST_TEST_MODULE conn-tls
#include <boost/test/included/unit_test.hpp>
#include <iostream>
#include "common.hpp"

namespace net = boost::asio;
Expand All @@ -16,24 +17,49 @@ using connection = boost::redis::connection;
using boost::redis::request;
using boost::redis::response;
using boost::redis::config;
using boost::redis::operation;
using boost::system::error_code;

bool verify_certificate(bool, net::ssl::verify_context&)
{
std::cout << "set_verify_callback" << std::endl;
return true;
}

config make_tls_config()
// CA certificate that signed the test server's certificate.
// This is a self-signed CA created for testing purposes.
// This must match tools/tls/ca.crt contents
static constexpr const char* ca_certificate = R"%(-----BEGIN CERTIFICATE-----
MIIFSzCCAzOgAwIBAgIUNd7VUuGK4+ylzCOrmeckg2+TqX8wDQ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Af8wDQYJKoZIhvcNAQELBQADggIBAFLl1NZHp0NT5Av4GKmsJFeI
cJOgcIygjR4SBGDAxyPqVpZk0x1q64gJsfOe1ARyI4olQPqO08FZMeB+VBYuqR3S
fEVQZz2FT5U7IVAEZwWHOcWkrrVpEZC6PZktYJ7Yqju6+ic93inoPrHhGNZ5XA/Y
GSfwriWkyWm2SOk35ChFH67MbPWmve8CRAXRmrOCByXwXF87wdqVYZUvH9xDe6WU
snFWXVHr2NA7Re8ZIGp7yJOwwW+CZagepNCPUDwnI0fWOahtOTzonIjq8bfgTZPx
2e7lBuAr9tVMpoeyUytVOlNJDojZAtKOpfMwhAG8ydhk+78aK07VVbnSYVhv7ctU
kkkldqP/S3lBlWo44oOxenwLc9vDQNh64py7eQTD7Qv+TjqAG0ljHIDbVqlkQsgR
pQsu7keG9O1xASSTLZVZN2/alNewpqE/eFRfPM3mtUiTiIZvSxiQnWQMbKofAZH5
HwhVli4RKWRWPqpof4GFNkB8XwfBE+gdlFuWtyg0oRyV3sJ6Zn7E+lUpbQX4CFx3
97vekaFNBchNYMcP3TZ9LwxTx1xOWZ5HHrHyzASG3uz2rqwAsEmdRbmK03KfEQyQ
YpNY718btZ1D6lLino9VMgzaPhUs79bHC64O4ncl7hRclK9qa3KLQdCG1cbIR7G0
2XVYrfsnPHX0CsPDIy7L
-----END CERTIFICATE-----)%";

static config make_tls_config()
{
config cfg;
cfg.use_ssl = true;
cfg.username = "aedis";
cfg.password = "aedis";
cfg.addr.host = "db.occase.de";
cfg.addr.host = get_server_hostname();
cfg.addr.port = "6380";
//cfg.health_check_interval = std::chrono::seconds{0};
return cfg;
}

Expand All @@ -49,11 +75,13 @@ BOOST_AUTO_TEST_CASE(ping_internal_ssl_context)

net::io_context ioc;
connection conn{ioc};
conn.next_layer().set_verify_mode(net::ssl::verify_peer);
conn.next_layer().set_verify_callback(verify_certificate);

conn.async_exec(req, resp, [&](auto ec, auto) {
BOOST_TEST(!ec);
// The custom server uses a certificate signed by a CA
// that is not trusted by default - skip verification.
conn.next_layer().set_verify_mode(net::ssl::verify_none);

conn.async_exec(req, resp, [&](error_code ec, auto) {
BOOST_TEST(ec == std::error_code());
conn.cancel();
});

Expand All @@ -76,12 +104,17 @@ BOOST_AUTO_TEST_CASE(ping_custom_ssl_context)

net::io_context ioc;
net::ssl::context ctx{boost::asio::ssl::context::tls_client};

// Configure the SSL context to trust the CA that signed the server's certificate.
// The test certificate uses "redis" as its common name, regardless of the actual server's hostname
ctx.add_certificate_authority(net::const_buffer(ca_certificate, std::strlen(ca_certificate)));
ctx.set_verify_mode(net::ssl::verify_peer);
ctx.set_verify_callback(net::ssl::host_name_verification("redis"));

connection conn{ioc, std::move(ctx)};
conn.next_layer().set_verify_mode(net::ssl::verify_peer);
conn.next_layer().set_verify_callback(verify_certificate);

conn.async_exec(req, resp, [&](auto ec, auto) {
BOOST_TEST(!ec);
BOOST_TEST(ec == std::error_code());
conn.cancel();
});

Expand All @@ -91,38 +124,3 @@ BOOST_AUTO_TEST_CASE(ping_custom_ssl_context)

BOOST_CHECK_EQUAL(in, std::get<0>(resp).value());
}

BOOST_AUTO_TEST_CASE(acl_does_not_allow_select)
{
auto cfg = make_tls_config();
cfg.database_index = 22;
cfg.reconnect_wait_interval = std::chrono::seconds::zero();

std::string const in = "Kabuf";

request req;
req.push("PING", in);

response<std::string> resp;

net::io_context ioc;
connection conn{ioc};
conn.next_layer().set_verify_mode(net::ssl::verify_peer);
conn.next_layer().set_verify_callback(verify_certificate);

conn.async_exec(req, resp, [&](auto, auto) {
// TODO: We should not need this cancel here because
// reconnect was disabled.
conn.cancel();
});


error_code ec2;
conn.async_run(cfg, {}, [&](auto ec) {
ec2 = ec;
});

ioc.run();

BOOST_TEST(!!ec2);
}
Loading