diff --git a/src/connection/index.ts b/src/connection/index.ts index 67d4211b..d08c883f 100644 --- a/src/connection/index.ts +++ b/src/connection/index.ts @@ -13,6 +13,7 @@ export default class Connection { public readonly http: HttpClient; constructor(params: ConnectionParams) { + params = this.sanitizeParams(params); this.http = httpClient(params); this.gql = gqlClient(params); this.authEnabled = this.parseAuthParams(params); @@ -35,6 +36,14 @@ export default class Connection { return false; } + private sanitizeParams(params: ConnectionParams) { + while (params.host.endsWith('/')) { + params.host = params.host.slice(0, -1); + } + + return params; + } + post = (path: string, payload: any, expectReturnContent = true) => { if (this.authEnabled) { return this.login().then((token) => diff --git a/src/connection/journey.test.ts b/src/connection/journey.test.ts index 4f6df3d2..599ffec3 100644 --- a/src/connection/journey.test.ts +++ b/src/connection/journey.test.ts @@ -9,6 +9,35 @@ import Connection from './index'; import weaviate from '../index'; describe('connection', () => { + it('makes a logged-in request when client host param has trailing slashes', () => { + if ( + process.env.WCS_DUMMY_CI_PW == undefined || + process.env.WCS_DUMMY_CI_PW == '' + ) { + console.warn('Skipping because `WCS_DUMMY_CI_PW` is not set'); + return; + } + + const client = weaviate.client({ + scheme: 'http', + host: 'localhost:8085/////', + authClientSecret: new AuthUserPasswordCredentials({ + username: 'ms_2d0e007e7136de11d5f29fce7a53dae219a51458@existiert.net', + password: process.env.WCS_DUMMY_CI_PW, + }), + }); + + return client.misc + .metaGetter() + .do() + .then((res: any) => { + expect(res.version).toBeDefined(); + }) + .catch((e: any) => { + throw new Error('it should not have errord: ' + e); + }); + }); + it('makes an Azure logged-in request with client credentials', () => { if ( process.env.AZURE_CLIENT_SECRET == undefined ||