Skip to content

Commit

Permalink
Merge pull request #461 from okhasawn/parametersTest
Browse files Browse the repository at this point in the history
Add endpoints and authentication details (including SigV4) as parameters to E2E test script
  • Loading branch information
okhasawn committed Jan 11, 2024
2 parents c14529b + c7c1da3 commit 75ff259
Show file tree
Hide file tree
Showing 6 changed files with 271 additions and 82 deletions.
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 --unique_id="testindex"
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
95 changes: 95 additions & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# 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")
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("--deployment_type", action="store", default="local", choices=["local", "cloud"])
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")
parser.addoption("--unique_id", action="store", default="")


@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")


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


@pytest.fixture
def unique_id(pytestconfig):
return pytestconfig.getoption("unique_id")
30 changes: 15 additions & 15 deletions test/operations.py
Original file line number Diff line number Diff line change
@@ -1,49 +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):
response = requests.put(f'{endpoint}/{index_name}', auth=auth, verify=False)
def create_index(endpoint: str, index_name: str, auth, verify_ssl: bool = False):
response = requests.put(f'{endpoint}/{index_name}', auth=auth, verify=verify_ssl)

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, 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, 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,
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=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,
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
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
boto3
Loading

0 comments on commit 75ff259

Please sign in to comment.