Test writing volunteers needed

A.M. Kuchling amk at mira.erols.com
Thu Jul 13 20:48:01 EDT 2000


On Wed, 12 Jul 2000 12:44:43 -0500 (CDT), 
	Skip Montanaro <skip at mojam.com> wrote:
>I'm look for a few people to write some regression tests for the posix (and
>windows or mac equivalents), os and sys modules.  Some of that functionality

To start the ball rolling, here's a little test case for the set{re,e}{u,g}id
functions that I added to the CVS version last night.

--amk

# Simple test case for os.setreuid(), os.setregid()
import os, pwd

uid = os.getuid()
if uid != 0:
    raise ImportError, "This test must be run as root; skipping"

nobody_uid, nobody_gid = pwd.getpwnam('nobody')[2:4]

# Set real uid and gid to root, effective uid and gid to nobody
os.setreuid( 0, nobody_uid ) ; os.setregid( 0, nobody_gid )

# Change effective ID to nobody
os.seteuid( nobody_uid )

# Expect these to fail
try: os.setuid( 1 )
except os.error: pass 
else: print 'Should have been unable to change UID to 1'

try: os.setgid( 1 )
except os.error: pass
else: print 'Should have been unable to change GID to 1'

# These should succeed, since we're just swapping the IDs
os.setreuid( nobody_uid, 0 )
os.setregid( nobody_gid, 0 )

# These should now succeed, since we're now back to root privilege
os.setgid( 1 ) ; os.setuid( 1 )




More information about the Python-list mailing list