Skip to content

Commit 564ffb8

Browse files
sanitize connection params (#29)
1 parent 52f12a2 commit 564ffb8

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/connection/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export default class Connection {
1313
public readonly http: HttpClient;
1414

1515
constructor(params: ConnectionParams) {
16+
params = this.sanitizeParams(params);
1617
this.http = httpClient(params);
1718
this.gql = gqlClient(params);
1819
this.authEnabled = this.parseAuthParams(params);
@@ -35,6 +36,14 @@ export default class Connection {
3536
return false;
3637
}
3738

39+
private sanitizeParams(params: ConnectionParams) {
40+
while (params.host.endsWith('/')) {
41+
params.host = params.host.slice(0, -1);
42+
}
43+
44+
return params;
45+
}
46+
3847
post = (path: string, payload: any, expectReturnContent = true) => {
3948
if (this.authEnabled) {
4049
return this.login().then((token) =>

src/connection/journey.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,35 @@ import Connection from './index';
99
import weaviate from '../index';
1010

1111
describe('connection', () => {
12+
it('makes a logged-in request when client host param has trailing slashes', () => {
13+
if (
14+
process.env.WCS_DUMMY_CI_PW == undefined ||
15+
process.env.WCS_DUMMY_CI_PW == ''
16+
) {
17+
console.warn('Skipping because `WCS_DUMMY_CI_PW` is not set');
18+
return;
19+
}
20+
21+
const client = weaviate.client({
22+
scheme: 'http',
23+
host: 'localhost:8085/////',
24+
authClientSecret: new AuthUserPasswordCredentials({
25+
username: 'ms_2d0e007e7136de11d5f29fce7a53dae219a51458@existiert.net',
26+
password: process.env.WCS_DUMMY_CI_PW,
27+
}),
28+
});
29+
30+
return client.misc
31+
.metaGetter()
32+
.do()
33+
.then((res: any) => {
34+
expect(res.version).toBeDefined();
35+
})
36+
.catch((e: any) => {
37+
throw new Error('it should not have errord: ' + e);
38+
});
39+
});
40+
1241
it('makes an Azure logged-in request with client credentials', () => {
1342
if (
1443
process.env.AZURE_CLIENT_SECRET == undefined ||

0 commit comments

Comments
 (0)