Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
B
brpc
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
brpc
Commits
74abdd83
Commit
74abdd83
authored
Sep 21, 2017
by
Zhangyi Chen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix the failure of FileUtilTest when the user is root
parent
e5e737c3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
3 deletions
+33
-3
bvar_reducer_unittest.cpp
test/bvar_reducer_unittest.cpp
+1
-1
file_util_unittest.cc
test/file_util_unittest.cc
+32
-2
No files found.
test/bvar_reducer_unittest.cpp
View file @
74abdd83
...
...
@@ -276,7 +276,7 @@ static void* string_appender(void* arg) {
int
count
=
0
;
std
::
string
id
=
butil
::
string_printf
(
"%lld"
,
(
long
long
)
pthread_self
());
std
::
string
tmp
=
"a"
;
for
(
count
=
0
;
!
g_stop
;
++
count
)
{
for
(
count
=
0
;
!
count
||
!
g_stop
;
++
count
)
{
*
cater
<<
id
<<
":"
;
for
(
char
c
=
'a'
;
c
<=
'z'
;
++
c
)
{
tmp
[
0
]
=
c
;
...
...
test/file_util_unittest.cc
View file @
74abdd83
...
...
@@ -16,6 +16,7 @@
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#endif
#include <algorithm>
...
...
@@ -182,11 +183,33 @@ const int FILES_AND_DIRECTORIES =
class
FileUtilTest
:
public
testing
::
Test
{
protected
:
virtual
void
SetUp
()
OVERRIDE
{
#if defined(OS_POSIX)
if
(
getuid
()
==
0
)
{
is_root_
=
true
;
ASSERT_EQ
(
0
,
setegid
(
65534
));
ASSERT_EQ
(
0
,
seteuid
(
65534
));
}
else
{
is_root_
=
false
;
}
#endif
testing
::
Test
::
SetUp
();
ASSERT_TRUE
(
temp_dir_
.
CreateUniqueTempDir
());
}
#if defined(OS_POSIX)
virtual
void
TearDown
()
OVERRIDE
{
if
(
is_root_
)
{
ASSERT_EQ
(
0
,
seteuid
(
0
));
ASSERT_EQ
(
0
,
setegid
(
0
));
is_root_
=
false
;
}
testing
::
Test
::
TearDown
();
}
#endif
ScopedTempDir
temp_dir_
;
#if defined(OS_POSIX)
bool
is_root_
;
#endif
};
// Collects all the results from the given file enumerator, and provides an
...
...
@@ -767,7 +790,9 @@ TEST_F(FileUtilTest, ChangeFilePermissionsAndWrite) {
EXPECT_FALSE
(
mode
&
FILE_PERMISSION_WRITE_BY_USER
);
// Make sure the file can't be write.
EXPECT_EQ
(
-
1
,
WriteFile
(
file_name
,
kData
.
data
(),
kData
.
length
()));
EXPECT_FALSE
(
PathIsWritable
(
file_name
));
if
(
!
is_root_
)
{
EXPECT_FALSE
(
PathIsWritable
(
file_name
));
}
// Give read permission.
EXPECT_TRUE
(
SetPosixFilePermissions
(
file_name
,
...
...
@@ -2176,7 +2201,7 @@ class VerifyPathControlledByUserTest : public FileUtilTest {
ok_gids_
.
insert
(
stat_buf
.
st_gid
);
bad_gids_
.
insert
(
stat_buf
.
st_gid
+
1
);
ASSERT_EQ
(
uid_
,
getuid
());
// This process should be the owner.
ASSERT_EQ
(
uid_
,
get
e
uid
());
// This process should be the owner.
// To ensure that umask settings do not cause the initial state
// of permissions to be different from what we expect, explicitly
...
...
@@ -2196,6 +2221,11 @@ class VerifyPathControlledByUserTest : public FileUtilTest {
ChangePosixFilePermissions
(
sub_dir_
,
enabled_permissions
,
disabled_permissions
));
}
#if defined(OS_POSIX)
virtual
void
TearDown
()
OVERRIDE
{
FileUtilTest
::
TearDown
();
}
#endif
FilePath
base_dir_
;
FilePath
sub_dir_
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment