Skip to content

Commit

Permalink
draft - admin token is retrieved via direct method call in some of th…
Browse files Browse the repository at this point in the history
…e tests
  • Loading branch information
eladiw committed Sep 8, 2022
1 parent f6f9650 commit b6d1dac
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 44 deletions.
1 change: 0 additions & 1 deletion e2e_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def verify(pytestconfig):
return False


@pytest.fixture
async def admin_token(verify) -> str:
async with AsyncClient(verify=verify) as client:
responseJson = ""
Expand Down
11 changes: 7 additions & 4 deletions e2e_tests/test_airlock.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from airlock.request import post_request, get_request, upload_blob_using_sas, wait_for_status
from airlock import strings as airlock_strings

from conftest import admin_token

pytestmark = pytest.mark.asyncio
LOGGER = logging.getLogger(__name__)
Expand All @@ -23,8 +24,9 @@
@pytest.mark.airlock
@pytest.mark.extended
@pytest.mark.timeout(2000)
async def test_airlock_import_flow(admin_token, verify) -> None:
async def test_airlock_import_flow(verify) -> None:

admin_tkn = admin_token(verify)
if config.TEST_AIRLOCK_WORKSPACE_ID != "":
workspace_id = config.TEST_AIRLOCK_WORKSPACE_ID
workspace_path = f"/workspaces/{workspace_id}"
Expand All @@ -45,8 +47,8 @@ async def test_airlock_import_flow(admin_token, verify) -> None:
if config.TEST_WORKSPACE_APP_PLAN != "":
payload["properties"]["app_service_plan_sku"] = config.TEST_WORKSPACE_APP_PLAN

workspace_path, workspace_id = await post_resource(payload, resource_strings.API_WORKSPACES, access_token=admin_token, verify=verify)
workspace_owner_token, scope_uri = await get_workspace_auth_details(admin_token=admin_token, workspace_id=workspace_id, verify=verify)
workspace_path, workspace_id = await post_resource(payload, resource_strings.API_WORKSPACES, access_token=admin_tkn, verify=verify)
workspace_owner_token, scope_uri = await get_workspace_auth_details(admin_token=admin_tkn, workspace_id=workspace_id, verify=verify)

# 2. create airlock request
LOGGER.info("Creating airlock request")
Expand Down Expand Up @@ -125,4 +127,5 @@ async def test_airlock_import_flow(admin_token, verify) -> None:
if config.TEST_AIRLOCK_WORKSPACE_ID == "":
# 8. delete workspace
LOGGER.info("Deleting workspace")
await disable_and_delete_resource(f'/api{workspace_path}', admin_token, verify)
admin_tkn = admin_token(verify)
await disable_and_delete_resource(f'/api{workspace_path}', admin_tkn, verify)
19 changes: 12 additions & 7 deletions e2e_tests/test_performance.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
from resources.resource import disable_and_delete_resource, post_resource
from resources import strings

from conftest import admin_token

pytestmark = pytest.mark.asyncio


@pytest.mark.performance
@pytest.mark.timeout(3000)
async def test_parallel_resource_creations(admin_token, verify) -> None:
async def test_parallel_resource_creations(verify) -> None:
"""Creates N workspaces in parallel, and creates a workspace service in each, in parallel"""

number_workspaces = 2
Expand All @@ -28,15 +30,16 @@ async def test_parallel_resource_creations(admin_token, verify) -> None:
}
}

task = asyncio.create_task(post_resource(payload=payload, endpoint=strings.API_WORKSPACES, access_token=admin_token, verify=verify))
admin_tkn = admin_token(verify)
task = asyncio.create_task(post_resource(payload=payload, endpoint=strings.API_WORKSPACES, access_token=admin_tkn, verify=verify))
tasks.append(task)

resource_paths = await asyncio.gather(*tasks)

# Now disable + delete them all in parallel
tasks = []
for workspace_path, _ in resource_paths:
task = asyncio.create_task(disable_and_delete_resource(f'/api{workspace_path}', admin_token, verify))
task = asyncio.create_task(disable_and_delete_resource(f'/api{workspace_path}', admin_tkn, verify))
tasks.append(task)

await asyncio.gather(*tasks)
Expand All @@ -45,7 +48,7 @@ async def test_parallel_resource_creations(admin_token, verify) -> None:
@pytest.mark.skip
@pytest.mark.performance
@pytest.mark.timeout(3000)
async def test_bulk_updates_to_ensure_each_resource_updated_in_series(admin_token, verify) -> None:
async def test_bulk_updates_to_ensure_each_resource_updated_in_series(verify) -> None:
"""Optionally creates a workspace and workspace service,
then creates N number of VMs in parallel, patches each, and deletes them"""

Expand All @@ -69,11 +72,12 @@ async def test_bulk_updates_to_ensure_each_resource_updated_in_series(admin_toke
}
}

workspace_path, workspace_id = await post_resource(payload, strings.API_WORKSPACES, admin_token, verify)
admin_tkn = admin_token(verify)
workspace_path, workspace_id = await post_resource(payload, strings.API_WORKSPACES, admin_tkn, verify)
else:
workspace_path = f"/workspaces/{config.PERF_TEST_WORKSPACE_ID}"

workspace_owner_token, scope_uri = await get_workspace_auth_details(admin_token=admin_token, workspace_id=workspace_id, verify=verify)
workspace_owner_token, scope_uri = await get_workspace_auth_details(admin_token=admin_tkn, workspace_id=workspace_id, verify=verify)

if config.PERF_TEST_WORKSPACE_SERVICE_ID == "":
# create a guac service
Expand Down Expand Up @@ -140,8 +144,9 @@ async def test_bulk_updates_to_ensure_each_resource_updated_in_series(admin_toke

await asyncio.gather(*tasks)

admin_tkn = admin_token(verify)
# clear up workspace + service (if we created them)
if config.PERF_TEST_WORKSPACE_SERVICE_ID == "":
await disable_and_delete_resource(f'/api{workspace_service_path}', workspace_owner_token, verify)
if config.PERF_TEST_WORKSPACE_ID == "":
await disable_and_delete_resource(f'/api{workspace_path}', admin_token, verify)
await disable_and_delete_resource(f'/api{workspace_path}', admin_tkn, verify)
11 changes: 7 additions & 4 deletions e2e_tests/test_shared_service_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import config
from helpers import get_auth_header, get_template
from resources import strings
from conftest import admin_token

shared_service_templates = [
(strings.FIREWALL_SHARED_SERVICE),
Expand All @@ -15,16 +16,18 @@

@pytest.mark.smoke
@pytest.mark.parametrize("template_name", shared_service_templates)
async def test_get_shared_service_templates(template_name, admin_token, verify) -> None:
async def test_get_shared_service_templates(template_name, verify) -> None:
async with AsyncClient(verify=verify) as client:
response = await client.get(f"https://{config.TRE_ID}.{config.RESOURCE_LOCATION}.cloudapp.azure.com{strings.API_SHARED_SERVICE_TEMPLATES}", headers=get_auth_header(admin_token))
admin_tkn = admin_token(verify)
response = await client.get(f"https://{config.TRE_ID}.{config.RESOURCE_LOCATION}.cloudapp.azure.com{strings.API_SHARED_SERVICE_TEMPLATES}", headers=get_auth_header(admin_tkn))

template_names = [templates["name"] for templates in response.json()["templates"]]
assert (template_name in template_names), f"No {template_name} template found"


@pytest.mark.smoke
@pytest.mark.parametrize("template_name", shared_service_templates)
async def test_get_shared_service_template(template_name, admin_token, verify) -> None:
async with get_template(template_name, strings.API_SHARED_SERVICE_TEMPLATES, admin_token, verify) as response:
async def test_get_shared_service_template(template_name, verify) -> None:
admin_tkn = admin_token(verify)
async with get_template(template_name, strings.API_SHARED_SERVICE_TEMPLATES, admin_tkn, verify) as response:
assert (response.status_code == status.HTTP_200_OK), f"GET Request for {template_name} failed"
19 changes: 11 additions & 8 deletions e2e_tests/test_shared_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
from resources.resource import disable_and_delete_resource, post_resource
from helpers import get_shared_service_id_by_name
from resources import strings

from conftest import admin_token

LOGGER = logging.getLogger(__name__)


@pytest.mark.shared_services
async def test_patch_firewall(admin_token, verify):
async def test_patch_firewall(verify):
template_name = strings.FIREWALL_SHARED_SERVICE

patch_payload = {
Expand Down Expand Up @@ -70,8 +70,9 @@ async def test_patch_firewall(admin_token, verify):
"templateName": template_name,
}

admin_tkn = admin_token(verify)
shared_service_firewall = await get_shared_service_id_by_name(
template_name, verify, admin_token
template_name, verify, admin_tkn
)
shared_service_path = f'/shared-services/{shared_service_firewall["id"]}'

Expand All @@ -93,18 +94,19 @@ async def test_patch_firewall(admin_token, verify):
@pytest.mark.shared_services
@pytest.mark.timeout(65 * 60)
@pytest.mark.parametrize("template_name", shared_service_templates_to_create)
async def test_create_shared_service(template_name, admin_token, verify) -> None:
async def test_create_shared_service(template_name, verify) -> None:
admin_tkn = admin_token(verify)
# Check that the shared service hasn't already been created
shared_service = await get_shared_service_id_by_name(
template_name, verify, admin_token
template_name, verify, admin_tkn
)
if shared_service:
id = shared_service["id"]
LOGGER.info(
f"Shared service {template_name} already exists (id {id}), deleting it first..."
)
await disable_and_delete_resource(
f"/api/shared-services/{id}", admin_token, verify
f"/api/shared-services/{id}", admin_tkn, verify
)

post_payload = {
Expand All @@ -118,10 +120,11 @@ async def test_create_shared_service(template_name, admin_token, verify) -> None
shared_service_path, _ = await post_resource(
payload=post_payload,
endpoint="/api/shared-services",
access_token=admin_token,
access_token=admin_tkn,
verify=verify,
)

admin_tkn = admin_token(verify)
await disable_and_delete_resource(
f"/api{shared_service_path}", admin_token, verify
f"/api{shared_service_path}", admin_tkn, verify
)
17 changes: 10 additions & 7 deletions e2e_tests/test_workspace_service_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import config
from helpers import get_auth_header, get_template
from resources import strings

from conftest import admin_token

pytestmark = pytest.mark.asyncio

Expand All @@ -20,23 +20,25 @@

@pytest.mark.smoke
@pytest.mark.parametrize("template_name", workspace_service_templates)
async def test_get_workspace_service_templates(template_name, admin_token, verify) -> None:
async def test_get_workspace_service_templates(template_name, verify) -> None:
async with AsyncClient(verify=verify) as client:
response = await client.get(f"https://{config.TRE_ID}.{config.RESOURCE_LOCATION}.cloudapp.azure.com{strings.API_WORKSPACE_SERVICE_TEMPLATES}", headers=get_auth_header(admin_token))
admin_tkn = admin_token(verify)
response = await client.get(f"https://{config.TRE_ID}.{config.RESOURCE_LOCATION}.cloudapp.azure.com{strings.API_WORKSPACE_SERVICE_TEMPLATES}", headers=get_auth_header(admin_tkn))

template_names = [templates["name"] for templates in response.json()["templates"]]
assert (template_name in template_names), f"No {template_name} template found"


@pytest.mark.smoke
@pytest.mark.parametrize("template_name", workspace_service_templates)
async def test_get_workspace_service_template(template_name, admin_token, verify) -> None:
async with get_template(template_name, strings.API_WORKSPACE_SERVICE_TEMPLATES, admin_token, verify) as response:
async def test_get_workspace_service_template(template_name, verify) -> None:
admin_tkn = admin_token(verify)
async with get_template(template_name, strings.API_WORKSPACE_SERVICE_TEMPLATES, admin_tkn, verify) as response:
assert (response.status_code == status.HTTP_200_OK), f"GET Request for {template_name} failed"


@pytest.mark.smoke
async def test_create_workspace_service_templates(admin_token, verify) -> None:
async def test_create_workspace_service_templates(verify) -> None:
async with AsyncClient(verify=verify) as client:
payload = {
"name": f"{strings.TEST_WORKSPACE_SERVICE_TEMPLATE}",
Expand All @@ -53,6 +55,7 @@ async def test_create_workspace_service_templates(admin_token, verify) -> None:
}
}

response = await client.post(f"https://{config.TRE_ID}.{config.RESOURCE_LOCATION}.cloudapp.azure.com{strings.API_WORKSPACE_SERVICE_TEMPLATES}", headers=get_auth_header(admin_token), json=payload)
admin_tkn = admin_token(verify)
response = await client.post(f"https://{config.TRE_ID}.{config.RESOURCE_LOCATION}.cloudapp.azure.com{strings.API_WORKSPACE_SERVICE_TEMPLATES}", headers=get_auth_header(admin_tkn), json=payload)

assert (response.status_code == status.HTTP_201_CREATED or response.status_code == status.HTTP_409_CONFLICT), "The workspace service template creation service returned unexpected response."
22 changes: 13 additions & 9 deletions e2e_tests/test_workspace_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
from resources.workspace import get_workspace_auth_details
from resources.resource import disable_and_delete_resource, post_resource
from resources import strings

from conftest import admin_token

pytestmark = pytest.mark.asyncio


@pytest.mark.extended
@pytest.mark.timeout(75 * 60)
async def test_create_guacamole_service_into_base_workspace(admin_token, verify) -> None:
async def test_create_guacamole_service_into_base_workspace(verify) -> None:

payload = {
"templateName": strings.BASE_WORKSPACE,
Expand All @@ -27,8 +27,9 @@ async def test_create_guacamole_service_into_base_workspace(admin_token, verify)
if config.TEST_WORKSPACE_APP_PLAN != "":
payload["properties"]["app_service_plan_sku"] = config.TEST_WORKSPACE_APP_PLAN

workspace_path, workspace_id = await post_resource(payload, strings.API_WORKSPACES, access_token=admin_token, verify=verify)
workspace_owner_token, scope_uri = await get_workspace_auth_details(admin_token=admin_token, workspace_id=workspace_id, verify=verify)
admin_tkn = admin_token(verify)
workspace_path, workspace_id = await post_resource(payload, strings.API_WORKSPACES, access_token=admin_tkn, verify=verify)
workspace_owner_token, scope_uri = await get_workspace_auth_details(admin_token=admin_tkn, workspace_id=workspace_id, verify=verify)

service_payload = {
"templateName": strings.GUACAMOLE_SERVICE,
Expand Down Expand Up @@ -67,12 +68,13 @@ async def test_create_guacamole_service_into_base_workspace(admin_token, verify)

await disable_and_delete_resource(f'/api{workspace_service_path}', workspace_owner_token, verify)

await disable_and_delete_resource(f'/api{workspace_path}', admin_token, verify)
admin_tkn = admin_token(verify)
await disable_and_delete_resource(f'/api{workspace_path}', admin_tkn, verify)


@pytest.mark.extended_aad
@pytest.mark.timeout(75 * 60)
async def test_create_guacamole_service_into_aad_workspace(admin_token, verify) -> None:
async def test_create_guacamole_service_into_aad_workspace(verify) -> None:
"""This test will create a Guacamole service but will create a workspace and automatically register the AAD Application"""

payload = {
Expand All @@ -87,8 +89,9 @@ async def test_create_guacamole_service_into_aad_workspace(admin_token, verify)
if config.TEST_WORKSPACE_APP_PLAN != "":
payload["properties"]["app_service_plan_sku"] = config.TEST_WORKSPACE_APP_PLAN

workspace_path, workspace_id = await post_resource(payload, strings.API_WORKSPACES, access_token=admin_token, verify=verify)
workspace_owner_token, scope_uri = await get_workspace_auth_details(admin_token=admin_token, workspace_id=workspace_id, verify=verify)
admin_tkn = admin_token(verify)
workspace_path, workspace_id = await post_resource(payload, strings.API_WORKSPACES, access_token=admin_tkn, verify=verify)
workspace_owner_token, scope_uri = await get_workspace_auth_details(admin_token=admin_tkn, workspace_id=workspace_id, verify=verify)

service_payload = {
"templateName": strings.GUACAMOLE_SERVICE,
Expand Down Expand Up @@ -127,4 +130,5 @@ async def test_create_guacamole_service_into_aad_workspace(admin_token, verify)

await disable_and_delete_resource(f'/api{workspace_service_path}', workspace_owner_token, verify)

await disable_and_delete_resource(f'/api{workspace_path}', admin_token, verify)
admin_tkn = admin_token(verify)
await disable_and_delete_resource(f'/api{workspace_path}', admin_tkn, verify)
11 changes: 7 additions & 4 deletions e2e_tests/test_workspace_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import config
from helpers import get_auth_header, get_template
from resources import strings
from conftest import admin_token


pytestmark = pytest.mark.asyncio
Expand All @@ -18,16 +19,18 @@

@pytest.mark.smoke
@pytest.mark.parametrize("template_name", workspace_templates)
async def test_get_workspace_templates(template_name, admin_token, verify) -> None:
async def test_get_workspace_templates(template_name, verify) -> None:
async with AsyncClient(verify=verify) as client:
response = await client.get(f"https://{config.TRE_ID}.{config.RESOURCE_LOCATION}.cloudapp.azure.com{strings.API_WORKSPACE_TEMPLATES}", headers=get_auth_header(admin_token))
admin_tkn = admin_token(verify)
response = await client.get(f"https://{config.TRE_ID}.{config.RESOURCE_LOCATION}.cloudapp.azure.com{strings.API_WORKSPACE_TEMPLATES}", headers=get_auth_header(admin_tkn))

template_names = [templates["name"] for templates in response.json()["templates"]]
assert (template_name in template_names), f"No {template_name} template found"


@pytest.mark.smoke
@pytest.mark.parametrize("template_name", workspace_templates)
async def test_get_workspace_template(template_name, admin_token, verify) -> None:
async with get_template(template_name, strings.API_WORKSPACE_TEMPLATES, admin_token, verify) as response:
async def test_get_workspace_template(template_name, verify) -> None:
admin_tkn = admin_token(verify)
async with get_template(template_name, strings.API_WORKSPACE_TEMPLATES, admin_tkn, verify) as response:
assert (response.status_code == status.HTTP_200_OK), f"GET Request for {template_name} creation failed"

0 comments on commit b6d1dac

Please sign in to comment.