OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/socket/unix_domain_server_socket_posix.h" | 5 #include "net/socket/unix_domain_server_socket_posix.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
11 #include "base/files/scoped_temp_dir.h" | 11 #include "base/files/scoped_temp_dir.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
14 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
15 #include "net/base/io_buffer.h" | 15 #include "net/base/io_buffer.h" |
16 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
17 #include "net/base/test_completion_callback.h" | 17 #include "net/base/test_completion_callback.h" |
18 #include "net/socket/unix_domain_client_socket_posix.h" | 18 #include "net/socket/unix_domain_client_socket_posix.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
20 | 20 |
21 namespace net { | 21 namespace net { |
22 namespace { | 22 namespace { |
23 | 23 |
24 const char kSocketFilename[] = "socket_for_testing"; | 24 const char kSocketFilename[] = "socket_for_testing"; |
25 const char kInvalidSocketPath[] = "/invalid/path"; | 25 const char kInvalidSocketPath[] = "/invalid/path"; |
26 | 26 |
27 bool UserCanConnectCallback(bool allow_user, uid_t uid, gid_t gid) { | 27 bool UserCanConnectCallback(bool allow_user, |
| 28 const UnixDomainServerSocket::Credentials& credentials) { |
28 // Here peers are running in same process. | 29 // Here peers are running in same process. |
29 EXPECT_EQ(getuid(), uid); | 30 #if defined(OS_LINUX) || defined(OS_ANDROID) |
30 EXPECT_EQ(getgid(), gid); | 31 EXPECT_EQ(getpid(), credentials.process_id); |
| 32 #endif |
| 33 EXPECT_EQ(getuid(), credentials.user_id); |
| 34 EXPECT_EQ(getgid(), credentials.group_id); |
31 return allow_user; | 35 return allow_user; |
32 } | 36 } |
33 | 37 |
34 UnixDomainServerSocket::AuthCallback CreateAuthCallback(bool allow_user) { | 38 UnixDomainServerSocket::AuthCallback CreateAuthCallback(bool allow_user) { |
35 return base::Bind(&UserCanConnectCallback, allow_user); | 39 return base::Bind(&UserCanConnectCallback, allow_user); |
36 } | 40 } |
37 | 41 |
38 class UnixDomainServerSocketTest : public testing::Test { | 42 class UnixDomainServerSocketTest : public testing::Test { |
39 protected: | 43 protected: |
40 UnixDomainServerSocketTest() { | 44 UnixDomainServerSocketTest() { |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 // The server socket should not have called |accept_callback| or modified | 107 // The server socket should not have called |accept_callback| or modified |
104 // |accepted_socket|. | 108 // |accepted_socket|. |
105 EXPECT_FALSE(accept_callback.have_result()); | 109 EXPECT_FALSE(accept_callback.have_result()); |
106 EXPECT_FALSE(accepted_socket); | 110 EXPECT_FALSE(accepted_socket); |
107 } | 111 } |
108 | 112 |
109 // Normal cases including read/write are tested by UnixDomainClientSocketTest. | 113 // Normal cases including read/write are tested by UnixDomainClientSocketTest. |
110 | 114 |
111 } // namespace | 115 } // namespace |
112 } // namespace net | 116 } // namespace net |
OLD | NEW |