Skip to content

Commit

Permalink
Update aircmd and fix testing TODO's (#8315)
Browse files Browse the repository at this point in the history
  • Loading branch information
Conor committed Aug 18, 2023
1 parent 46ac990 commit 2bf5f3f
Show file tree
Hide file tree
Showing 19 changed files with 274 additions and 133 deletions.
1 change: 1 addition & 0 deletions airbyte-connector-builder-server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ plugins {
id "io.airbyte.gradle.jvm.app"
id "io.airbyte.gradle.docker"
id "org.openapi.generator"
id "io.airbyte.gradle.publish"
}

dependencies {
Expand Down
1 change: 1 addition & 0 deletions airbyte-container-orchestrator/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import java.util.zip.ZipFile
plugins {
id "io.airbyte.gradle.jvm.app"
id "io.airbyte.gradle.docker"
id "io.airbyte.gradle.publish"
}

configurations {
Expand Down
1 change: 1 addition & 0 deletions airbyte-cron/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
id "io.airbyte.gradle.jvm.app"
id "io.airbyte.gradle.docker"
id "io.airbyte.gradle.publish"
}

dependencies {
Expand Down
6 changes: 1 addition & 5 deletions airbyte-keycloak/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id "io.airbyte.gradle.docker"
id "io.airbyte.gradle.publish"
}

airbyte {
Expand All @@ -22,8 +23,3 @@ tasks.named("dockerBuildImage") {
dependsOn copyScripts
dependsOn copyTheme
}

tasks.register("test") {
description "dummy test task because `test` is part of the base jvm plugin, but there are no tests to run for this module." +
"Without this, running something like `build -x test` will fail because it can't find a test task to exclude."
}
1 change: 1 addition & 0 deletions airbyte-metrics/reporter/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
id "io.airbyte.gradle.jvm.app"
id "io.airbyte.gradle.docker"
id "io.airbyte.gradle.publish"
}

configurations {
Expand Down
1 change: 1 addition & 0 deletions airbyte-proxy/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
id "io.airbyte.gradle.jvm"
id "io.airbyte.gradle.docker"
id "io.airbyte.gradle.publish"
}

airbyte {
Expand Down
32 changes: 32 additions & 0 deletions airbyte-proxy/nginx-test-auth-newpass.conf.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
events {}

http {
server {
listen 8001 default_server;

location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 200M;

auth_basic "Welcome to Airbyte";
auth_basic_user_file /etc/nginx/.htpasswd;

error_page 401 /etc/nginx/401.html;
location ~ (401.html)$ {
alias /etc/nginx/$1;
auth_basic off;
}

# If no error occurs, proceed to the test block
try_files $uri @testblock;
}

location @testblock {
# Instead of proxying to the actual service, we simply return a 200
return 200 "Auth OK\n";
}
}
}

32 changes: 32 additions & 0 deletions airbyte-proxy/nginx-test-auth.conf.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
events {}

http {
server {
listen 8000 default_server;

location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 200M;

auth_basic "Welcome to Airbyte";
auth_basic_user_file /etc/nginx/.htpasswd;

error_page 401 /etc/nginx/401.html;
location ~ (401.html)$ {
alias /etc/nginx/$1;
auth_basic off;
}

# If no error occurs, proceed to the test block
try_files $uri @testblock;
}

location @testblock {
# Instead of proxying to the actual service, we simply return a 200
return 200 "Auth OK\n";
}
}
}

17 changes: 17 additions & 0 deletions airbyte-proxy/nginx-test-no-auth.conf.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
events {}

http {
server {
listen 8002 default_server;

location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 200M;

# Directly return a 200 without checking for credentials
return 200 "No Auth Required\n";
}
}
}
42 changes: 30 additions & 12 deletions airbyte-proxy/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,40 @@

rm /etc/nginx/nginx.conf

if [[ -z "${BASIC_AUTH_USERNAME}" ]]; then
echo "BASIC_AUTH_USERNAME is not set, skipping nginx auth"

TEMPLATE_PATH="/etc/nginx/templates/nginx-no-auth.conf.template"
# Check if PROXY_TEST is set and its value to decide on the template
if [[ -n "${PROXY_TEST}" ]]; then
case "${PROXY_TEST}" in
"AUTH")
echo "Running in test mode with auth"
htpasswd -c -b /etc/nginx/.htpasswd $BASIC_AUTH_USERNAME $BASIC_AUTH_PASSWORD
TEMPLATE_PATH="/etc/nginx/templates/nginx-test-auth.conf.template"
;;
"NEW_AUTH")
echo "Running in test mode with new auth"
htpasswd -c -b /etc/nginx/.htpasswd $BASIC_AUTH_USERNAME $BASIC_AUTH_PASSWORD
TEMPLATE_PATH="/etc/nginx/templates/nginx-test-auth-newpass.conf.template"
;;
"NO_AUTH")
echo "Running in test mode without auth"
TEMPLATE_PATH="/etc/nginx/templates/nginx-test-no-auth.conf.template"
;;
*)
echo "Invalid PROXY_TEST value. Expected AUTH, NEW_AUTH, or NO_AUTH."
exit 1
;;
esac
else
echo "BASIC_AUTH_USERNAME is set, requiring auth for user '$BASIC_AUTH_USERNAME'"

# htpasswd for basic authentication
rm -rf /etc/nginx/.htpasswd
htpasswd -c -b /etc/nginx/.htpasswd $BASIC_AUTH_USERNAME $BASIC_AUTH_PASSWORD

TEMPLATE_PATH="/etc/nginx/templates/nginx-auth.conf.template"
if [[ -z "${BASIC_AUTH_USERNAME}" ]]; then
echo "BASIC_AUTH_USERNAME is not set, using production config without auth"
TEMPLATE_PATH="/etc/nginx/templates/nginx-no-auth.conf.template"
else
echo "BASIC_AUTH_USERNAME is set, using production config with auth for user '$BASIC_AUTH_USERNAME'"
htpasswd -c -b /etc/nginx/.htpasswd $BASIC_AUTH_USERNAME $BASIC_AUTH_PASSWORD
TEMPLATE_PATH="/etc/nginx/templates/nginx-auth.conf.template"
fi
fi

envsubst '${PROXY_PASS_WEB} ${PROXY_PASS_API} ${CONNECTOR_BUILDER_SERVER_API} ${PROXY_PASS_AIRBYTE_API_SERVER} ${PROXY_PASS_RESOLVER} ${BASIC_AUTH_PROXY_TIMEOUT}' < $TEMPLATE_PATH > /etc/nginx/nginx.conf

echo "starting nginx..."
nginx -v
nginx -g "daemon off;"
89 changes: 50 additions & 39 deletions airbyte-proxy/test.sh
Original file line number Diff line number Diff line change
@@ -1,53 +1,61 @@
#!/bin/bash

NAME="airbyte-proxy-test-container"
PORT=18000
BASIC_AUTH_USERNAME=airbyte
BASIC_AUTH_PASSWORD=password
BASIC_AUTH_UPDATED_PASSWORD=pa55w0rd
BASIC_AUTH_PROXY_TIMEOUT=120
TEST_HOST=localhost

if [[ -z "${DAGGER}" ]]; then
# If DAGGER env variable is not set
TEST_HOST_AUTH="localhost"
TEST_HOST_NEWAUTH="localhost"
TEST_HOST_NOAUTH="localhost"
else
# If DAGGER env variable is set, set TEST_HOST based on the test section
# These correspond to the hostnames we spin up in the dagger config
TEST_HOST_AUTH="airbyte-proxy-test-container"
TEST_HOST_NEWAUTH="airbyte-proxy-test-container-newauth"
TEST_HOST_NOAUTH="airbyte-proxy-test-container-noauth"
fi

VERSION="${VERSION:-dev}" # defaults to "dev", otherwise it is set by environment's $VERSION

echo "testing with proxy container airbyte/proxy:$VERSION"

function start_container () {
CMD="docker run -d -p $PORT:8000 --env BASIC_AUTH_USERNAME=$1 --env BASIC_AUTH_PASSWORD=$2 --env BASIC_AUTH_PROXY_TIMEOUT=$3 --env PROXY_PASS_WEB=http://localhost --env PROXY_PASS_API=http://localhost --env CONNECTOR_BUILDER_SERVER_API=http://localhost --env PROXY_PASS_AIRBYTE_API_SERVER=http://localhost --name $NAME airbyte/proxy:$VERSION"
CMD="docker run -d -p $1:8000 --env BASIC_AUTH_USERNAME=$2 --env BASIC_AUTH_PASSWORD=$3 --env BASIC_AUTH_PROXY_TIMEOUT=$4 --env PROXY_PASS_WEB=http://localhost --env PROXY_PASS_API=http://localhost --env CONNECTOR_BUILDER_SERVER_API=http://localhost --env PROXY_PASS_AIRBYTE_API_SERVER=http://localhost --name $NAME-$1 airbyte/proxy:$VERSION"
echo $CMD
eval $CMD
wait_for_docker;
}

function start_container_with_proxy () {
CMD="docker run -d -p $PORT:8000 --env PROXY_PASS_WEB=$1 --env PROXY_PASS_API=$1 --name $NAME
airbyte/proxy:$VERSION"
echo $CMD
eval $CMD
wait_for_docker;
wait_for_docker $NAME-$1;
}

function stop_container () {
echo "Stopping $NAME"
docker kill $NAME
docker rm $NAME
echo "Stopping $1"
docker kill $1
docker rm $1
}

function wait_for_docker() {
until [ "`docker inspect -f {{.State.Running}} $NAME`"=="true" ]; do
until [ "`docker inspect -f {{.State.Running}} $1`"=="true" ]; do
sleep 1;
done;
sleep 1;
}

# If using Dagger in CI, we manage the lifecycle of the containers through that
# and assume they are already up. We also don't care if the service itself is up,
# only that the proxy is working.
# Here we preserve the old way for backwards compatibility
echo "Testing airbyte proxy..."
# Start container with port 8000
if [[ -z "$DAGGER" ]]; then
start_container 8000 $BASIC_AUTH_USERNAME $BASIC_AUTH_PASSWORD $BASIC_AUTH_PROXY_TIMEOUT
fi

stop_container; # just in case there was a failure of a previous test run

echo "Starting $NAME"
start_container $BASIC_AUTH_USERNAME $BASIC_AUTH_PASSWORD $BASIC_AUTH_PROXY_TIMEOUT

# Test on port 8000
echo "Testing access without auth"
RESPONSE=`curl "http://$TEST_HOST:$PORT" -i --silent`
RESPONSE=`curl "http://$TEST_HOST_AUTH:8000" -i -v`
if [[ $RESPONSE == *"401 Unauthorized"* ]]; then
echo "✔️ access without auth blocked"
else
Expand All @@ -57,7 +65,7 @@ else
fi

echo "Testing access with auth"
RESPONSE=`curl "http://$BASIC_AUTH_USERNAME:$BASIC_AUTH_PASSWORD@$TEST_HOST:$PORT" -i --silent`
RESPONSE=`curl "http://$BASIC_AUTH_USERNAME:$BASIC_AUTH_PASSWORD@$TEST_HOST_AUTH:8000" -i -v`
if [[ $RESPONSE != *"401 Unauthorized"* ]]; then
echo "✔️ access with auth worked"
else
Expand All @@ -66,13 +74,15 @@ else
exit 1
fi

stop_container;

echo "Starting $NAME with updated password"
start_container $BASIC_AUTH_USERNAME $BASIC_AUTH_UPDATED_PASSWORD $BASIC_AUTH_PROXY_TIMEOUT
# Start container with updated password on port 8001
if [[ -z "$DAGGER" ]]; then
stop_container $NAME-8000
start_container 8001 $BASIC_AUTH_USERNAME $BASIC_AUTH_UPDATED_PASSWORD $BASIC_AUTH_PROXY_TIMEOUT
fi

echo "Testing access with orignial paassword"
RESPONSE=`curl "http://$BASIC_AUTH_USERNAME:$BASIC_AUTH_PASSWORD@$TEST_HOST:$PORT" -i --silent`
# Test on port 8001
echo "Testing access with original password"
RESPONSE=`curl "http://$BASIC_AUTH_USERNAME:$BASIC_AUTH_PASSWORD@$TEST_HOST_NEWAUTH:8001" -i -v`
if [[ $RESPONSE == *"401 Unauthorized"* ]]; then
echo "✔️ access with original auth blocked"
else
Expand All @@ -82,7 +92,7 @@ else
fi

echo "Testing access updated auth"
RESPONSE=`curl "http://$BASIC_AUTH_USERNAME:$BASIC_AUTH_UPDATED_PASSWORD@$TEST_HOST:$PORT" -i --silent`
RESPONSE=`curl "http://$BASIC_AUTH_USERNAME:$BASIC_AUTH_UPDATED_PASSWORD@$TEST_HOST_NEWAUTH:8001" -i -v`
if [[ $RESPONSE != *"401 Unauthorized"* ]]; then
echo "✔️ access with updated auth worked"
else
Expand All @@ -91,13 +101,15 @@ else
exit 1
fi

stop_container;

echo "Starting $NAME with no password"
start_container "" ""
# Start container with no password on port 8002
if [[ -z "$DAGGER" ]]; then
stop_container $NAME-8001
start_container 8002 "" ""
fi

# Test on port 8002
echo "Testing access without auth"
RESPONSE=`curl "http://$TEST_HOST:$PORT" -i --silent`
RESPONSE=`curl "http://$TEST_HOST_NOAUTH:8002" -i -v`
if [[ $RESPONSE != *"401 Unauthorized"* ]]; then
echo "✔️ access without auth allowed when configured"
else
Expand All @@ -106,8 +118,9 @@ else
exit 1
fi

stop_container;

if [[ -z "$DAGGER" ]]; then
stop_container $NAME-8002
fi

# TODO: We can't test external URLs without a resolver, but adding a resolver that isn't dynamic+local doesn't work with docker.

Expand All @@ -123,7 +136,5 @@ stop_container;
# exit 1
# fi

# stop_container;

echo "Tests Passed ✅"
exit 0
1 change: 1 addition & 0 deletions airbyte-temporal/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
id "io.airbyte.gradle.jvm.lib"
id "io.airbyte.gradle.docker"
id "io.airbyte.gradle.publish"
}

airbyte {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jest.mock("hooks/theme/useAirbyteTheme", () => ({
useAirbyteTheme: () => mockTheme,
}));

jest.setTimeout(20000);
jest.setTimeout(40000);

describe("CreateConnectionForm", () => {
const Wrapper: React.FC<React.PropsWithChildren<unknown>> = ({ children }) => <TestWrapper>{children}</TestWrapper>;
Expand Down
2 changes: 2 additions & 0 deletions airbyte-webapp/src/components/forms/Form.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ const LAST_NAME = {
fieldType: "input",
};

jest.setTimeout(20000);

describe(`${Form.name}`, () => {
it("should call onSubmit upon submission", async () => {
const mockOnSubmit = jest.fn();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jest.mock("services/connector/DestinationDefinitionService", () => ({
useDestinationDefinition: () => mockDestinationDefinition,
}));

jest.setTimeout(20000);
jest.setTimeout(40000);

jest.mock("area/workspace/utils", () => ({
useCurrentWorkspaceId: () => mockWorkspaceId,
Expand Down
Loading

0 comments on commit 2bf5f3f

Please sign in to comment.