tests/OBSLocal: re-parse config and reset authentication when changing user.

Previously, the user was changed, but the authentication not reset. For
osc.core calls made within the text context they would still run as Admin
while separate processes (like scripts) would run as the desired user. As
such this was not an issue before since only scripts were meant to run as
a different user.
This commit is contained in:
Jimmy Berry 2018-01-03 16:22:13 -06:00
parent f1462def6e
commit df8cd0f677

View File

@ -28,10 +28,7 @@ class OBSLocalTestCase(unittest.TestCase):
# Avoid stale cookiejar since local OBS may be completely reset. # Avoid stale cookiejar since local OBS may be completely reset.
os.remove(OSCCOOKIEJAR) os.remove(OSCCOOKIEJAR)
self.oscrc('Admin') self.osc_user('Admin')
conf.get_config(override_conffile=OSCRC,
override_no_keyring=True,
override_no_gnome_keyring=True)
self.apiurl = conf.config['apiurl'] self.apiurl = conf.config['apiurl']
self.assertOBS() self.assertOBS()
@ -56,9 +53,24 @@ class OBSLocalTestCase(unittest.TestCase):
])) ]))
def osc_user(self, userid): def osc_user(self, userid):
conf.config['api_host_options'][self.apiurl]['user'] = userid
self.oscrc(userid) self.oscrc(userid)
# Rather than modify userid and email, just re-parse entire config and
# reset authentication by clearing opener to avoid edge-cases.
self.oscParse()
def oscParse(self):
# Otherwise, will stick to first user for a given apiurl.
conf._build_opener.last_opener = (None, None)
# Otherwise, will not re-parse same config file.
if 'cp' in conf.get_configParser.__dict__:
del conf.get_configParser.cp
conf.get_config(override_conffile=OSCRC,
override_no_keyring=True,
override_no_gnome_keyring=True)
def execute_script(self, args): def execute_script(self, args):
if self.script: if self.script:
args.insert(0, self.script) args.insert(0, self.script)