Skip to content

Commit 96d3bb8

Browse files
committed
Improve skipping of auth tests
1 parent 31f8dad commit 96d3bb8

File tree

1 file changed

+61
-78
lines changed

1 file changed

+61
-78
lines changed

src/connection/journey.test.ts

Lines changed: 61 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,38 @@ import Connection from './index.js';
99
import { WeaviateStartUpError } from '../errors.js';
1010
import weaviate from '../index.js';
1111

12-
describe('connection', () => {
13-
it('makes a logged-in request when client host param has trailing slashes', async () => {
14-
if (process.env.WCS_DUMMY_CI_PW == undefined || process.env.WCS_DUMMY_CI_PW == '') {
15-
console.warn('Skipping because `WCS_DUMMY_CI_PW` is not set');
16-
return Promise.resolve();
17-
}
18-
19-
const client = await weaviate.connectToLocal({
20-
port: 8085,
21-
authCredentials: new AuthUserPasswordCredentials({
22-
username: '[email protected]',
23-
password: process.env.WCS_DUMMY_CI_PW,
24-
silentRefresh: false,
25-
}),
26-
});
12+
const check = (cred?: string) => {
13+
if (cred == undefined || cred == '') {
14+
console.warn('Skipping because `WCS_DUMMY_CI_PW` is not set');
15+
return it.skip;
16+
} else {
17+
return it;
18+
}
19+
};
2720

28-
return client
29-
.getMeta()
30-
.then((res) => {
31-
expect(res.version).toBeDefined();
32-
})
33-
.catch((e) => {
34-
throw new Error('it should not have errord: ' + e);
21+
describe('connection', () => {
22+
check(process.env.WCS_DUMMY_CI_PW)(
23+
'makes a logged-in request when client host param has trailing slashes',
24+
async () => {
25+
const client = await weaviate.connectToLocal({
26+
port: 8085,
27+
authCredentials: new AuthUserPasswordCredentials({
28+
username: '[email protected]',
29+
password: process.env.WCS_DUMMY_CI_PW,
30+
silentRefresh: false,
31+
}),
3532
});
36-
});
33+
34+
return client
35+
.getMeta()
36+
.then((res) => {
37+
expect(res.version).toBeDefined();
38+
})
39+
.catch((e) => {
40+
throw new Error('it should not have errord: ' + e);
41+
});
42+
}
43+
);
3744

3845
// it('makes an Azure logged-in request with client credentials', async () => {
3946
// if (process.env.AZURE_CLIENT_SECRET == undefined || process.env.AZURE_CLIENT_SECRET == '') {
@@ -59,37 +66,30 @@ describe('connection', () => {
5966
// });
6067
// });
6168

62-
it('makes an Okta logged-in request with client credentials', async () => {
63-
if (process.env.OKTA_CLIENT_SECRET == undefined || process.env.OKTA_CLIENT_SECRET == '') {
64-
console.warn('Skipping because `OKTA_CLIENT_SECRET` is not set');
65-
return Promise.resolve();
66-
}
67-
68-
const client = await weaviate.connectToLocal({
69-
port: 8082,
70-
authCredentials: new AuthClientCredentials({
71-
clientSecret: process.env.OKTA_CLIENT_SECRET,
72-
scopes: ['some_scope'],
73-
silentRefresh: false,
74-
}),
75-
});
76-
77-
return client
78-
.getMeta()
79-
.then((res) => {
80-
expect(res.version).toBeDefined();
81-
})
82-
.catch((e) => {
83-
throw new Error('it should not have errord: ' + e);
69+
check(process.env.OKTA_CLIENT_SECRET)(
70+
'makes an Okta logged-in request with client credentials',
71+
async () => {
72+
const client = await weaviate.connectToLocal({
73+
port: 8082,
74+
authCredentials: new AuthClientCredentials({
75+
clientSecret: process.env.OKTA_CLIENT_SECRET!,
76+
scopes: ['some_scope'],
77+
silentRefresh: false,
78+
}),
8479
});
85-
});
8680

87-
it('makes an Okta logged-in request with username/password', async () => {
88-
if (process.env.OKTA_DUMMY_CI_PW == undefined || process.env.OKTA_DUMMY_CI_PW == '') {
89-
console.warn('Skipping because `OKTA_DUMMY_CI_PW` is not set');
90-
return Promise.resolve();
81+
return client
82+
.getMeta()
83+
.then((res) => {
84+
expect(res.version).toBeDefined();
85+
})
86+
.catch((e) => {
87+
throw new Error('it should not have errord: ' + e);
88+
});
9189
}
90+
);
9291

92+
check(process.env.OKTA_DUMMY_CI_PW)('makes an Okta logged-in request with username/password', async () => {
9393
const client = await weaviate.connectToLocal({
9494
port: 8083,
9595
authCredentials: new AuthUserPasswordCredentials({
@@ -109,12 +109,7 @@ describe('connection', () => {
109109
});
110110
});
111111

112-
it('makes a WCS logged-in request with username/password', async () => {
113-
if (process.env.WCS_DUMMY_CI_PW == undefined || process.env.WCS_DUMMY_CI_PW == '') {
114-
console.warn('Skipping because `WCS_DUMMY_CI_PW` is not set');
115-
return Promise.resolve();
116-
}
117-
112+
check(process.env.WCS_DUMMY_CI_PW)('makes a WCS logged-in request with username/password', async () => {
118113
const client = await weaviate.connectToLocal({
119114
port: 8085,
120115
authCredentials: new AuthUserPasswordCredentials({
@@ -168,12 +163,7 @@ describe('connection', () => {
168163
});
169164
});
170165

171-
it('makes a logged-in request with access token', async () => {
172-
if (process.env.WCS_DUMMY_CI_PW == undefined || process.env.WCS_DUMMY_CI_PW == '') {
173-
console.warn('Skipping because `WCS_DUMMY_CI_PW` is not set');
174-
return;
175-
}
176-
166+
check(process.env.WCS_DUMMY_CI_PW)('makes a logged-in request with access token', async () => {
177167
const dummy = new Connection({
178168
scheme: 'http',
179169
host: 'localhost:8085',
@@ -208,12 +198,7 @@ describe('connection', () => {
208198
});
209199
});
210200

211-
it('uses refresh token to fetch new access token', async () => {
212-
if (process.env.WCS_DUMMY_CI_PW == undefined || process.env.WCS_DUMMY_CI_PW == '') {
213-
console.warn('Skipping because `WCS_DUMMY_CI_PW` is not set');
214-
return;
215-
}
216-
201+
check(process.env.WCS_DUMMY_CI_PW)('uses refresh token to fetch new access token', async () => {
217202
const dummy = new Connection({
218203
scheme: 'http',
219204
host: 'localhost:8085',
@@ -240,16 +225,14 @@ describe('connection', () => {
240225
// force the use of refreshToken
241226
(conn as any).oidcAuth?.resetExpiresAt();
242227

243-
return conn
244-
.login()
245-
.then((resp) => {
246-
expect(resp).toBeDefined();
247-
expect(resp != '').toBeTruthy();
248-
conn.oidcAuth?.stopTokenRefresh();
249-
})
250-
.catch((e: any) => {
251-
throw new Error('it should not have errord: ' + e);
252-
});
228+
return conn.login().then((resp) => {
229+
expect(resp).toBeDefined();
230+
expect(resp != '').toBeTruthy();
231+
conn.oidcAuth?.stopTokenRefresh();
232+
});
233+
// .catch((e: any) => {
234+
// throw new Error('it should not have errord: ' + e);
235+
// });
253236
});
254237

255238
it('fails to access auth-enabled server without client auth', async () => {

0 commit comments

Comments
 (0)