~tribaal/txaws/xss-hardening

50.1.4 by Duncan McGreggor
* Added S3 exception module and associated unit test module.
1
# Copyright (c) 2009 Canonical Ltd <duncan.mcgreggor@canonical.com>
2
# Licenced under the txaws licence available at /LICENSE in the txaws source.
3
4
from twisted.trial.unittest import TestCase
5
6
from txaws.s3.exception import S3Error
7
from txaws.testing import payload
8
from txaws.util import XML
9
10
11
REQUEST_ID = "0ef9fc37-6230-4d81-b2e6-1b36277d4247"
12
13
14
class S3ErrorTestCase(TestCase):
15
50.1.5 by Duncan McGreggor
* Moved the shared logic out of EC2Error and into AWSError.
16
    def test_set_400_error(self):
50.1.4 by Duncan McGreggor
* Added S3 exception module and associated unit test module.
17
        xml = "<Error><Code>1</Code><Message>2</Message></Error>"
63 by Thomas Hervé
Fix test suite against latest release of Twisted, which requires the code argument
18
        error = S3Error("<dummy />", 400)
50.1.5 by Duncan McGreggor
* Moved the shared logic out of EC2Error and into AWSError.
19
        error._set_400_error(XML(xml))
50.1.4 by Duncan McGreggor
* Added S3 exception module and associated unit test module.
20
        self.assertEquals(error.errors[0]["Code"], "1")
21
        self.assertEquals(error.errors[0]["Message"], "2")
22
23
    def test_get_error_code(self):
63 by Thomas Hervé
Fix test suite against latest release of Twisted, which requires the code argument
24
        error = S3Error(payload.sample_s3_invalid_access_key_result, 400)
50.1.4 by Duncan McGreggor
* Added S3 exception module and associated unit test module.
25
        self.assertEquals(error.get_error_code(), "InvalidAccessKeyId")
26
27
    def test_get_error_message(self):
63 by Thomas Hervé
Fix test suite against latest release of Twisted, which requires the code argument
28
        error = S3Error(payload.sample_s3_invalid_access_key_result, 400)
50.1.4 by Duncan McGreggor
* Added S3 exception module and associated unit test module.
29
        self.assertEquals(
30
            error.get_error_message(),
31
            ("The AWS Access Key Id you provided does not exist in our "
32
             "records."))
33
34
    def test_error_count(self):
63 by Thomas Hervé
Fix test suite against latest release of Twisted, which requires the code argument
35
        error = S3Error(payload.sample_s3_invalid_access_key_result, 400)
50.1.4 by Duncan McGreggor
* Added S3 exception module and associated unit test module.
36
        self.assertEquals(len(error.errors), 1)
37
38
    def test_error_repr(self):
63 by Thomas Hervé
Fix test suite against latest release of Twisted, which requires the code argument
39
        error = S3Error(payload.sample_s3_invalid_access_key_result, 400)
50.1.4 by Duncan McGreggor
* Added S3 exception module and associated unit test module.
40
        self.assertEquals(
41
            repr(error),
42
            "<S3Error object with Error code: InvalidAccessKeyId>")
43
44
    def test_signature_mismatch_result(self):
63 by Thomas Hervé
Fix test suite against latest release of Twisted, which requires the code argument
45
        error = S3Error(payload.sample_s3_signature_mismatch, 400)
50.1.4 by Duncan McGreggor
* Added S3 exception module and associated unit test module.
46
        self.assertEquals(
63 by Thomas Hervé
Fix test suite against latest release of Twisted, which requires the code argument
47
            error.get_error_messages(),
50.1.4 by Duncan McGreggor
* Added S3 exception module and associated unit test module.
48
            ("The request signature we calculated does not match the "
49
             "signature you provided. Check your key and signing method."))
50
51
    def test_invalid_access_key_result(self):
63 by Thomas Hervé
Fix test suite against latest release of Twisted, which requires the code argument
52
        error = S3Error(payload.sample_s3_invalid_access_key_result, 400)
50.1.4 by Duncan McGreggor
* Added S3 exception module and associated unit test module.
53
        self.assertEquals(
54
            error.get_error_messages(),
55
            ("The AWS Access Key Id you provided does not exist in our "
56
             "records."))
57
58
    def test_internal_error_result(self):
63 by Thomas Hervé
Fix test suite against latest release of Twisted, which requires the code argument
59
        error = S3Error(payload.sample_server_internal_error_result, 400)
50.1.4 by Duncan McGreggor
* Added S3 exception module and associated unit test module.
60
        self.assertEquals(
61
            error.get_error_messages(),
62
            "We encountered an internal error. Please try again.")