~tribaal/txaws/xss-hardening

« back to all changes in this revision

Viewing changes to txaws/ec2/tests/test_client.py

  • Committer: Thomas Hervé
  • Date: 2009-10-21 19:40:18 UTC
  • Revision ID: thomas@canonical.com-20091021194018-nbcgy745732s00xs
Default to HmacSHA256 instead of HmacSHA1: it's more secure and provides
compatibility with Eucalyptus [r=oubiwann]

Show diffs side-by-side

added added

removed removed

Lines of Context:
564
564
        self.assertRaises(ValueError, ec2.authorize_security_group,
565
565
                "WebServers", ip_protocol="tcp", from_port="22")
566
566
        try:
567
 
            d = ec2.authorize_security_group(
 
567
            ec2.authorize_security_group(
568
568
                "WebServers", ip_protocol="tcp", from_port="22")
569
569
        except Exception, error:
570
570
            self.assertEquals(
694
694
        self.assertRaises(ValueError, ec2.authorize_security_group,
695
695
                "WebServers", ip_protocol="tcp", from_port="22")
696
696
        try:
697
 
            d = ec2.authorize_security_group(
 
697
            ec2.authorize_security_group(
698
698
                "WebServers", ip_protocol="tcp", from_port="22")
699
699
        except Exception, error:
700
700
            self.assertEquals(
1252
1252
        self.assertEqual(
1253
1253
            {"AWSAccessKeyId": "foo",
1254
1254
             "Action": "DescribeInstances",
1255
 
             "SignatureMethod": "HmacSHA1",
 
1255
             "SignatureMethod": "HmacSHA256",
1256
1256
             "SignatureVersion": "2",
1257
1257
             "Version": "2008-12-01"},
1258
1258
            query.params)
1271
1271
            {"AWSAccessKeyId": "foo",
1272
1272
             "Action": "DescribeInstances",
1273
1273
             "InstanceId.0": "12345",
1274
 
             "SignatureMethod": "HmacSHA1",
 
1274
             "SignatureMethod": "HmacSHA256",
1275
1275
             "SignatureVersion": "2",
1276
1276
             "Timestamp": "2007-11-12T13:14:15Z",
1277
1277
             "Version": "2008-12-01"},
1284
1284
        self.assertEqual([
1285
1285
            ("AWSAccessKeyId", "foo"),
1286
1286
            ("Action", "DescribeInstances"),
1287
 
            ("SignatureMethod", "HmacSHA1"),
 
1287
            ("SignatureMethod", "HmacSHA256"),
1288
1288
            ("SignatureVersion", "2"),
1289
1289
            ("Timestamp", "2007-11-12T13:14:15Z"),
1290
1290
            ("Version", "2008-12-01"),
1309
1309
            time_tuple=(2007,11,12,13,14,15,0,0,0))
1310
1310
        expected_query = ("AWSAccessKeyId=foo&Action=DescribeInstances"
1311
1311
            "&InstanceId.1=i-1234"
1312
 
            "&SignatureMethod=HmacSHA1&SignatureVersion=2&"
 
1312
            "&SignatureMethod=HmacSHA256&SignatureVersion=2&"
1313
1313
            "Timestamp=2007-11-12T13%3A14%3A15Z&Version=2008-12-01&"
1314
1314
            "argwithnovalue=&fu%20n=g%2Fames")
1315
1315
        self.assertEqual(expected_query, query.canonical_query_params())
1319
1319
            time_tuple=(2007,11,12,13,14,15,0,0,0))
1320
1320
        signing_text = ("GET\n%s\n/\n" % self.endpoint.host +
1321
1321
            "AWSAccessKeyId=foo&Action=DescribeInstances&"
1322
 
            "SignatureMethod=HmacSHA1&SignatureVersion=2&"
 
1322
            "SignatureMethod=HmacSHA256&SignatureVersion=2&"
1323
1323
            "Timestamp=2007-11-12T13%3A14%3A15Z&Version=2008-12-01")
1324
1324
        self.assertEqual(signing_text, query.signing_text())
1325
1325
 
1326
1326
    def test_sign(self):
1327
1327
        query = client.Query("DescribeInstances", self.creds, self.endpoint,
1328
 
            time_tuple=(2007,11,12,13,14,15,0,0,0))
 
1328
            time_tuple=(2007, 11, 12, 13, 14, 15, 0, 0, 0))
1329
1329
        query.sign()
1330
 
        self.assertEqual("JuCpwFA2H4OVF3Ql/lAQs+V6iMc=",
 
1330
        self.assertEqual("aDmLr0Ktjsmt17UJD/EZf6DrfKWT1JW0fq2FDUCOPic=",
1331
1331
            query.params["Signature"])
1332
1332
 
1333
1333
    def test_submit_400(self):