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)
def add_auth(self, request): if self.credentials is None: raise NoCredentialsError LOG.debug("Calculating signature using %s." % self.auth_method) LOG.debug('HTTP request method: %s', request.method) split = urlsplit(request.url) signature = self._get_signature(request.method, split, request.headers) self._inject_signature(request, signature)
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)
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'])
def _urljoin(endpoint_url, url_path): p = urlsplit(endpoint_url) # <part> - <index> # scheme - p[0] # netloc - p[1] # path - p[2] # query - p[3] # fragment - p[4] if not url_path or url_path == '/': # If there's no path component, ensure the URL ends with # a '/' for backwards compatibility. if not p[2]: return endpoint_url + '/' return endpoint_url if p[2].endswith('/') and url_path.startswith('/'): new_path = p[2][:-1] + url_path else: new_path = p[2] + url_path reconstructed = urlunsplit((p[0], p[1], new_path, p[3], p[4])) return reconstructed