~tribaal/txaws/xss-hardening

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# Copyright (c) 2009 Canonical Ltd <duncan.mcgreggor@canonical.com>
# Licenced under the txaws licence available at /LICENSE in the txaws source.

from twisted.trial.unittest import TestCase

from txaws.s3.exception import S3Error
from txaws.testing import payload
from txaws.util import XML


REQUEST_ID = "0ef9fc37-6230-4d81-b2e6-1b36277d4247"


class S3ErrorTestCase(TestCase):

    def test_set_400_error(self):
        xml = "<Error><Code>1</Code><Message>2</Message></Error>"
        error = S3Error("<dummy />")
        error._set_400_error(XML(xml))
        self.assertEquals(error.errors[0]["Code"], "1")
        self.assertEquals(error.errors[0]["Message"], "2")

    def test_get_error_code(self):
        error = S3Error(payload.sample_s3_invalid_access_key_result)
        self.assertEquals(error.get_error_code(), "InvalidAccessKeyId")

    def test_get_error_message(self):
        error = S3Error(payload.sample_s3_invalid_access_key_result)
        self.assertEquals(
            error.get_error_message(),
            ("The AWS Access Key Id you provided does not exist in our "
             "records."))

    def test_error_count(self):
        error = S3Error(payload.sample_s3_invalid_access_key_result)
        self.assertEquals(len(error.errors), 1)

    def test_error_repr(self):
        error = S3Error(payload.sample_s3_invalid_access_key_result)
        self.assertEquals(
            repr(error),
            "<S3Error object with Error code: InvalidAccessKeyId>")

    def test_signature_mismatch_result(self):
        error = S3Error(payload.sample_s3_signature_mismatch)
        self.assertEquals(
            error.get_error_messages(), 
            ("The request signature we calculated does not match the "
             "signature you provided. Check your key and signing method."))

    def test_invalid_access_key_result(self):
        error = S3Error(payload.sample_s3_invalid_access_key_result)
        self.assertEquals(
            error.get_error_messages(),
            ("The AWS Access Key Id you provided does not exist in our "
             "records."))

    def test_internal_error_result(self):
        error = S3Error(payload.sample_server_internal_error_result)
        self.assertEquals(
            error.get_error_messages(),
            "We encountered an internal error. Please try again.")