From 9f03269800fa30ed2b91a35528717bfd8b1e5cd2 Mon Sep 17 00:00:00 2001 From: Trayan Azarov Date: Wed, 7 Feb 2024 18:00:46 +0200 Subject: [PATCH] feat: JS SSL test in integration tests - Fixed utils to support isomorphic-fetch Response - Added some cleanups Refs: #1604 --- bin/integration-test | 13 +++++++++++-- bin/run_ssl_server.sh | 3 ++- clients/js/package.json | 4 ++-- clients/js/src/utils.ts | 3 ++- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/bin/integration-test b/bin/integration-test index 3a1b1bb2a07..c36c28984f2 100755 --- a/bin/integration-test +++ b/bin/integration-test @@ -62,8 +62,8 @@ cd clients/js npm install npm run test:run -docker compose down cd ../.. +docker compose -f docker-compose.test.yml down for auth_type in basic token xtoken; do echo "Testing $auth_type auth" setup_auth "$auth_type" @@ -71,5 +71,14 @@ for auth_type in basic token xtoken; do docker compose --env-file ../../.chroma_env -f ../../docker-compose.test-auth.yml up --build -d yarn test:run-auth-"$auth_type" cd ../.. - docker compose down + docker compose -f docker-compose.test-auth.yml down done + +docker compose down +sh bin/run_ssl_server.sh +cd clients/js +npm run test:run-ssl +cd ../.. +docker compose down +# clean certs created by run_ssl_server.sh +rm -rf certs/ \ No newline at end of file diff --git a/bin/run_ssl_server.sh b/bin/run_ssl_server.sh index 6be870776e4..ec91e60451d 100644 --- a/bin/run_ssl_server.sh +++ b/bin/run_ssl_server.sh @@ -1,7 +1,8 @@ #!/usr/bin/env sh -./bin/generate_self_signed_cert.sh +sh ./bin/generate_self_signed_cert.sh +rm -rf certs mkdir certs mv *.pem certs/ diff --git a/clients/js/package.json b/clients/js/package.json index a89d5f375ac..8128d784cd0 100644 --- a/clients/js/package.json +++ b/clients/js/package.json @@ -51,7 +51,7 @@ "test:run-auth-basic": "jest --runInBand --testPathPattern=test/auth.basic.test.ts", "test:run-auth-token": "jest --runInBand --testPathPattern=test/auth.token.test.ts", "test:run-auth-xtoken": "XTOKEN_TEST=true jest --runInBand --testPathPattern=test/auth.token.test.ts", - "test:runfull": "PORT=8001 jest --runInBand --testPathIgnorePatterns=test/auth.*.test.ts", + "test:runfull": "PORT=8001 jest --runInBand --testPathIgnorePatterns=test/auth.*.test.ts --testPathIgnorePatterns=test/ssl.*.test.ts", "test:runfull-authonly": "run-s db:run-auth-basic test:runfull-authonly-basic db:clean db:run-auth-token test:runfull-authonly-token db:clean db:run-auth-xtoken test:runfull-authonly-xtoken db:clean", "test:runfull-authonly-basic": "PORT=8001 jest --runInBand --testPathPattern=test/auth.basic.test.ts", "test:runfull-authonly-token": "PORT=8001 jest --runInBand --testPathPattern=test/auth.token.test.ts", @@ -59,7 +59,7 @@ "test:update": "run-s db:clean db:run && jest --runInBand --updateSnapshot && run-s db:clean", "db:clean": "cd ../.. && CHROMA_PORT=8001 docker-compose -f docker-compose.test.yml down --volumes", "db:cleanauth": "cd ../.. && CHROMA_PORT=8001 docker-compose -f docker-compose.test-auth.yml down --volumes", - "db:cleanssl": "cd ../.. && CHROMA_PORT=8443 docker-compose down --volumes", + "db:cleanssl": "cd ../.. && CHROMA_PORT=8443 docker-compose down --volumes && rm -rf certs/", "db:run": "cd ../.. && CHROMA_PORT=8001 docker-compose -f docker-compose.test.yml up --detach && sleep 5", "db:run-auth-basic": "cd ../.. && docker run --rm --entrypoint htpasswd httpd:2 -Bbn admin admin > server.htpasswd && echo \"CHROMA_SERVER_AUTH_CREDENTIALS_FILE=/chroma/server.htpasswd\\nCHROMA_SERVER_AUTH_CREDENTIALS_PROVIDER=chromadb.auth.providers.HtpasswdFileServerAuthCredentialsProvider\\nCHROMA_SERVER_AUTH_PROVIDER=chromadb.auth.basic.BasicAuthServerProvider\\nCHROMA_PORT=8001\" > .chroma_env && docker-compose -f docker-compose.test-auth.yml --env-file ./.chroma_env up --detach && sleep 5", "db:run-auth-token": "cd ../.. && echo \"CHROMA_SERVER_AUTH_CREDENTIALS=test-token\nCHROMA_SERVER_AUTH_CREDENTIALS_PROVIDER=chromadb.auth.token.TokenConfigServerAuthCredentialsProvider\nCHROMA_SERVER_AUTH_PROVIDER=chromadb.auth.token.TokenAuthServerProvider\\nCHROMA_PORT=8001\" > .chroma_env && docker-compose -f docker-compose.test-auth.yml --env-file ./.chroma_env up --detach && sleep 5", diff --git a/clients/js/src/utils.ts b/clients/js/src/utils.ts index e3ad5361e61..57cb12146d7 100644 --- a/clients/js/src/utils.ts +++ b/clients/js/src/utils.ts @@ -37,7 +37,8 @@ export function repack(value: unknown): any { } export async function handleError(error: unknown) { - if (error instanceof Response) { + // @ts-ignore + if (error instanceof Response || (error && typeof error === 'object' && error.constructor && error.constructor.name === "Response")) { try { const res = await (error as Response).json(); if ("error" in res) {