allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [4/8] git commit: [#7524] ticket:613 Add some tests for user account audit
Date Fri, 25 Jul 2014 16:03:10 GMT
[#7524] ticket:613 Add some tests for user account audit


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/36fadf8c
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/36fadf8c
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/36fadf8c

Branch: refs/heads/master
Commit: 36fadf8ce30a32660cc70216ed4e3ca15dc19aa3
Parents: d2753a9
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Tue Jul 22 13:31:23 2014 +0300
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Fri Jul 25 16:02:57 2014 +0000

----------------------------------------------------------------------
 Allura/allura/tests/functional/test_auth.py     | 32 +++++++++++++++++---
 .../allura/tests/functional/test_site_admin.py  | 21 ++++++++++++-
 2 files changed, 48 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/36fadf8c/Allura/allura/tests/functional/test_auth.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_auth.py b/Allura/allura/tests/functional/test_auth.py
index c5c0330..9e03bed 100644
--- a/Allura/allura/tests/functional/test_auth.py
+++ b/Allura/allura/tests/functional/test_auth.py
@@ -112,8 +112,12 @@ class TestAuth(TestController):
             extra_environ=dict(username='test-admin'))
         r = self.app.get('/auth/preferences/')
         assert 'test@example.com' in r
-        assert_equal(M.User.query.get(username='test-admin').get_pref('email_address'),
-                     'test-admin@users.localhost')
+        user = M.User.query.get(username='test-admin')
+        assert_equal(user.get_pref('email_address'), 'test-admin@users.localhost')
+        log = M.AuditLog.for_user(user).all()
+        assert_equal(len(log), 1)
+        assert_equal(log[0].message, 'New email address: test@example.com')
+        M.AuditLog.query.remove()
 
         # remove test-admin@users.localhost
         r = self.app.post('/auth/preferences/update', params={
@@ -128,8 +132,21 @@ class TestAuth(TestController):
         r = self.app.get('/auth/preferences/')
         assert 'test-admin@users.localhost' not in r
         # preferred address has not changed if email is not verified
-        assert_equal(M.User.query.get(username='test-admin').get_pref('email_address'),
-                     None)
+        user = M.User.query.get(username='test-admin')
+        assert_equal(user.get_pref('email_address'), None)
+        log = M.AuditLog.for_user(user).all()
+        assert_equal(len(log), 1)
+        assert_equal(log[0].message, 'Email address deleted: test-admin@users.localhost')
+        M.AuditLog.query.remove()
+
+        r = self.app.post('/auth/preferences/update', params={
+            'preferences.display_name': 'Admin',
+            'new_addr.addr': ''},
+            extra_environ=dict(username='test-admin'))
+        user = M.User.query.get(username='test-admin')
+        log = M.AuditLog.for_user(user).all()
+        assert_equal(len(log), 1)
+        assert_equal(log[0].message, 'Display Name changed Test Admin => Admin')
 
     @td.with_user_project('test-admin')
     def test_prefs_subscriptions(self):
@@ -751,6 +768,13 @@ To reset your password on %s, please visit the following URL:
         hash_expiry = user.get_tool_data('AuthPasswordReset', 'hash_expiry')
         assert_equal(hash, '')
         assert_equal(hash_expiry, '')
+        log = M.AuditLog.for_user(user).all()
+        assert_equal(len(log), 2)
+        messages = set([l.message for l in log])
+        assert_equal(
+            messages,
+            set(['Password recovery link sent to: test-admin@users.localhost',
+                 'Password changed (through recovery process)']))
 
     @patch('allura.tasks.mail_tasks.sendsimplemail')
     @patch('allura.lib.helpers.gen_message_id')

http://git-wip-us.apache.org/repos/asf/allura/blob/36fadf8c/Allura/allura/tests/functional/test_site_admin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_site_admin.py b/Allura/allura/tests/functional/test_site_admin.py
index 79ca43b..8dbc2f6 100644
--- a/Allura/allura/tests/functional/test_site_admin.py
+++ b/Allura/allura/tests/functional/test_site_admin.py
@@ -17,8 +17,10 @@
 
 import json
 
-from nose.tools import assert_equal
+from mock import patch
+from nose.tools import assert_equal, assert_in, assert_not_in
 from ming.odm import ThreadLocalORMSession
+from pylons import tmpl_context as c
 
 from allura import model as M
 from allura.tests import TestController
@@ -160,6 +162,23 @@ class TestSiteAdmin(TestController):
             task_name='allura.tests.functional.test_site_admin.test_task'))
         assert json.loads(r.body)['doc'] == 'test_task doc string'
 
+    @patch('allura.model.auth.request')
+    def test_users(self, request):
+        request.url = 'http://host.domain/path/'
+        c.user = M.User.by_username('test-user-1')
+        M.AuditLog.log_user('test activity user 1')
+        M.AuditLog.log_user('test activity user 2', user=M.User.by_username('test-user-2'))
+        r = self.app.get('/nf/admin/users')
+        assert_not_in('test activity', r)
+        r = self.app.get('/nf/admin/users?username=admin1')
+        assert_not_in('test activity', r)
+        r = self.app.get('/nf/admin/users?username=test-user-1')
+        assert_in('test activity user 1', r)
+        assert_not_in('test activity user 2', r)
+        r = self.app.get('/nf/admin/users?username=test-user-2')
+        assert_not_in('test activity user 1', r)
+        assert_in('test activity user 2', r)
+
 
 @task
 def test_task(*args, **kw):


Mime
View raw message