Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add endpoints and authentication details (including SigV4) as parameters to E2E test script #461

Merged
merged 12 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/e2eTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ jobs:
run: |
cd test
chmod +x ./tests.py
pytest tests.py --proxy_endpoint="https://localhost:9200" --source_endpoint="https://localhost:19200" --target_endpoint="https://localhost:29200" --source_auth_type="basic" --source_username="admin" --source_password="admin" --target_auth_type="basic" --target_username="admin" --target_password="admin" --source_verify_ssl=False --target_verify_ssl=False
pytest tests.py
12 changes: 12 additions & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
# conftest.py
import pytest

import logging


def pytest_configure(config):
# Configure logging
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s - %(levelname)s - %(message)s',
datefmt='%Y-%m-%d %H:%M:%S')

# This line ensures that log messages are displayed on the console during test runs
logging.getLogger().setLevel(logging.DEBUG)


def pytest_addoption(parser):
parser.addoption("--proxy_endpoint", action="store", default="https://localhost:9200")
Expand Down
15 changes: 6 additions & 9 deletions test/operations.py
Original file line number Diff line number Diff line change
@@ -1,52 +1,49 @@
import requests
import json
from typing import Optional, Tuple


def create_index(endpoint: str, index_name: str, auth: Optional[Tuple[str, str]] = None, verify_ssl: bool = False):
def create_index(endpoint: str, index_name: str, auth, verify_ssl: bool = False, protocol: str = 'https'):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is the protocol argument being used in these methods? And why do only some methods have?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll remove this. Mistakenly added from something else I was testing.

response = requests.put(f'{endpoint}/{index_name}', auth=auth, verify=verify_ssl)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume the requests library is smart enough to see if it has basic or sigv4 auth passed to it and parse accordingly

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's correct!


return response


def check_index(endpoint: str, index_name: str, auth: Optional[Tuple[str, str]] = None, verify_ssl: bool = False):
def check_index(endpoint: str, index_name: str, auth, verify_ssl: bool = False, protocol: str = 'https'):
response = requests.get(f'{endpoint}/{index_name}', auth=auth, verify=verify_ssl)

return response


def delete_index(endpoint: str, index_name: str, auth: Optional[Tuple[str, str]] = None, verify_ssl: bool = False):
def delete_index(endpoint: str, index_name: str, auth, verify_ssl: bool = False):
response = requests.delete(f'{endpoint}/{index_name}', auth=auth, verify=verify_ssl)

return response


def delete_document(endpoint: str, index_name: str, doc_id: str, auth: Optional[Tuple[str, str]] = None,
def delete_document(endpoint: str, index_name: str, doc_id: str, auth,
verify_ssl: bool = False):
response = requests.delete(f'{endpoint}/{index_name}/_doc/{doc_id}', auth=auth, verify=verify_ssl)

return response


def create_document(endpoint: str, index_name: str, doc_id: str, auth: Optional[Tuple[str, str]] = None,
def create_document(endpoint: str, index_name: str, doc_id: str, auth,
verify_ssl: bool = False):
document = {
'title': 'Test Document',
'content': 'This is a sample document for testing OpenSearch.'
}
url = f'{endpoint}/{index_name}/_doc/{doc_id}'
headers = {'Content-Type': 'application/json'}

response = requests.put(url, headers=headers, data=json.dumps(document), auth=auth, verify=verify_ssl)

return response


def get_document(endpoint: str, index_name: str, doc_id: str, auth: Optional[Tuple[str, str]] = None,
def get_document(endpoint: str, index_name: str, doc_id: str, auth,
verify_ssl: bool = False):
url = f'{endpoint}/{index_name}/_doc/{doc_id}'
headers = {'Content-Type': 'application/json'}

response = requests.get(url, headers=headers, auth=auth, verify=verify_ssl)

return response
2 changes: 2 additions & 0 deletions test/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ pytest==7.3.1
pytest-xdist==3.3.1
requests==2.31.0
urllib3==2.0.7
requests_aws4auth
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this what FetchMigration uses as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, although one has a "-" and the other has a "_", but they're the exact same.

boto3
8 changes: 8 additions & 0 deletions test/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import string
import secrets
import pytest
import boto3
from requests_aws4auth import AWS4Auth

from requests.exceptions import ConnectionError, SSLError

Expand Down Expand Up @@ -92,6 +94,12 @@ def init_fixtures(self, proxy_endpoint, source_endpoint, target_endpoint, source
def setup_authentication(self, auth_type, username, password):
if auth_type == "basic":
return (username, password)
elif auth_type == "sigv4":
session = boto3.Session()
credentials = session.get_credentials()
aws_auth = AWS4Auth(credentials.access_key, credentials.secret_key, session.region_name, 'es',
session_token=credentials.token)
return aws_auth
return None

def set_common_values(self):
Expand Down
Loading