allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [2/2] git commit: [#7307] safer 'doc too large' checking, to account for ming's arg injection
Date Fri, 04 Apr 2014 22:01:39 GMT
[#7307] safer 'doc too large' checking, to account for ming's arg injection


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

Branch: refs/heads/master
Commit: 2c88f7d749c607537f63942e1955c5fa85958dcb
Parents: b227c3f
Author: Dave Brondsema <dbrondsema@slashdotmedia.com>
Authored: Thu Apr 3 15:21:13 2014 +0000
Committer: Cory Johns <cjohns@slashdotmedia.com>
Committed: Fri Apr 4 22:01:22 2014 +0000

----------------------------------------------------------------------
 Allura/allura/command/show_models.py     | 2 +-
 Allura/allura/model/session.py           | 2 +-
 Allura/allura/tests/test_commands.py     | 5 ++++-
 Allura/allura/tests/unit/test_session.py | 5 ++++-
 4 files changed, 10 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/2c88f7d7/Allura/allura/command/show_models.py
----------------------------------------------------------------------
diff --git a/Allura/allura/command/show_models.py b/Allura/allura/command/show_models.py
index 76d95ac..36aa29e 100644
--- a/Allura/allura/command/show_models.py
+++ b/Allura/allura/command/show_models.py
@@ -177,7 +177,7 @@ class ReindexCommand(base.Command):
         except InvalidDocument as e:
             # there are many types of InvalidDocument, only recurse if its
             # expected to help
-            if str(e).startswith('BSON document too large'):
+            if e.args[0].startswith('BSON document too large'):
                 self._post_add_artifacts(chunk[:len(chunk) // 2])
                 self._post_add_artifacts(chunk[len(chunk) // 2:])
             else:

http://git-wip-us.apache.org/repos/asf/allura/blob/2c88f7d7/Allura/allura/model/session.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/session.py b/Allura/allura/model/session.py
index 50bbb8a..ca5db5a 100644
--- a/Allura/allura/model/session.py
+++ b/Allura/allura/model/session.py
@@ -162,7 +162,7 @@ class BatchIndexer(ArtifactSessionExtension):
         except pymongo.errors.InvalidDocument as e:
             # there are many types of InvalidDocument, only recurse if its
             # expected to help
-            if str(e).startswith('BSON document too large'):
+            if e.args[0].startswith('BSON document too large'):
                 cls._post(task_func, chunk[:len(chunk) // 2])
                 cls._post(task_func, chunk[len(chunk) // 2:])
             else:

http://git-wip-us.apache.org/repos/asf/allura/blob/2c88f7d7/Allura/allura/tests/test_commands.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_commands.py b/Allura/allura/tests/test_commands.py
index 1ecfb39..73b419a 100644
--- a/Allura/allura/tests/test_commands.py
+++ b/Allura/allura/tests/test_commands.py
@@ -442,8 +442,11 @@ class TestReindexCommand(object):
     def test_post_add_artifacts_too_large(self, add_artifacts):
         def on_post(chunk, **kw):
             if len(chunk) > 1:
-                raise pymongo.errors.InvalidDocument(
+                e = pymongo.errors.InvalidDocument(
                     "BSON document too large (16906035 bytes) - the connected server supports
BSON document sizes up to 16777216 bytes.")
+                # ming injects a 2nd arg with the document, so we do too
+                e.args = e.args + ("doc:  {'task_name': 'allura.tasks.index_tasks.add_artifacts',
........",)
+                raise e
         add_artifacts.post.side_effect = on_post
         cmd = show_models.ReindexCommand('reindex')
         cmd.options, args = cmd.parser.parse_args([])

http://git-wip-us.apache.org/repos/asf/allura/blob/2c88f7d7/Allura/allura/tests/unit/test_session.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/unit/test_session.py b/Allura/allura/tests/unit/test_session.py
index f9bd277..eec41bd 100644
--- a/Allura/allura/tests/unit/test_session.py
+++ b/Allura/allura/tests/unit/test_session.py
@@ -142,8 +142,11 @@ class TestBatchIndexer(TestCase):
     def test__post_too_large(self, index_tasks):
         def on_post(chunk):
             if len(chunk) > 1:
-                raise pymongo.errors.InvalidDocument(
+                e = pymongo.errors.InvalidDocument(
                     "BSON document too large (16906035 bytes) - the connected server supports
BSON document sizes up to 16777216 bytes.")
+                # ming injects a 2nd arg with the document, so we do too
+                e.args = e.args + ("doc:  {'task_name': 'allura.tasks.index_tasks.add_artifacts',
........",)
+                raise e
         index_tasks.add_artifacts.post.side_effect = on_post
         self.ext._post(index_tasks.add_artifacts, range(5))
         expected = [


Mime
View raw message