1
0
mirror of synced 2026-01-01 09:02:59 -05:00
Files
airbyte/octavia-cli/integration_tests/test_api_http_headers.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

78 lines
2.5 KiB
Python

#
# Copyright (c) 2022 Airbyte, Inc., all rights reserved.
#
import base64
import logging
import pytest
from click.testing import CliRunner
from octavia_cli import api_http_headers, entrypoint
logging.basicConfig() # you need to initialize logging, otherwise you will not see anything from vcrpy
vcr_log = logging.getLogger("vcr")
vcr_log.setLevel(logging.WARN)
AIRBYTE_URL = "http://localhost:8000"
AIRBYTE_USERNAME = "airbyte"
AIRBYTE_PASSWORD = "password"
@pytest.fixture(scope="module")
def vcr_config():
return {
"record_mode": "rewrite",
"match_on": ["method", "scheme", "host", "port", "path", "query", "headers"],
}
@pytest.fixture
def file_based_headers(tmp_path):
yaml_document = """
headers:
Custom-Header: Foo
"""
custom_api_http_headers_yaml_file_path = tmp_path / "custom_api_http_headers.yaml"
custom_api_http_headers_yaml_file_path.write_text(yaml_document)
expected_headers = [api_http_headers.ApiHttpHeader("Custom-Header", "Foo")]
return custom_api_http_headers_yaml_file_path, expected_headers
@pytest.fixture
def option_based_headers():
return ["Another-Custom-Header", "Bar"], [api_http_headers.ApiHttpHeader("Another-Custom-Header", "Bar")]
@pytest.mark.vcr
def test_api_http_headers(vcr, file_based_headers, option_based_headers):
raw_option_based_headers, expected_option_based_headers = option_based_headers
custom_api_http_headers_yaml_file_path, expected_file_based_headers = file_based_headers
basic_auth_header_value = f"Basic {base64.b64encode(f'{AIRBYTE_USERNAME}:{AIRBYTE_PASSWORD}'.encode()).decode()}"
expected_headers = (
expected_option_based_headers
+ expected_file_based_headers
+ [api_http_headers.ApiHttpHeader("Authorization", basic_auth_header_value)]
)
runner = CliRunner()
command_options = (
[
"--airbyte-url",
AIRBYTE_URL,
"--airbyte-username",
AIRBYTE_USERNAME,
"--airbyte-password",
AIRBYTE_PASSWORD,
"--api-http-headers-file-path",
custom_api_http_headers_yaml_file_path,
"--api-http-header",
]
+ raw_option_based_headers
+ ["list", "connectors", "sources"]
)
result = runner.invoke(entrypoint.octavia, command_options, obj={})
for request in vcr.requests:
for expected_header in expected_headers:
assert request.headers[expected_header.name] == expected_header.value
assert result.exit_code == 0