Ejemplo n.º 1
0
 def test_put(self):
     http_headers = HTTPHeaders.from_dict({})
     split = urlsplit('/foo/bar')
     cs = self.rsav1._canonical_string('PUT', split, http_headers)
     expected_canonical = "PUT\n\nThu, 17 Nov 2005 18:49:58 GMT\n/foo/bar\nrsav1"
     self.assertEqual(expected_canonical, cs)
     sig = self.rsav1._get_signature('PUT', split,
                                     HTTPHeaders.from_dict({}))
     self.assertEqual(EXPECTED_RSA_SIG, sig)
Ejemplo n.º 2
0
 def test_duplicate_auth_header(self):
     request = CdpRequest()
     request.headers = HTTPHeaders.from_dict({'x-altus-auth': 'signature'})
     request.method = 'PUT'
     request.url = 'https://altus.cloudera.com/service/op'
     with self.assertRaises(Exception):
         self.rsav1._inject_signature(request, 'new_signature')
Ejemplo n.º 3
0
 def test_duplicate_date(self):
     pairs = [('x-altus-date', 'Thu, 17 Nov 2015 18:49:58 GMT'),
              ('X-Altus-Magic', 'abracadabra')]
     http_headers = HTTPHeaders.from_pairs(pairs)
     split = urlsplit('/foo/bar')
     with self.assertRaises(Exception):
         self.rsav1.get_signature('PUT', split, http_headers)
Ejemplo n.º 4
0
    def test_auth_header_string(self):
        http_headers = HTTPHeaders.from_dict({})
        split = urlsplit('/foo/bar')
        sig = self.ed25519v1._get_signature('PUT', split, http_headers)
        self.assertEqual(EXPECTED_ED25519_SIG, sig)

        auth_header_string = self.ed25519v1._get_signature_header(sig)
        expected_metadata = 'eyJhY2Nlc3Nfa2V5X2lkIjogIkFCQ0QtRUZHSC1JSktMLU1OT1' \
                            'AtUVJTVCIsICJhdXRoX21ldGhvZCI6ICJlZDI1NTE5djEifQ=='
        metadata, sig = auth_header_string.split(".")
        self.assertEqual(expected_metadata, metadata)
        self.assertEqual(EXPECTED_ED25519_SIG, sig)

        json_metadata = json.loads(
            urlsafe_b64decode(metadata.encode('utf-8')).decode('utf-8'))
        self.assertEqual(self.credentials.access_key_id,
                         json_metadata['access_key_id'])
        self.assertEqual("ed25519v1", json_metadata['auth_method'])
Ejemplo n.º 5
0
 def __init__(self, *args, **kwargs):
     self.auth_path = None
     if 'auth_path' in kwargs:
         self.auth_path = kwargs['auth_path']
         del kwargs['auth_path']
     models.Request.__init__(self, *args, **kwargs)
     headers = HTTPHeaders()
     if self.headers is not None:
         for key, value in self.headers.items():
             headers[key] = value
     self.headers = headers
     # This is a dictionary to hold information that is used when
     # processing the request. What is inside of ``context`` is open-ended.
     # For example, it may have a timestamp key that is used for holding
     # what the timestamp is when signing the request. Note that none
     # of the information that is inside of ``context`` is directly
     # sent over the wire; the information is only used to assist in
     # creating what is sent over the wire.
     self.context = {}