1
0
mirror of synced 2026-01-03 06:02:23 -05:00
Files
airbyte/octavia-cli/integration_tests/conftest.py
Evan Tahler 3d053e32ee Use Nginx + Basic Auth to secure OSS Airbyte (#17694)
* Use Nginx + Basic Auth to secure OSS Airbyte

* use local passwords

* Use gradle builds

* K8s setup and source values from ENV

* note about disabling

* add back defaults

* custom 401 page

* update http message

* update docs

* remove kube files

* additional doc updates

* Add a test suite

* fix failure exit codes

* doc updates

* Add docs

* bump to re-test

* add more sleep in tests for CI

* better sleep in test

* Update docs/operator-guides/security.md

Co-authored-by: Davin Chia <davinchia@gmail.com>

* PR updates

* test comment

* change test host on CI

* update tests and nginx to boot without backend

* proxy updates for docker DNS

* simpler test for uptime

* acceptance test skips PWs

* remove resolver madness

* fixup tests

* more proxy_pass revert

* update acceptance test exit codes

* relax test expectations

* add temporal mount back for testing

* Update docs/operator-guides/security.md

Co-authored-by: swyx <shawnthe1@gmail.com>

* Update airbyte-proxy/401.html

Co-authored-by: swyx <shawnthe1@gmail.com>

* more doc updates

* Octavia CLI uses Basic Auth  (#17982)

* [WIP] Octavia CLI uses Basic Auth

* readme

* augustin: add basic auth headers to clien

* augustin: add basic auth headers to client

* tests passing

* lint

* docs

* Move monkey patch to test

* coerce headers into strings

* monkey patch get_basic_auth_token

Co-authored-by: alafanechere <augustin.lafanechere@gmail.com>

* fix launch permissions

* Keep worker port internal

* more readme

Co-authored-by: Davin Chia <davinchia@gmail.com>
Co-authored-by: swyx <shawnthe1@gmail.com>
Co-authored-by: alafanechere <augustin.lafanechere@gmail.com>
2022-10-19 15:52:01 -07:00

156 lines
6.1 KiB
Python

#
# Copyright (c) 2022 Airbyte, Inc., all rights reserved.
#
import os
import pytest
import yaml
from airbyte_api_client.api import connection_api
from airbyte_api_client.model.connection_id_request_body import ConnectionIdRequestBody
from octavia_cli.apply.resources import Connection, Destination, Source
from octavia_cli.entrypoint import get_api_client, get_workspace_id
from octavia_cli.init.commands import DIRECTORIES_TO_CREATE as OCTAVIA_PROJECT_DIRECTORIES
def silent_remove(path):
try:
os.remove(path)
return True
except FileNotFoundError:
return False
@pytest.fixture
def octavia_tmp_project_directory(tmpdir):
for directory in OCTAVIA_PROJECT_DIRECTORIES:
tmpdir.mkdir(directory)
return tmpdir
@pytest.fixture(scope="session")
def octavia_test_project_directory():
return f"{os.path.dirname(__file__)}/configurations"
@pytest.fixture(scope="session")
def api_client():
return get_api_client("http://localhost:8000", "airbyte", "password", "octavia-cli/integration-tests", None)
@pytest.fixture(scope="session")
def workspace_id(api_client):
return get_workspace_id(api_client, None)
def open_yaml_configuration(path: str):
with open(path, "r") as f:
local_configuration = yaml.safe_load(f)
return local_configuration, path
@pytest.fixture(scope="session")
def source_configuration_and_path(octavia_test_project_directory):
path = f"{octavia_test_project_directory}/sources/poke/configuration.yaml"
return open_yaml_configuration(path)
@pytest.fixture(scope="session")
def source_state_path(octavia_test_project_directory, workspace_id):
state_path = f"{octavia_test_project_directory}/sources/poke/state_{workspace_id}.yaml"
silent_remove(state_path)
yield state_path
silent_remove(state_path)
@pytest.fixture(scope="session")
def source(api_client, workspace_id, source_configuration_and_path, source_state_path):
configuration, path = source_configuration_and_path
source = Source(api_client, workspace_id, configuration, path)
yield source
source.api_instance.delete_source(source.get_payload)
@pytest.fixture(scope="session")
def destination_configuration_and_path(octavia_test_project_directory):
path = f"{octavia_test_project_directory}/destinations/postgres/configuration.yaml"
return open_yaml_configuration(path)
@pytest.fixture(scope="session")
def destination_state_path(octavia_test_project_directory, workspace_id):
state_path = f"{octavia_test_project_directory}/destinations/postgres/state_{workspace_id}.yaml"
silent_remove(state_path)
yield state_path
silent_remove(state_path)
@pytest.fixture(scope="session")
def destination(api_client, workspace_id, destination_configuration_and_path, destination_state_path):
configuration, path = destination_configuration_and_path
destination = Destination(api_client, workspace_id, configuration, path)
yield destination
destination.api_instance.delete_destination(destination.get_payload)
@pytest.fixture(scope="session")
def connection_configuration_and_path(octavia_test_project_directory):
path = f"{octavia_test_project_directory}/connections/poke_to_pg/configuration.yaml"
with open(path, "r") as f:
local_configuration = yaml.safe_load(f)
return local_configuration, path
@pytest.fixture(scope="session")
def connection_state_path(octavia_test_project_directory, workspace_id):
state_path = f"{octavia_test_project_directory}/connections/poke_to_pg/state_{workspace_id}.yaml"
silent_remove(state_path)
yield state_path
silent_remove(state_path)
@pytest.fixture(scope="session")
def connection_with_normalization_state_path(octavia_test_project_directory, workspace_id):
state_path = f"{octavia_test_project_directory}/connections/poke_to_pg_normalization/state_{workspace_id}.yaml"
silent_remove(state_path)
yield state_path
silent_remove(state_path)
def updated_connection_configuration_and_path(octavia_test_project_directory, source, destination, with_normalization=False):
if with_normalization:
path = f"{octavia_test_project_directory}/connections/poke_to_pg_normalization/configuration.yaml"
edited_path = f"{octavia_test_project_directory}/connections/poke_to_pg_normalization/updated_configuration.yaml"
else:
path = f"{octavia_test_project_directory}/connections/poke_to_pg/configuration.yaml"
edited_path = f"{octavia_test_project_directory}/connections/poke_to_pg/updated_configuration.yaml"
with open(path, "r") as dumb_local_configuration_file:
local_configuration = yaml.safe_load(dumb_local_configuration_file)
local_configuration["source_configuration_path"] = source.configuration_path
local_configuration["destination_configuration_path"] = destination.configuration_path
with open(edited_path, "w") as updated_configuration_file:
yaml.dump(local_configuration, updated_configuration_file)
return local_configuration, edited_path
@pytest.fixture(scope="session")
def connection(api_client, workspace_id, octavia_test_project_directory, source, destination, connection_state_path):
configuration, configuration_path = updated_connection_configuration_and_path(octavia_test_project_directory, source, destination)
connection = Connection(api_client, workspace_id, configuration, configuration_path)
yield connection
connection_api.ConnectionApi(api_client).delete_connection(ConnectionIdRequestBody(connection.resource_id))
silent_remove(configuration_path)
@pytest.fixture(scope="session")
def connection_with_normalization(
api_client, workspace_id, octavia_test_project_directory, source, destination, connection_with_normalization_state_path
):
configuration, configuration_path = updated_connection_configuration_and_path(
octavia_test_project_directory, source, destination, with_normalization=True
)
connection = Connection(api_client, workspace_id, configuration, configuration_path)
yield connection
connection_api.ConnectionApi(api_client).delete_connection(ConnectionIdRequestBody(connection.resource_id))
silent_remove(configuration_path)