Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
54db2fd5
Kaydet (Commit)
54db2fd5
authored
Şub 20, 2013
tarafından
Serhiy Storchaka
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #15301: Enhance os.*chown() testing. Based on patch by Larry Hastings.
üst
774a39f2
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
21 deletions
+39
-21
test_posix.py
Lib/test/test_posix.py
+39
-21
No files found.
Lib/test/test_posix.py
Dosyayı görüntüle @
54db2fd5
...
@@ -234,30 +234,42 @@ class PosixTester(unittest.TestCase):
...
@@ -234,30 +234,42 @@ class PosixTester(unittest.TestCase):
def
_test_all_chown_common
(
self
,
chown_func
,
first_param
,
stat_func
):
def
_test_all_chown_common
(
self
,
chown_func
,
first_param
,
stat_func
):
"""Common code for chown, fchown and lchown tests."""
"""Common code for chown, fchown and lchown tests."""
def
check_stat
():
def
check_stat
(
uid
,
gid
):
if
stat_func
is
not
None
:
if
stat_func
is
not
None
:
stat
=
stat_func
(
first_param
)
stat
=
stat_func
(
first_param
)
self
.
assertEqual
(
stat
.
st_uid
,
os
.
getuid
())
self
.
assertEqual
(
stat
.
st_uid
,
uid
)
self
.
assertEqual
(
stat
.
st_gid
,
os
.
getgid
())
self
.
assertEqual
(
stat
.
st_gid
,
gid
)
uid
=
os
.
getuid
()
gid
=
os
.
getgid
()
# test a successful chown call
# test a successful chown call
chown_func
(
first_param
,
os
.
getuid
(),
os
.
getgid
())
chown_func
(
first_param
,
uid
,
gid
)
check_stat
()
check_stat
(
uid
,
gid
)
chown_func
(
first_param
,
-
1
,
os
.
getgid
())
chown_func
(
first_param
,
-
1
,
gid
)
check_stat
()
check_stat
(
uid
,
gid
)
chown_func
(
first_param
,
os
.
getuid
(),
-
1
)
chown_func
(
first_param
,
uid
,
-
1
)
check_stat
()
check_stat
(
uid
,
gid
)
if
os
.
getuid
()
==
0
:
if
uid
==
0
:
try
:
# Try an amusingly large uid/gid to make sure we handle
# Many linux distros have a nfsnobody user as MAX_UID-2
# large unsigned values. (chown lets you use any
# that makes a good test case for signedness issues.
# uid/gid you like, even if they aren't defined.)
#
# This problem keeps coming up:
# http://bugs.python.org/issue1747858
# http://bugs.python.org/issue1747858
# http://bugs.python.org/issue4591
# http://bugs.python.org/issue15301
# Hopefully the fix in 4591 fixes it for good!
#
# This part of the test only runs when run as root.
# This part of the test only runs when run as root.
# Only scary people run their tests as root.
# Only scary people run their tests as root.
ent
=
pwd
.
getpwnam
(
'nfsnobody'
)
chown_func
(
first_param
,
ent
.
pw_uid
,
ent
.
pw_gid
)
big_value
=
2
**
31
except
KeyError
:
chown_func
(
first_param
,
big_value
,
big_value
)
pass
check_stat
(
big_value
,
big_value
)
chown_func
(
first_param
,
-
1
,
-
1
)
check_stat
(
big_value
,
big_value
)
chown_func
(
first_param
,
uid
,
gid
)
check_stat
(
uid
,
gid
)
elif
platform
.
system
()
in
(
'HP-UX'
,
'SunOS'
):
elif
platform
.
system
()
in
(
'HP-UX'
,
'SunOS'
):
# HP-UX and Solaris can allow a non-root user to chown() to root
# HP-UX and Solaris can allow a non-root user to chown() to root
# (issue #5113)
# (issue #5113)
...
@@ -266,11 +278,17 @@ class PosixTester(unittest.TestCase):
...
@@ -266,11 +278,17 @@ class PosixTester(unittest.TestCase):
else
:
else
:
# non-root cannot chown to root, raises OSError
# non-root cannot chown to root, raises OSError
self
.
assertRaises
(
OSError
,
chown_func
,
first_param
,
0
,
0
)
self
.
assertRaises
(
OSError
,
chown_func
,
first_param
,
0
,
0
)
check_stat
()
check_stat
(
uid
,
gid
)
self
.
assertRaises
(
OSError
,
chown_func
,
first_param
,
-
1
,
0
)
self
.
assertRaises
(
OSError
,
chown_func
,
first_param
,
-
1
,
0
)
check_stat
()
check_stat
(
uid
,
gid
)
self
.
assertRaises
(
OSError
,
chown_func
,
first_param
,
0
,
-
1
)
self
.
assertRaises
(
OSError
,
chown_func
,
first_param
,
0
,
-
1
)
check_stat
()
check_stat
(
uid
,
gid
)
# test illegal types
for
t
in
str
,
float
:
self
.
assertRaises
(
TypeError
,
chown_func
,
first_param
,
t
(
uid
),
gid
)
check_stat
(
uid
,
gid
)
self
.
assertRaises
(
TypeError
,
chown_func
,
first_param
,
uid
,
t
(
gid
))
check_stat
(
uid
,
gid
)
@unittest.skipUnless
(
hasattr
(
posix
,
'chown'
),
"test needs os.chown()"
)
@unittest.skipUnless
(
hasattr
(
posix
,
'chown'
),
"test needs os.chown()"
)
def
test_chown
(
self
):
def
test_chown
(
self
):
...
...
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