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
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 -n 3 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
Copy link
Collaborator

Choose a reason for hiding this comment

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

Aren't these all defaults, do we need to specify?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you also add the --verbose flag to this command. Some of these tests take a while to run so you start to wonder if things are working with no output. This flag will show each test as it gets started running

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, I don't need to specify those in the workflow anymore. I had updated the defaults value after.
I'll update this to remove the values and add the verbose flag. Thank you!

54 changes: 46 additions & 8 deletions test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,52 @@ pytest tests.py
The test script, by default, uses the ports assigned to the containers in this
[docker-compose file](../TrafficCapture/dockerSolution/src/main/docker/docker-compose.yml), so if the Docker solution in
its current setup started with no issues, then the test script will run as is. If for any reason
the user changed the ports in that file, they must also either, change the following environment variables:
`PROXY_ENDPOINT`, `SOURCE_ENDPOINT`, and `TARGET_ENDPOINT` respectively, or update the default value
(which can be found below) for them in [tests.py](tests.py).

The following are the default values for the only endpoints touched by this script:
* `PROXY_ENDPOINT = https://localhost:9200`
* `SOURCE_ENDPOINT = http://localhost:19200`
* `TARGET_ENDPOINT = https://localhost:29200`
the user changed the ports in that file, they must also either, provide the following parameters variables:
`proxy_endpoint`, `source_endpoint`, and `target_endpoint` respectively, or update the default value
for them in [conftest.py](conftest.py).


#### Script Parameters

This script accepts various parameters to customize its behavior. Below is a list of available parameters along with their default values and acceptable choices:

- `--proxy_endpoint`: The endpoint for the proxy endpoint.
- Default: `https://localhost:9200`

- `--source_endpoint`: The endpoint for the source endpoint.
- Default: `https://localhost:19200`

- `--target_endpoint`: The endpoint for the target endpoint.
- Default: `https://localhost:29200`

- `--source_auth_type`: Specifies the authentication type for the source endpoint.
- Default: `basic`
- Choices: `none`, `basic`, `sigv4`

- `--source_verify_ssl`: Determines whether to verify the SSL certificate for the source endpoint.
- Default: `False`
- Choices: `True`, `False`

- `--target_auth_type`: Specifies the authentication type for the target endpoint.
- Default: `basic`
- Choices: `none`, `basic`, `sigv4`

- `--target_verify_ssl`: Determines whether to verify the SSL certificate for the target endpoint.
- Default: `False`
- Choices: `True`, `False`

- `--source_username`: Username for authentication with the source endpoint.
- Default: `admin`

- `--source_password`: Password for authentication with the source endpoint.
- Default: `admin`

- `--target_username`: Username for authentication with the target endpoint.
- Default: `admin`

- `--target_password`: Password for authentication with the target endpoint.
- Default: `admin`


#### Clean Up
The test script is implemented with a setup and teardown functions that are ran after
Expand Down
71 changes: 71 additions & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# conftest.py
import pytest


def pytest_addoption(parser):
parser.addoption("--proxy_endpoint", action="store", default="https://localhost:9200")
parser.addoption("--source_endpoint", action="store", default="https://localhost:19200")
parser.addoption("--target_endpoint", action="store", default="https://localhost:29200")
parser.addoption("--source_auth_type", action="store", default="basic", choices=["none", "basic", "sigv4"])
parser.addoption("--source_verify_ssl", action="store", default="False", choices=["True", "False"])
parser.addoption("--target_auth_type", action="store", default="basic", choices=["none", "basic", "sigv4"])
parser.addoption("--target_verify_ssl", action="store", default="False", choices=["True", "False"])
parser.addoption("--source_username", action="store", default="admin")
parser.addoption("--source_password", action="store", default="admin")
parser.addoption("--target_username", action="store", default="admin")
parser.addoption("--target_password", action="store", default="admin")


@pytest.fixture
def proxy_endpoint(pytestconfig):
return pytestconfig.getoption("proxy_endpoint")


@pytest.fixture
def source_endpoint(pytestconfig):
return pytestconfig.getoption("source_endpoint")


@pytest.fixture
def target_endpoint(pytestconfig):
return pytestconfig.getoption("target_endpoint")


@pytest.fixture
def source_auth_type(pytestconfig):
return pytestconfig.getoption("source_auth_type")


@pytest.fixture
def source_username(pytestconfig):
return pytestconfig.getoption("source_username")


@pytest.fixture
def source_password(pytestconfig):
return pytestconfig.getoption("source_password")


@pytest.fixture
def target_auth_type(pytestconfig):
return pytestconfig.getoption("target_auth_type")


@pytest.fixture
def target_username(pytestconfig):
return pytestconfig.getoption("target_username")


@pytest.fixture
def target_password(pytestconfig):
return pytestconfig.getoption("target_password")


@pytest.fixture
def target_verify_ssl(pytestconfig):
return pytestconfig.getoption("target_verify_ssl")


@pytest.fixture
def source_verify_ssl(pytestconfig):
return pytestconfig.getoption("source_verify_ssl")
27 changes: 15 additions & 12 deletions test/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,50 @@
from typing import Optional, Tuple


def create_index(endpoint: str, index_name: str, auth: Optional[Tuple[str, str]] = None):
response = requests.put(f'{endpoint}/{index_name}', auth=auth, verify=False)
def create_index(endpoint: str, index_name: str, auth: Optional[Tuple[str, str]] = None, verify_ssl: bool = False):
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):
response = requests.get(f'{endpoint}/{index_name}', auth=auth, verify=False)
def check_index(endpoint: str, index_name: str, auth: Optional[Tuple[str, str]] = None, verify_ssl: bool = False):
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):
response = requests.delete(f'{endpoint}/{index_name}', auth=auth, verify=False)
def delete_index(endpoint: str, index_name: str, auth: Optional[Tuple[str, str]] = None, 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):
response = requests.delete(f'{endpoint}/{index_name}/_doc/{doc_id}', auth=auth, verify=False)
def delete_document(endpoint: str, index_name: str, doc_id: str, auth: Optional[Tuple[str, str]] = None,
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: Optional[Tuple[str, str]] = None,
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=False)
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: Optional[Tuple[str, str]] = None,
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=False)
response = requests.get(url, headers=headers, auth=auth, verify=verify_ssl)

return response
Loading
Loading