~tribaal/txaws/xss-hardening

« back to all changes in this revision

Viewing changes to txaws/tests/test_util.py

  • Committer: Duncan McGreggor
  • Date: 2009-09-05 00:26:12 UTC
  • mto: This revision was merged to the branch mainline in revision 17.
  • Revision ID: duncan@canonical.com-20090905002612-cuk3ndv1tkpadgag
Replaced all occurances of ' in all the modules with " (excepting proper usage
of apostrophes).

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
 
9
9
    def test_hmac_sha1(self):
10
10
        cases = [
11
 
            ('0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b'.decode('hex'),
12
 
             'Hi There', 'thcxhlUFcmTii8C2+zeMjvFGvgA='),
13
 
            ('Jefe', 'what do ya want for nothing?',
14
 
             '7/zfauXrL6LSdBbV8YTfnCWafHk='),
15
 
            ('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'.decode('hex'),
16
 
             '\xdd' * 50, 'El1zQrmsEc2Ro5r0iqF7T2PxddM='),
 
11
            ("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b".decode("hex"),
 
12
             "Hi There", "thcxhlUFcmTii8C2+zeMjvFGvgA="),
 
13
            ("Jefe", "what do ya want for nothing?",
 
14
             "7/zfauXrL6LSdBbV8YTfnCWafHk="),
 
15
            ("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa".decode("hex"),
 
16
             "\xdd" * 50, "El1zQrmsEc2Ro5r0iqF7T2PxddM="),
17
17
            ]
18
18
 
19
19
        for key, data, expected in cases:
34
34
        """
35
35
        # The default port for HTTP is 80.
36
36
        self.assertEqual(
37
 
            parse('http://127.0.0.1/'),
38
 
            ('http', '127.0.0.1', 80, '/'))
 
37
            parse("http://127.0.0.1/"),
 
38
            ("http", "127.0.0.1", 80, "/"))
39
39
 
40
40
        # The default port for HTTPS is 443.
41
41
        self.assertEqual(
42
 
            parse('https://127.0.0.1/'),
43
 
            ('https', '127.0.0.1', 443, '/'))
 
42
            parse("https://127.0.0.1/"),
 
43
            ("https", "127.0.0.1", 443, "/"))
44
44
 
45
45
        # Specifying a port.
46
46
        self.assertEqual(
47
 
            parse('http://spam:12345/'),
48
 
            ('http', 'spam', 12345, '/'))
 
47
            parse("http://spam:12345/"),
 
48
            ("http", "spam", 12345, "/"))
49
49
 
50
50
        # Weird (but commonly accepted) structure uses default port.
51
51
        self.assertEqual(
52
 
            parse('http://spam:/'),
53
 
            ('http', 'spam', 80, '/'))
 
52
            parse("http://spam:/"),
 
53
            ("http", "spam", 80, "/"))
54
54
 
55
55
        # Spaces in the hostname are trimmed, the default path is /.
56
56
        self.assertEqual(
57
 
            parse('http://foo '),
58
 
            ('http', 'foo', 80, '/'))
 
57
            parse("http://foo "),
 
58
            ("http", "foo", 80, "/"))
59
59
 
60
60
    def test_externalUnicodeInterference(self):
61
61
        """
63
63
        elements of its return tuple, even when passed an URL which has
64
64
        previously been passed to L{urlparse} as a C{unicode} string.
65
65
        """
66
 
        badInput = u'http://example.com/path'
67
 
        goodInput = badInput.encode('ascii')
 
66
        badInput = u"http://example.com/path"
 
67
        goodInput = badInput.encode("ascii")
68
68
        urlparse(badInput)
69
69
        scheme, host, port, path = parse(goodInput)
70
70
        self.assertTrue(isinstance(scheme, str))