Skip to content

Commit

Permalink
Ensure a desired URL is returned
Browse files Browse the repository at this point in the history
  • Loading branch information
rayluo committed Dec 8, 2015
1 parent b6ed654 commit fbcab9c
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions tests/functional/cloudfront/test_sign.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
import mock
from botocore.compat import urlparse, parse_qs

from awscli.testutils import FileCreator
from awscli.testutils import BaseAWSPreviewCommandParamsTest as \
BaseAWSCommandParamsTest
Expand Down Expand Up @@ -54,14 +57,28 @@ def setUp(self):
self.addCleanup(files.remove_all)
super(TestSign, self).setUp()

def assertDesiredUrl(self, url, base, params):
self.assertEqual(len(url.splitlines()), 1, "Expects only 1 line")
self.assertTrue(url.startswith(base), "URL mismatch")
url = url.strip() # Otherwise the last param contains a trailing CRLF
self.assertEqual(parse_qs(urlparse(url).query), params)

def test_canned_policy(self):
cmdline = (
self.prefix + '--private-key file://' + self.private_key_file +
' --date-less-than 2016-1-1')
self.assertIn('Expires', self.run_cmd(cmdline)[0])
expected_params = {
'Key-Pair-Id': ['my_id'],
'Expires': ['1451606400'], 'Signature': [mock.ANY]}
self.assertDesiredUrl(
self.run_cmd(cmdline)[0], 'http://example.com/hi', expected_params)

def test_custom_policy(self):
cmdline = (
self.prefix + '--private-key file://' + self.private_key_file +
' --date-less-than 2016-1-1 --ip-address 12.34.56.78')
self.assertIn('Policy', self.run_cmd(cmdline)[0])
expected_params = {
'Key-Pair-Id': ['my_id'],
'Policy': [mock.ANY], 'Signature': [mock.ANY]}
self.assertDesiredUrl(
self.run_cmd(cmdline)[0], 'http://example.com/hi', expected_params)

0 comments on commit fbcab9c

Please sign in to comment.