Skip to content

Commit a48a1df

Browse files
committed
Separate out user cert generation and addition to the grid-mapfile
Also move verification to before the user cert generation
1 parent 1b8033a commit a48a1df

File tree

1 file changed

+40
-22
lines changed

1 file changed

+40
-22
lines changed

osgtest/tests/special_user.py

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ class TestUser(osgunittest.OSGTestCase):
3333

3434
def test_01_add_user(self):
3535
core.state['general.user_added'] = False
36-
core.state['general.user_cert_created'] = False
3736

3837
# Bail out if this step is not needed
3938
if not core.options.adduser:
@@ -61,36 +60,55 @@ def test_01_add_user(self):
6160
core.state['general.user_added'] = True
6261

6362
# Set up directories
64-
user = pwd.getpwnam(core.options.username)
65-
os.chown(user.pw_dir, user.pw_uid, user.pw_gid)
66-
os.chmod(user.pw_dir, 0o755)
63+
core.state['user.pwd'] = pwd.getpwnam(core.options.username)
64+
os.chown(core.state['user.pwd'].pw_dir, core.state['user.pwd'].pw_uid, core.state['user.pwd'].pw_gid)
65+
os.chmod(core.state['user.pwd'].pw_dir, 0o755)
6766

68-
# Set up certificate
69-
globus_dir = os.path.join(user.pw_dir, '.globus')
70-
user_cert = os.path.join(globus_dir, 'usercert.pem')
71-
test_ca = CA.load(core.config['certs.test-ca'])
72-
if not os.path.exists(user_cert):
73-
test_ca.usercert(core.options.username, core.options.password)
74-
core.state['general.user_cert_created'] = True
67+
def test_02_verify_user(self):
68+
core.state['user.verified'] = False
7569

76-
def test_02_user(self):
77-
core.state['system.wrote_mapfile'] = False
7870
if core.options.skiptests:
7971
core.skip('no user needed')
8072
return
73+
8174
try:
82-
password_entry = pwd.getpwnam(core.options.username)
83-
except KeyError as e:
84-
self.fail("User '%s' should exist but does not" % core.options.username)
85-
self.assert_(password_entry.pw_dir != '/', "User '%s' has home directory at '/'" % (core.options.username))
86-
self.assert_(os.path.isdir(password_entry.pw_dir),
87-
"User '%s' missing a home directory at '%s'" % (core.options.username, password_entry.pw_dir))
88-
cert_path = os.path.join(password_entry.pw_dir, '.globus', 'usercert.pem')
89-
core.config['user.cert_subject'], core.config['user.cert_issuer'] = certificate_info(cert_path)
75+
user = core.state['user.pwd']
76+
except KeyError:
77+
try:
78+
core.state['user.pwd'] = user = pwd.getpwnam(core.options.username)
79+
except KeyError:
80+
self.fail("User '%s' should exist but does not" % core.options.username)
81+
82+
self.assert_(user.pw_dir != '/', "User '%s' has home directory at '/'" % (core.options.username))
83+
self.assert_(os.path.isdir(user.pw_dir),
84+
"User '%s' missing a home directory at '%s'" % (core.options.username, user.pw_dir))
85+
86+
core.state['user.verified'] = True
87+
88+
def test_03_generate_user_cert(self):
89+
core.state['general.user_cert_created'] = False
90+
core.state['system.wrote_mapfile'] = False
91+
92+
if core.options.skiptests:
93+
core.skip('no user needed')
94+
return
95+
96+
self.skip_bad_unless(core.state['user.verified'], "User doesn't exist, has HOME=/, or is missing HOME")
97+
98+
# Set up certificate
99+
globus_dir = os.path.join(core.state['user.pwd'].pw_dir, '.globus')
100+
core.state['user.cert_path'] = os.path.join(globus_dir, 'usercert.pem')
101+
test_ca = CA.load(core.config['certs.test-ca'])
102+
if not os.path.exists(core.state['user.cert_path']):
103+
test_ca.usercert(core.options.username, core.options.password)
104+
core.state['general.user_cert_created'] = True
105+
106+
(core.config['user.cert_subject'],
107+
core.config['user.cert_issuer']) = certificate_info(core.state['user.cert_path'])
90108

91109
# Add user to mapfile
92110
files.append(core.config['system.mapfile'], '"%s" %s\n' %
93-
(core.config['user.cert_subject'], password_entry.pw_name),
111+
(core.config['user.cert_subject'], core.state['user.pwd'].pw_name),
94112
owner='user')
95113
core.state['system.wrote_mapfile'] = True
96114
os.chmod(core.config['system.mapfile'], 0o644)

0 commit comments

Comments
 (0)