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

Windows: Fix address_imp_test #11334

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions source/common/api/win32/os_sys_calls_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ SysCallIntResult OsSysCallsImpl::bind(os_fd_t sockfd, const sockaddr* addr, sock
}

SysCallIntResult OsSysCallsImpl::chmod(const std::string& path, mode_t mode) {
//
// Windows only supports _S_IWRITE and _S_IREAD bits, other bits will be ignored.
// Also all files are always readable; it is not possible to give write-only permission.
// For more granular security we need to rely on access-control-list (ACL) on Windows.
//
const int rc = ::_chmod(path.c_str(), mode);
return {rc, rc != -1 ? 0 : errno};
}
Expand Down
8 changes: 4 additions & 4 deletions source/common/network/address_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,8 @@ IoHandlePtr Ipv6Instance::socket(SocketType type) const {
PipeInstance::PipeInstance(const sockaddr_un* address, socklen_t ss_len, mode_t mode)
: InstanceBase(Type::Pipe) {
if (address->sun_path[0] == '\0') {
#if !defined(__linux__)
throw EnvoyException("Abstract AF_UNIX sockets are only supported on linux.");
#if defined(__APPLE__)
throw EnvoyException("Abstract AF_UNIX sockets are only supported on linux/windows.");
#endif
RELEASE_ASSERT(static_cast<unsigned int>(ss_len) >= offsetof(struct sockaddr_un, sun_path) + 1,
"");
Expand Down Expand Up @@ -396,8 +396,8 @@ PipeInstance::PipeInstance(const std::string& pipe_path, mode_t mode) : Instance
// characters of pipe_path to sun_path, including null bytes in the name. The pathname must also
// be null terminated. The friendly name is the address path with embedded nulls replaced with
// '@' for consistency with the first character.
#if !defined(__linux__)
throw EnvoyException("Abstract AF_UNIX sockets are only supported on linux.");
#if defined(__APPLE__)
throw EnvoyException("Abstract AF_UNIX sockets are only supported on linux/windows.");
#endif
if (mode != 0) {
throw EnvoyException("Cannot set mode for Abstract AF_UNIX sockets");
Expand Down
1 change: 0 additions & 1 deletion test/common/network/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ envoy_cc_test_library(
envoy_cc_test(
name = "address_impl_test",
srcs = ["address_impl_test.cc"],
tags = ["fails_on_windows"],
deps = [
"//source/common/network:address_lib",
"//source/common/network:utility_lib",
Expand Down
10 changes: 5 additions & 5 deletions test/common/network/address_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ TEST(PipeInstanceTest, Basic) {
TEST(PipeInstanceTest, BasicPermission) {
std::string path = TestEnvironment::unixDomainSocketPath("foo.sock");

const mode_t mode = 0777;
const mode_t mode = 0666;
PipeInstance address(path, mode);

IoHandlePtr io_handle = address.socket(SocketType::Stream);
Expand Down Expand Up @@ -361,7 +361,7 @@ TEST(PipeInstanceTest, PermissionFail) {
}

TEST(PipeInstanceTest, AbstractNamespacePermission) {
#if defined(__linux__)
#if defined(__linux__) || defined(WIN32)
std::string path = "@/foo";
const mode_t mode = 0777;
EXPECT_THROW_WITH_REGEX(PipeInstance address(path, mode), EnvoyException,
Expand All @@ -379,7 +379,7 @@ TEST(PipeInstanceTest, AbstractNamespacePermission) {
}

TEST(PipeInstanceTest, AbstractNamespace) {
#if defined(__linux__)
#if defined(__linux__) || defined(WIN32)
PipeInstance address("@/foo");
EXPECT_EQ("@/foo", address.asString());
EXPECT_EQ("@/foo", address.asStringView());
Expand All @@ -398,9 +398,9 @@ TEST(PipeInstanceTest, BadAddress) {

// Validate that embedded nulls in abstract socket addresses are included and represented with '@'.
TEST(PipeInstanceTest, EmbeddedNullAbstractNamespace) {
#if defined(__linux__) || defined(WIN32)
std::string embedded_null("@/foo/bar");
embedded_null[5] = '\0'; // Set embedded null.
#if defined(__linux__)
PipeInstance address(embedded_null);
EXPECT_EQ("@/foo@bar", address.asString());
EXPECT_EQ("@/foo@bar", address.asStringView());
Expand Down Expand Up @@ -496,7 +496,7 @@ TEST(AddressFromSockAddrDeathTest, Pipe) {
StringUtil::strlcpy(&sun.sun_path[1], "/some/abstract/path", sizeof sun.sun_path);
sun.sun_path[0] = '\0';
ss_len = offsetof(struct sockaddr_un, sun_path) + 1 + strlen("/some/abstract/path");
#if defined(__linux__)
#if defined(__linux__) || defined(WIN32)
EXPECT_EQ("@/some/abstract/path", addressFromSockAddr(ss, ss_len)->asString());
#else
EXPECT_THROW(addressFromSockAddr(ss, ss_len), EnvoyException);
Expand Down