Abstract away service name (#268)
* Abstract away service name Signed-off-by: Harsha Vamsi Kalluri <[email protected]> * Compuute x-amz-content-256 header Signed-off-by: Harsha Vamsi Kalluri <[email protected]> * Fix async signing Signed-off-by: Harsha Vamsi Kalluri <[email protected]> * Adds types-six to dependencies Signed-off-by: Harsha Vamsi Kalluri <[email protected]> * Optionally remove Content-Length Signed-off-by: Harsha Vamsi Kalluri <[email protected]> * Fix dict typo Signed-off-by: Harsha Vamsi Kalluri <[email protected]> * Remove requirement for x-amz-content-sha256 header Signed-off-by: Harsha Vamsi Kalluri <[email protected]> * Remove deletion of content-length Signed-off-by: Harsha Vamsi Kalluri <[email protected]> * Fix capitalization Signed-off-by: Harsha Vamsi Kalluri <[email protected]> * Adding unit tests Signed-off-by: Harsha Vamsi Kalluri <[email protected]> Signed-off-by: Harsha Vamsi Kalluri <[email protected]>
This commit is contained in:
@@ -63,3 +63,18 @@ class TestAsyncSigner(TestCase):
|
||||
|
||||
with pytest.raises(ValueError) as e:
|
||||
assert str(e.value) == "Credentials cannot be empty"
|
||||
|
||||
@pytest.mark.skipif(
|
||||
sys.version_info < (3, 6), reason="AWSV4SignerAsyncAuth requires python3.6+"
|
||||
)
|
||||
async def test_aws_signer_async_when_service_is_specified(self):
|
||||
region = "us-west-2"
|
||||
service = "aoss"
|
||||
|
||||
from opensearchpy.helpers.asyncsigner import AWSV4SignerAsyncAuth
|
||||
|
||||
auth = AWSV4SignerAsyncAuth(self.mock_session(), region, service)
|
||||
headers = auth("GET", "http://localhost")
|
||||
self.assertIn("Authorization", headers)
|
||||
self.assertIn("X-Amz-Date", headers)
|
||||
self.assertIn("X-Amz-Security-Token", headers)
|
||||
|
||||
@@ -333,6 +333,9 @@ class TestUrllib3Connection(TestCase):
|
||||
self.assertIn("X-Amz-Date", prepared_request.headers)
|
||||
self.assertIn("X-Amz-Security-Token", prepared_request.headers)
|
||||
|
||||
@pytest.mark.skipif(
|
||||
sys.version_info < (3, 6), reason="AWSV4SignerAuth requires python3.6+"
|
||||
)
|
||||
def test_aws_signer_when_region_is_null(self):
|
||||
session = self.mock_session()
|
||||
|
||||
@@ -346,6 +349,9 @@ class TestUrllib3Connection(TestCase):
|
||||
AWSV4SignerAuth(session, "")
|
||||
assert str(e.value) == "Region cannot be empty"
|
||||
|
||||
@pytest.mark.skipif(
|
||||
sys.version_info < (3, 6), reason="AWSV4SignerAuth requires python3.6+"
|
||||
)
|
||||
def test_aws_signer_when_credentials_is_null(self):
|
||||
region = "us-west-1"
|
||||
|
||||
@@ -359,6 +365,26 @@ class TestUrllib3Connection(TestCase):
|
||||
AWSV4SignerAuth("", region)
|
||||
assert str(e.value) == "Credentials cannot be empty"
|
||||
|
||||
@pytest.mark.skipif(
|
||||
sys.version_info < (3, 6), reason="AWSV4SignerAuth requires python3.6+"
|
||||
)
|
||||
def test_aws_signer_when_service_is_specified(self):
|
||||
region = "us-west-1"
|
||||
service = "aoss"
|
||||
|
||||
import requests
|
||||
|
||||
from opensearchpy.helpers.signer import AWSV4SignerAuth
|
||||
|
||||
auth = AWSV4SignerAuth(self.mock_session(), region, service)
|
||||
con = RequestsHttpConnection(http_auth=auth)
|
||||
prepared_request = requests.Request("GET", "http://localhost").prepare()
|
||||
auth(prepared_request)
|
||||
self.assertEqual(auth, con.session.auth)
|
||||
self.assertIn("Authorization", prepared_request.headers)
|
||||
self.assertIn("X-Amz-Date", prepared_request.headers)
|
||||
self.assertIn("X-Amz-Security-Token", prepared_request.headers)
|
||||
|
||||
def mock_session(self):
|
||||
access_key = uuid.uuid4().hex
|
||||
secret_key = uuid.uuid4().hex
|
||||
|
||||
Reference in New Issue
Block a user