| #include "credential_pipe.hpp" |
| |
| #include <unistd.h> |
| |
| #include <boost/asio/io_context.hpp> |
| #include <boost/beast/core/file_posix.hpp> |
| #include <boost/system/detail/error_code.hpp> |
| |
| #include <array> |
| #include <cstddef> |
| #include <functional> |
| #include <string> |
| |
| #include <gmock/gmock.h> |
| #include <gtest/gtest.h> |
| |
| using ::testing::ElementsAre; |
| |
| static void handler(boost::asio::io_context& io, |
| const boost::system::error_code& ec, size_t sent) |
| { |
| io.stop(); |
| EXPECT_FALSE(ec); |
| EXPECT_EQ(sent, 18); |
| } |
| |
| TEST(CredentialsPipe, BasicSend) |
| { |
| boost::beast::file_posix file; |
| { |
| boost::asio::io_context io; |
| CredentialsPipe pipe(io); |
| file.native_handle(dup(pipe.fd())); |
| ASSERT_GT(file.native_handle(), 0); |
| pipe.asyncWrite("username", "password", |
| std::bind_front(handler, std::ref(io))); |
| io.run(); |
| } |
| std::array<char, 18> buff{}; |
| boost::system::error_code ec; |
| size_t r = file.read(buff.data(), buff.size(), ec); |
| ASSERT_FALSE(ec); |
| ASSERT_EQ(r, 18); |
| |
| EXPECT_THAT(buff, |
| ElementsAre('u', 's', 'e', 'r', 'n', 'a', 'm', 'e', '\0', 'p', |
| 'a', 's', 's', 'w', 'o', 'r', 'd', '\0')); |
| } |