You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by je...@apache.org on 2014/07/22 14:33:03 UTC

[4/4] git commit: [#7524] ticket:613 Add some tests for user account audit

[#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/c03d10d1
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/c03d10d1
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/c03d10d1

Branch: refs/heads/je/42cc_7524
Commit: c03d10d1f119adac9362d1ffe66cca8c7c0eb678
Parents: 368675a
Author: Igor Bondarenko <je...@gmail.com>
Authored: Tue Jul 22 13:31:23 2014 +0300
Committer: Igor Bondarenko <je...@gmail.com>
Committed: Tue Jul 22 13:31:23 2014 +0300

----------------------------------------------------------------------
 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/c03d10d1/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 1c41e8a..c79b52e 100644
--- a/Allura/allura/tests/functional/test_auth.py
+++ b/Allura/allura/tests/functional/test_auth.py
@@ -98,8 +98,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={
@@ -114,8 +118,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):
@@ -737,6 +754,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.sendmail')
     @patch('allura.lib.helpers.gen_message_id')

http://git-wip-us.apache.org/repos/asf/allura/blob/c03d10d1/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):