Merge lp:~kwmonroe/charms/trusty/mediawiki/test-updates into lp:~tvansteenburgh/charms/trusty/mediawiki/fix-tests

Proposed by Kevin W Monroe
Status: Needs review
Proposed branch: lp:~kwmonroe/charms/trusty/mediawiki/test-updates
Merge into: lp:~tvansteenburgh/charms/trusty/mediawiki/fix-tests
Diff against target: 67 lines (+23/-9)
2 files modified
hooks/config-changed (+7/-3)
tests/100-deploy (+16/-6)
To merge this branch: bzr merge lp:~kwmonroe/charms/trusty/mediawiki/test-updates
Reviewer Review Type Date Requested Status
Charles Butler (community) Approve
Tim Van Steenburgh Pending
Review via email: mp+274793@code.launchpad.net

Description of the change

actually test the login capabilities at the end of 100-deploy

To post a comment you must log in.
86. By Kevin W Monroe

handle adding a new admin better (set -e causes us to fail fast if adding an existing user; trick it with "|| true" so we can properly inform the user of the problem).

87. By Kevin W Monroe

add our test admin after the db relation has been validated. the config-changed hook wont add an admin unless certain files are present (meaning we have a db connection). setting this config too early looks like it works, but the admin is never actually created.

Revision history for this message
Charles Butler (lazypower) wrote :

+1'd and rolled into tvansteenburgh's MP upstream

review: Approve

Unmerged revisions

87. By Kevin W Monroe

add our test admin after the db relation has been validated. the config-changed hook wont add an admin unless certain files are present (meaning we have a db connection). setting this config too early looks like it works, but the admin is never actually created.

86. By Kevin W Monroe

handle adding a new admin better (set -e causes us to fail fast if adding an existing user; trick it with "|| true" so we can properly inform the user of the problem).

85. By Kevin W Monroe

update test to exercise login

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hooks/config-changed'
2--- hooks/config-changed 2014-07-14 21:50:00 +0000
3+++ hooks/config-changed 2015-10-16 23:18:46 +0000
4@@ -82,9 +82,13 @@
5 for admin in $admins ; do
6 user=`echo $admin | cut -d: -f1`
7 pass=`echo $admin | cut -d: -f2`
8- output=`php createAndPromote.php --conf /etc/mediawiki/LocalSettings.php $user $pass`
9- if [ ! "$output" = "account exists." ] ; then
10- echo $output
11+ # createAndPromote.php will exit non-zero if the user already exists.
12+ # Since this hook is set -e, it would exit immediately unless we used
13+ # ' || true' at the end. This lets us properly inform the user of the
14+ # error, versus having a failed config-changed hook with no message.
15+ user_count=`php createAndPromote.php --conf /etc/mediawiki/LocalSettings.php $user $pass 2>&1 | grep -c "account exists" || true`
16+ if [ $user_count -gt 0 ] ; then
17+ echo "ERROR: $user account already exists"
18 exit 1
19 fi
20 done
21
22=== modified file 'tests/100-deploy'
23--- tests/100-deploy 2015-10-16 20:40:21 +0000
24+++ tests/100-deploy 2015-10-16 23:18:46 +0000
25@@ -1,6 +1,7 @@
26 #!/usr/bin/env python3
27 import amulet
28 import requests
29+import time
30
31 seconds = 900
32
33@@ -10,7 +11,7 @@
34 d.add('mysql')
35 d.add('memcached')
36 d.add('mediawiki')
37-d.configure('mediawiki', {'admins': 'tom:swordfish', 'name': 'amulet-wiki'})
38+d.configure('mediawiki', {'name': 'amulet-wiki'})
39 d.configure('memcached', {'allow-ufw-ip6-softfail': True})
40 d.relate('mysql:db', 'mediawiki:db')
41 d.relate('memcached:cache', 'mediawiki:cache')
42@@ -70,11 +71,20 @@
43 amulet.raise_status(amulet.FAIL,
44 "Unable to validate configuration for wiki-name")
45
46-login_url = "http://%s/mediawiki/index.php?title=" % mw_ip
47-payload = {'wpName': 'tom', 'wpPassword': 'swordfish'}
48+# Add an admin (now that we validated a good db connection)
49+d.configure('mediawiki', {'admins': 'tom:swordfish'})
50+# Give the config-changed hook 30s to settle
51+time.sleep(30)
52+login_url = "http://%s/mediawiki/api.php?action=login&lgname=tom&lgpassword=swordfish&format=json" % mw_ip
53
54+# Test that we can login with the newly created admin
55 with requests.Session() as s:
56+ # hit the login url with credentials, retrieve a token to use for later validation
57+ resp = s.post(login_url)
58+ token = resp.json()['login']['token']
59
60- resp = s.post(login_url, data=payload)
61- if resp.text.find("<title>amulet-wiki") == -1:
62- amulet.raise_status(amulet.FAIL, "Unable to validate admin login")
63+ # hit the login url again with creds+token to verify if we are successfully logged in
64+ resp2 = s.post(login_url+'&lgtoken=%s' % token, cookies=resp.cookies)
65+ result = resp2.json()['login']['result']
66+ if result != "Success":
67+ amulet.raise_status(amulet.FAIL, "Unable to validate admin login: %s" % result)

Subscribers

People subscribed via source and target branches