예제 #1
0
 def test_sign(self):
     key = "abc123"
     qs_list = ["x=1&y=2&z=3", "x=%20%2B%2F!%40%23%24%25%5E%26"]
     for qs in qs_list:
         o = urlparse.parse_qs(sign(key, qs))
         self.assertTrue("sig" in o)
         self.assertTrue(o["sig"])
예제 #2
0
 def test_valid(self):
     cases = self.get_image_resize_cases()
     for case in cases:
         if case.get("mode") == "crop" and case.get("position") == "face":
             continue
         params = case["source_query_params"]
         params["client"] = self.NAME
         qs = sign(self.KEY, urlencode(params))
         resp = self.fetch_success("/?%s" % qs)
         msg = "/?%s does not match %s" \
             % (qs, case["expected_path"])
         with open(case["expected_path"], "rb") as expected:
             self.assertEqual(resp.buffer.read(), expected.read(), msg)
예제 #3
0
 def test_valid(self):
     cases = self.get_image_resize_cases()
     for case in cases:
         if case.get("mode") == "crop" and case.get("position") == "face":
             continue
         params = case["source_query_params"]
         params["client"] = self.NAME
         qs = sign(self.KEY, urlencode(params))
         resp = self.fetch_success("/?%s" % qs)
         msg = "/?%s does not match %s" \
             % (qs, case["expected_path"])
         with open(case["expected_path"], "rb") as expected:
             self.assertEqual(resp.buffer.read(), expected.read(), msg)
예제 #4
0
 def test_bad_host(self):
     params = dict(url="http://bar.co/x.jpg", w=1, h=1, client=self.NAME)
     qs = sign(self.KEY, urlencode(params))
     resp = self.fetch_error(403, "/?%s" % qs)
     self.assertEqual(resp.get("error_code"), errors.HostError.get_code())
예제 #5
0
 def test_bad_client_name(self):
     params = dict(url="http://foo.co/x.jpg", w=1, h=1, client="123")
     qs = sign(self.KEY, urlencode(params))
     resp = self.fetch_error(403, "/?%s" % qs)
     self.assertEqual(resp.get("error_code"), errors.ClientError.get_code())
예제 #6
0
 def test_bad_host(self):
     params = dict(url="http://bar.co/x.jpg", w=1, h=1, client=self.NAME)
     qs = sign(self.KEY, urlencode(params))
     resp = self.fetch_error(403, "/?%s" % qs)
     self.assertEqual(resp.get("error_code"), errors.HostError.get_code())
예제 #7
0
 def test_bad_client_name(self):
     params = dict(url="http://foo.co/x.jpg", w=1, h=1, client="123")
     qs = sign(self.KEY, urlencode(params))
     resp = self.fetch_error(403, "/?%s" % qs)
     self.assertEqual(resp.get("error_code"), errors.ClientError.get_code())
예제 #8
0
 def test_bad_signature(self):
     key1 = "abc123"
     key2 = "def456"
     qs_list = ["x=1&y=2&z=3", "x=%20%2B%2F!%40%23%24%25%5E%26"]
     for qs in qs_list:
         self.assertFalse(verify_signature(key1, sign(key2, qs)))
예제 #9
0
 def test_verify(self):
     key = "abc123"
     qs_list = ["x=1&y=2&z=3", "x=%20%2B%2F!%40%23%24%25%5E%26"]
     for qs in qs_list:
         self.assertTrue(verify_signature(key, sign(key, qs)))