Esempio n. 1
0
    def test_sign(self, time, policy):
        time.return_value = 10
        url = URL('http://redhat.com:1234/path;p1;p2?age=10')
        key = Mock()
        expiration = 10
        signature = 's1234['
        encoded_policy = 'p1234['
        _policy = Mock()
        _policy.sign.return_value = (encoded_policy, signature)
        policy.return_value = _policy
        extensions = dict(remote_ip='10.1.1.1')

        # test
        signed = url.sign(key, expiration, **extensions)

        # validation
        query = dict(Query.decode(url.query))
        query[URL.POLICY] = encoded_policy
        query[URL.SIGNATURE] = signature
        policy.assert_called_once_with(url.resource, expiration + time.return_value)
        self.assertEqual(signed.scheme, url.scheme)
        self.assertEqual(signed.netloc, url.netloc)
        self.assertEqual(signed.params, url.params)
        self.assertEqual(signed.path, url.path)
        self.assertEqual(signed.query, url.query)
        self.assertEqual(signed.bundle, (encoded_policy, signature))
Esempio n. 2
0
    def test_sign(self, time, policy):
        time.return_value = 10
        url = URL('http://redhat.com:1234/path;p1;p2?age=10')
        key = Mock()
        expiration = 10
        signature = 's1234['
        encoded_policy = 'p1234['
        _policy = Mock()
        _policy.sign.return_value = (encoded_policy, signature)
        policy.return_value = _policy
        extensions = dict(remote_ip='10.1.1.1')

        # test
        signed = url.sign(key, expiration, **extensions)

        # validation
        query = dict(Query.decode(url.query))
        query[URL.POLICY] = encoded_policy
        query[URL.SIGNATURE] = signature
        policy.assert_called_once_with(url.resource,
                                       expiration + time.return_value)
        self.assertEqual(signed.scheme, url.scheme)
        self.assertEqual(signed.netloc, url.netloc)
        self.assertEqual(signed.params, url.params)
        self.assertEqual(signed.path, url.path)
        self.assertEqual(signed.query, url.query)
        self.assertEqual(signed.bundle, (encoded_policy, signature))
Esempio n. 3
0
 def test_decode_with_padding(self):
     encoded = 'policy=SuchPad==;signature=MuchZero=='
     decoded = Query.decode(encoded)
     self.assertEqual(decoded, {
         'policy': 'SuchPad==',
         'signature': 'MuchZero=='
     })
Esempio n. 4
0
 def test_bundle(self):
     policy = 'p1234['
     signature = 's1234['
     bundle = Query.encode({URL.POLICY: policy, URL.SIGNATURE: signature})
     query = 'age=10'
     url = SignedURL('https://pulp.org/content?{b};{q}'.format(b=bundle,
                                                               q=query))
     self.assertEqual(url.bundle, (policy, signature))
Esempio n. 5
0
 def test_query(self):
     bundle = Query.encode(
         {
             URL.POLICY: 'p1234[',
             URL.SIGNATURE: 's1234['
         })
     query = 'age=10'
     url = SignedURL('https://pulp.org/content?{b};{q}'.format(b=bundle, q=query))
     self.assertEqual(url.query, query)
Esempio n. 6
0
 def test_bundle(self):
     policy = 'p1234['
     signature = 's1234['
     bundle = Query.encode(
         {
             URL.POLICY: policy,
             URL.SIGNATURE: signature
         })
     query = 'age=10'
     url = SignedURL('https://pulp.org/content?{b};{q}'.format(b=bundle, q=query))
     self.assertEqual(url.bundle, (policy, signature))
Esempio n. 7
0
 def test_encode(self):
     decoded = OrderedDict()
     decoded['name'] = 'john'
     decoded['age'] = '12'
     encoded = Query.encode(decoded)
     self.assertEqual(encoded, 'name=john;age=12')
Esempio n. 8
0
 def test_decode(self):
     encoded = ';name=john;age=12;'
     decoded = Query.decode(encoded)
     self.assertEqual(decoded, {'name': 'john', 'age': '12'})
Esempio n. 9
0
 def test_encode(self):
     decoded = OrderedDict()
     decoded['name'] = 'john'
     decoded['age'] = '12'
     encoded = Query.encode(decoded)
     self.assertEqual(encoded, 'name=john;age=12')
Esempio n. 10
0
 def test_decode(self):
     encoded = ';name=john;age=12;'
     decoded = Query.decode(encoded)
     self.assertEqual(decoded, {'name': 'john', 'age': '12'})