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_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'])