From 3b61d5721aec18abb33c1fcd4aa5a837869ff103 Mon Sep 17 00:00:00 2001 From: Don Mitchell Date: Tue, 24 Sep 2013 09:03:36 -0400 Subject: [PATCH] Ensure location is valid before trying to fetch Prevent accidental wildcarding. --- common/lib/xmodule/xmodule/contentstore/mongo.py | 2 ++ .../xmodule/xmodule/modulestore/tests/test_mongo.py | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/common/lib/xmodule/xmodule/contentstore/mongo.py b/common/lib/xmodule/xmodule/contentstore/mongo.py index 40c0b4bc9f..e146e46e32 100644 --- a/common/lib/xmodule/xmodule/contentstore/mongo.py +++ b/common/lib/xmodule/xmodule/contentstore/mongo.py @@ -177,6 +177,8 @@ class MongoContentStore(ContentStore): :param location: a c4x asset location """ + # raises exception if location is not fully specified + Location.ensure_fully_specified(location) for attr in attr_dict.iterkeys(): if attr in ['_id', 'md5', 'uploadDate', 'length']: raise AttributeError("{} is a protected attribute.".format(attr)) diff --git a/common/lib/xmodule/xmodule/modulestore/tests/test_mongo.py b/common/lib/xmodule/xmodule/modulestore/tests/test_mongo.py index e89aa21a16..c2e6be2793 100644 --- a/common/lib/xmodule/xmodule/modulestore/tests/test_mongo.py +++ b/common/lib/xmodule/xmodule/modulestore/tests/test_mongo.py @@ -22,6 +22,7 @@ from xmodule.contentstore.mongo import MongoContentStore from xmodule.modulestore.tests.test_modulestore import check_path_to_location from IPython.testing.nose_assert_methods import assert_in, assert_not_in from xmodule.exceptions import NotFoundError +from xmodule.modulestore.exceptions import InsufficientSpecificationError log = logging.getLogger(__name__) @@ -227,11 +228,11 @@ class TestMongoModuleStore(object): TestMongoModuleStore.content_store.set_attrs(content['_id'], {'miscel': 99}) assert_equals(TestMongoModuleStore.content_store.get_attr(content['_id'], 'miscel'), 99) assert_raises( - AttributeError, TestMongoModuleStore.content_store.set_attr, course_content[0], + AttributeError, TestMongoModuleStore.content_store.set_attr, course_content[0]['_id'], 'md5', 'ff1532598830e3feac91c2449eaa60d6' ) assert_raises( - AttributeError, TestMongoModuleStore.content_store.set_attrs, course_content[0], + AttributeError, TestMongoModuleStore.content_store.set_attrs, course_content[0]['_id'], {'foo': 9, 'md5': 'ff1532598830e3feac91c2449eaa60d6'} ) assert_raises( @@ -253,6 +254,11 @@ class TestMongoModuleStore(object): Location('bogus', 'bogus', 'bogus', 'asset', 'bogus'), {'displayname': 'hello'} ) + assert_raises( + InsufficientSpecificationError, TestMongoModuleStore.content_store.set_attrs, + Location('bogus', 'bogus', 'bogus', 'asset', None), + {'displayname': 'hello'} + ) class TestMongoKeyValueStore(object):