From 3b15fc7547c863db3bfcbc46f4e284c5b3fb8c67 Mon Sep 17 00:00:00 2001 From: Stephon Striplin Date: Tue, 26 Jul 2011 20:12:48 -0700 Subject: [PATCH] add Date header tests --- s3tests/functional/test_headers.py | 84 ++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/s3tests/functional/test_headers.py b/s3tests/functional/test_headers.py index 90c0268..659059b 100644 --- a/s3tests/functional/test_headers.py +++ b/s3tests/functional/test_headers.py @@ -320,3 +320,87 @@ def test_object_create_bad_ua_unreadable(): def test_object_create_bad_ua_none(): key = _setup_bad_object(remove=('User-Agent',)) key.set_contents_from_string('bar') + + +@nose.with_setup(teardown=_clear_custom_headers) +@attr('fails_on_dho') +def test_object_create_bad_date_invalid(): + key = _setup_bad_object({'Date': 'Bad Date'}) + + e = assert_raises(boto.exception.S3ResponseError, key.set_contents_from_string, 'bar') + eq(e.status, 403) + eq(e.reason, 'Forbidden') + eq(e.error_code, 'AccessDenied') + + +@nose.with_setup(teardown=_clear_custom_headers) +@attr('fails_on_dho') +def test_object_create_bad_date_empty(): + key = _setup_bad_object({'Date': ''}) + + e = assert_raises(boto.exception.S3ResponseError, key.set_contents_from_string, 'bar') + eq(e.status, 403) + eq(e.reason, 'Forbidden') + eq(e.error_code, 'AccessDenied') + + +@nose.with_setup(teardown=_clear_custom_headers) +@attr('fails_on_dho') +def test_object_create_bad_date_unreadable(): + key = _setup_bad_object({'Date': '\x07'}) + + e = assert_raises(boto.exception.S3ResponseError, key.set_contents_from_string, 'bar') + eq(e.status, 403) + eq(e.reason, 'Forbidden') + eq(e.error_code, 'AccessDenied') + + +@nose.with_setup(teardown=_clear_custom_headers) +@attr('fails_on_dho') +def test_object_create_bad_date_none(): + key = _setup_bad_object(remove=('Date',)) + + e = assert_raises(boto.exception.S3ResponseError, key.set_contents_from_string, 'bar') + eq(e.status, 403) + eq(e.reason, 'Forbidden') + eq(e.error_code, 'AccessDenied') + + +@nose.with_setup(teardown=_clear_custom_headers) +def test_object_create_bad_date_before_today(): + key = _setup_bad_object({'Date': 'Tue, 07 Jul 2010 21:53:04 GMT'}) + + e = assert_raises(boto.exception.S3ResponseError, key.set_contents_from_string, 'bar') + eq(e.status, 403) + eq(e.reason, 'Forbidden') + eq(e.error_code, 'RequestTimeTooSkewed') + + +@nose.with_setup(teardown=_clear_custom_headers) +def test_object_create_bad_date_after_today(): + key = _setup_bad_object({'Date': 'Tue, 07 Jul 2030 21:53:04 GMT'}) + + e = assert_raises(boto.exception.S3ResponseError, key.set_contents_from_string, 'bar') + eq(e.status, 403) + eq(e.reason, 'Forbidden') + eq(e.error_code, 'RequestTimeTooSkewed') + + +@nose.with_setup(teardown=_clear_custom_headers) +def test_object_create_bad_date_before_epoch(): + key = _setup_bad_object({'Date': 'Tue, 07 Jul 1950 21:53:04 GMT'}) + + e = assert_raises(boto.exception.S3ResponseError, key.set_contents_from_string, 'bar') + eq(e.status, 403) + eq(e.reason, 'Forbidden') + eq(e.error_code, 'AccessDenied') + + +@nose.with_setup(teardown=_clear_custom_headers) +def test_object_create_bad_date_after_end(): + key = _setup_bad_object({'Date': 'Tue, 07 Jul 9999 21:53:04 GMT'}) + + e = assert_raises(boto.exception.S3ResponseError, key.set_contents_from_string, 'bar') + eq(e.status, 403) + eq(e.reason, 'Forbidden') + eq(e.error_code, 'RequestTimeTooSkewed')