Skip to content

Commit

Permalink
Merge pull request boto#1271 from seandst/develop
Browse files Browse the repository at this point in the history
Added more unittests for Distribution._sign_string
  • Loading branch information
garnaat committed Jan 31, 2013
2 parents b54a0e7 + 417de05 commit c1a8026
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion tests/unit/cloudfront/test_signed_urls.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@

import tempfile
import unittest
try:
import simplejson as json
except ImportError:
import json
from textwrap import dedent

from boto.cloudfront.distribution import Distribution

class CloudfrontSignedUrlsTest(unittest.TestCase):
Expand Down Expand Up @@ -99,6 +100,38 @@ def test_sign_canned_policy(self):
encoded_sig = self.dist._url_base64_encode(sig)
self.assertEqual(expected, encoded_sig)

def test_sign_canned_policy_pk_file(self):
"""
Test signing the canned policy from amazon's cloudfront documentation
with a file object.
"""
expected = ("Nql641NHEUkUaXQHZINK1FZ~SYeUSoBJMxjdgqrzIdzV2gyEXPDN"
"v0pYdWJkflDKJ3xIu7lbwRpSkG98NBlgPi4ZJpRRnVX4kXAJK6td"
"Nx6FucDB7OVqzcxkxHsGFd8VCG1BkC-Afh9~lOCMIYHIaiOB6~5j"
"t9w2EOwi6sIIqrg_")
pk_file = tempfile.TemporaryFile()
pk_file.write(self.pk_str)
pk_file.seek(0)
sig = self.dist._sign_string(self.canned_policy, private_key_file=pk_file)
encoded_sig = self.dist._url_base64_encode(sig)
self.assertEqual(expected, encoded_sig)

def test_sign_canned_policy_pk_file_name(self):
"""
Test signing the canned policy from amazon's cloudfront documentation
with a file name.
"""
expected = ("Nql641NHEUkUaXQHZINK1FZ~SYeUSoBJMxjdgqrzIdzV2gyEXPDN"
"v0pYdWJkflDKJ3xIu7lbwRpSkG98NBlgPi4ZJpRRnVX4kXAJK6td"
"Nx6FucDB7OVqzcxkxHsGFd8VCG1BkC-Afh9~lOCMIYHIaiOB6~5j"
"t9w2EOwi6sIIqrg_")
pk_file = tempfile.NamedTemporaryFile()
pk_file.write(self.pk_str)
pk_file.flush()
sig = self.dist._sign_string(self.canned_policy, private_key_file=pk_file.name)
encoded_sig = self.dist._url_base64_encode(sig)
self.assertEqual(expected, encoded_sig)

def test_sign_canned_policy_unicode(self):
"""
Test signing the canned policy from amazon's cloudfront documentation.
Expand Down

0 comments on commit c1a8026

Please sign in to comment.