incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [1/5] git commit: [#6692] Split bearer token tests and fixed no_api test
Date Tue, 22 Oct 2013 20:32:37 GMT
Updated Branches:
  refs/heads/cj/6692 f3f12795c -> 763a31a29


[#6692] Split bearer token tests and fixed no_api test

Signed-off-by: Cory Johns <cjohns@slashdotmedia.com>


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

Branch: refs/heads/cj/6692
Commit: 61bb842459759b93cb23e82749fe40413cf82193
Parents: f3f1279
Author: Cory Johns <cjohns@slashdotmedia.com>
Authored: Tue Oct 22 16:25:02 2013 +0000
Committer: Cory Johns <cjohns@slashdotmedia.com>
Committed: Tue Oct 22 16:25:02 2013 +0000

----------------------------------------------------------------------
 Allura/allura/controllers/base.py           |  2 +-
 Allura/allura/tests/functional/test_rest.py | 30 ++++++++++++++++++------
 2 files changed, 24 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/61bb8424/Allura/allura/controllers/base.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/base.py b/Allura/allura/controllers/base.py
index 1196126..d599e21 100644
--- a/Allura/allura/controllers/base.py
+++ b/Allura/allura/controllers/base.py
@@ -22,7 +22,7 @@ from tg.controllers.dispatcher import ObjectDispatcher
 
 class BaseController(object):
     @expose()
-    def _lookup(self, name, *remainder):
+    def _lookup(self, name=None, *remainder):
         """Provide explicit default lookup to avoid dispatching backtracking
         and possible loops."""
         raise exc.HTTPNotFound, name

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/61bb8424/Allura/allura/tests/functional/test_rest.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_rest.py b/Allura/allura/tests/functional/test_rest.py
index e814580..3a17af9 100644
--- a/Allura/allura/tests/functional/test_rest.py
+++ b/Allura/allura/tests/functional/test_rest.py
@@ -46,13 +46,17 @@ class TestRestHome(TestRestApiBase):
 
     @mock.patch('allura.controllers.rest.M.OAuthAccessToken')
     @mock.patch('allura.controllers.rest.request')
-    def test_bearer_token(self, request, OAuthAccessToken):
+    def test_bearer_token_non_ssl(self, request, OAuthAccessToken):
         request.params = {'access_token': 'foo'}
         request.scheme = 'http'
         r = self.api_post('/rest/p/test/wiki', access_token='foo')
         assert_equal(r.status_int, 403)
         assert_equal(OAuthAccessToken.query.get.call_count, 0)
 
+    @mock.patch('allura.controllers.rest.M.OAuthAccessToken')
+    @mock.patch('allura.controllers.rest.request')
+    def test_bearer_token_non_bearer(self, request, OAuthAccessToken):
+        request.params = {'access_token': 'foo'}
         request.scheme = 'https'
         access_token = OAuthAccessToken.query.get.return_value
         access_token.is_bearer = False
@@ -60,16 +64,28 @@ class TestRestHome(TestRestApiBase):
         assert_equal(r.status_int, 403)
         OAuthAccessToken.query.get.assert_called_once_with(api_key='foo')
 
-        OAuthAccessToken.query.get.reset_mock()
-        access_token.is_bearer = True
-        r = self.api_post('/rest/p/test/wiki', access_token='foo')
-        assert_equal(r.status_int, 404)
-        OAuthAccessToken.query.get.assert_called_once_with(api_key='foo')
-
+    @mock.patch('allura.controllers.rest.M.OAuthAccessToken')
+    @mock.patch('allura.controllers.rest.request')
+    def test_bearer_token_invalid(self, request, OAuthAccessToken):
+        request.params = {'access_token': 'foo'}
+        request.scheme = 'https'
         OAuthAccessToken.query.get.return_value = None
         r = self.api_post('/rest/p/test/wiki', access_token='foo')
         assert_equal(r.status_int, 403)
 
+    @mock.patch('allura.controllers.rest.M.OAuthAccessToken')
+    @mock.patch('allura.controllers.rest.request')
+    @td.with_wiki
+    def test_bearer_token_valid(self, request, OAuthAccessToken):
+        request.params = {'access_token': 'foo'}
+        request.scheme = 'https'
+        access_token = OAuthAccessToken.query.get.return_value
+        access_token.is_bearer = True
+        access_token.user = M.User.by_username('test-admin')
+        r = self.api_post('/rest/p/test/wiki', access_token='foo')
+        assert_equal(r.status_int, 200)
+        OAuthAccessToken.query.get.assert_called_once_with(api_key='foo')
+
     def test_bad_path(self):
         r = self.api_post('/rest/1/test/wiki/')
         assert r.status_int == 404


Mime
View raw message