Skip to content

Commit a75ee19

Browse files
committed
adjust logout to have double confirm for ucph but only one for mig openid
git-svn-id: svn+ssh://svn.code.sf.net/p/migrid/code/trunk@6243 b75ad72c-e7d7-11dd-a971-7dbc132099af
1 parent 7b75f6a commit a75ee19

File tree

2 files changed

+43
-16
lines changed

2 files changed

+43
-16
lines changed

mig/user/selenium/migcore.py

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -345,11 +345,12 @@ def get_nav_link(driver, url, nav_class):
345345
return link
346346

347347

348-
def shared_logout(driver, url, login, passwd, callbacks={}):
348+
def shared_logout(driver, url, double_confirm, login, passwd, callbacks={}):
349349
"""Logout through the shared logout navmenu entry and confirm. Optionally
350350
execute any provided callbacks for confirm states. The callbacks dictionary
351351
should contain state names bound to functions accepting driver and state
352352
name like do_stuff(driver, state) .
353+
The double_confirm arg specifies if one or two confirm steps are needed.
353354
"""
354355
status = True
355356
do_logout = False
@@ -380,21 +381,40 @@ def shared_logout(driver, url, login, passwd, callbacks={}):
380381
# print("DEBUG: click confirm elem: %s" % confirm_elem)
381382
confirm_elem.click()
382383
# Upstream OID(C) may have additional logout step
383-
print("Confirm logout again")
384-
try:
385-
confirm_elem = driver.find_element(by_what('xpath'),
386-
"//button[@value='Yes']")
387-
# print("DEBUG: found confirm elem: %s" % confirm_elem)
388-
state = 'logout-confirm-upstream'
389-
if callbacks.get(state, None):
390-
callbacks[state](driver, state)
391-
# print("DEBUG: click confirm elem: %s" % confirm_elem)
392-
confirm_elem.click()
393-
except Exception as exc:
394-
print("WARNING: failed in secondary logout: %s" % exc)
384+
if double_confirm:
385+
print("Confirm logout again")
386+
try:
387+
confirm_elem = driver.find_element(by_what('xpath'),
388+
"//button[@value='Yes']")
389+
# print("DEBUG: found confirm elem: %s" % confirm_elem)
390+
state = 'logout-confirm-upstream'
391+
if callbacks.get(state, None):
392+
callbacks[state](driver, state)
393+
# print("DEBUG: click confirm elem: %s" % confirm_elem)
394+
confirm_elem.click()
395+
except Exception as exc:
396+
print("WARNING: failed in secondary logout: %s" % exc)
395397
else:
396398
status = False
397399
print("Confirm login NOT found")
398400

399401
print("Finished logout: %s" % status)
400402
return status
403+
404+
405+
def mig_logout(driver, url, login, passwd, callbacks={}):
406+
"""Logout through the shared logout navmenu entry and confirm once. Optionally
407+
execute any provided callbacks for confirm states. The callbacks dictionary
408+
should contain state names bound to functions accepting driver and state
409+
name like do_stuff(driver, state) .
410+
"""
411+
return shared_logout(driver, url, False, login, passwd, callbacks)
412+
413+
414+
def ucph_logout(driver, url, login, passwd, callbacks={}):
415+
"""Logout through the shared logout navmenu entry and try to confirm twice.
416+
Optionally execute any provided callbacks for confirm states. The callbacks
417+
dictionary should contain state names bound to functions accepting driver
418+
and state name like do_stuff(driver, state) .
419+
"""
420+
return shared_logout(driver, url, True, login, passwd, callbacks)

mig/user/selenium/userguidescreens.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@
5656

5757
try:
5858
from mig.user.selenium.migcore import init_driver, ucph_login, mig_login, \
59-
shared_twofactor, shared_logout, save_screen, scroll_to_elem, \
60-
doubleclick_elem, select_item_by_index, get_nav_link, by_what
59+
shared_twofactor, ucph_logout, mig_logout, save_screen, \
60+
scroll_to_elem, doubleclick_elem, select_item_by_index, get_nav_link, \
61+
by_what
6162
except ImportError:
6263
print("Failed to import migrid modules - missing PYTHONPATH=$MIG_ROOT?")
6364
exit(1)
@@ -1033,7 +1034,13 @@ def main():
10331034
time.sleep(1)
10341035

10351036
print("Log out before exit")
1036-
status = shared_logout(driver, url, login, passwd, logout_calls)
1037+
if openid.lower() == 'ucph':
1038+
status = ucph_logout(driver, url, login, passwd, ucph_calls)
1039+
elif openid.lower() == 'mig':
1040+
status = mig_logout(driver, url, login, passwd, mig_calls)
1041+
else:
1042+
print("No such OpenID handler: %s" % openid)
1043+
status = False
10371044

10381045
print("Now you can proceed using the browser or interrupt with Ctrl-C")
10391046
while True:

0 commit comments

Comments
 (0)