@@ -33,7 +33,6 @@ class TestUser(osgunittest.OSGTestCase):
33
33
34
34
def test_01_add_user (self ):
35
35
core .state ['general.user_added' ] = False
36
- core .state ['general.user_cert_created' ] = False
37
36
38
37
# Bail out if this step is not needed
39
38
if not core .options .adduser :
@@ -61,36 +60,55 @@ def test_01_add_user(self):
61
60
core .state ['general.user_added' ] = True
62
61
63
62
# 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 )
67
66
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
75
69
76
- def test_02_user (self ):
77
- core .state ['system.wrote_mapfile' ] = False
78
70
if core .options .skiptests :
79
71
core .skip ('no user needed' )
80
72
return
73
+
81
74
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' ])
90
108
91
109
# Add user to mapfile
92
110
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 ),
94
112
owner = 'user' )
95
113
core .state ['system.wrote_mapfile' ] = True
96
114
os .chmod (core .config ['system.mapfile' ], 0o644 )
0 commit comments