Skip to content

Commit

Permalink
feat: JS SSL test in integration tests
Browse files Browse the repository at this point in the history
- Fixed utils to support isomorphic-fetch Response
- Added some cleanups

Refs: chroma-core#1604
  • Loading branch information
tazarov committed Feb 9, 2024
1 parent 9b7980c commit 9f03269
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
13 changes: 11 additions & 2 deletions bin/integration-test
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,23 @@ 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"
cd clients/js
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/
3 changes: 2 additions & 1 deletion bin/run_ssl_server.sh
Original file line number Diff line number Diff line change
@@ -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/

Expand Down
4 changes: 2 additions & 2 deletions clients/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@
"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",
"test:runfull-authonly-xtoken": "PORT=8001 XTOKEN_TEST=true jest --runInBand --testPathPattern=test/auth.token.test.ts",
"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",
Expand Down
3 changes: 2 additions & 1 deletion clients/js/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 9f03269

Please sign in to comment.