11import {
2+ ApiKey ,
23 AuthAccessTokenCredentials ,
34 AuthClientCredentials ,
45 AuthUserPasswordCredentials ,
@@ -151,6 +152,24 @@ describe('connection', () => {
151152 } ) ;
152153 } ) ;
153154
155+ it ( 'makes a logged-in request with API key' , ( ) => {
156+ const client = weaviate . client ( {
157+ scheme : 'http' ,
158+ host : 'localhost:8085' ,
159+ apiKey : new ApiKey ( 'my-secret-key' ) ,
160+ } ) ;
161+
162+ return client . misc
163+ . metaGetter ( )
164+ . do ( )
165+ . then ( ( res : any ) => {
166+ expect ( res . version ) . toBeDefined ( ) ;
167+ } )
168+ . catch ( ( e : any ) => {
169+ throw new Error ( 'it should not have errord: ' + e ) ;
170+ } ) ;
171+ } ) ;
172+
154173 it ( 'makes a logged-in request with access token' , async ( ) => {
155174 if (
156175 process . env . WCS_DUMMY_CI_PW == undefined ||
@@ -172,11 +191,12 @@ describe('connection', () => {
172191 // use it to test AuthAccessTokenCredentials
173192 await dummy . login ( ) ;
174193
194+ const accessToken = ( dummy as any ) . oidcAuth ?. accessToken || '' ;
175195 const client = weaviate . client ( {
176196 scheme : 'http' ,
177197 host : 'localhost:8085' ,
178198 authClientSecret : new AuthAccessTokenCredentials ( {
179- accessToken : dummy . auth . accessToken ,
199+ accessToken : accessToken ,
180200 expiresIn : 900 ,
181201 } ) ,
182202 } ) ;
@@ -213,17 +233,18 @@ describe('connection', () => {
213233 // use it to test AuthAccessTokenCredentials
214234 await dummy . login ( ) ;
215235
236+ const accessToken = ( dummy as any ) . oidcAuth ?. accessToken || '' ;
216237 const conn = new Connection ( {
217238 scheme : 'http' ,
218239 host : 'localhost:8085' ,
219240 authClientSecret : new AuthAccessTokenCredentials ( {
220- accessToken : dummy . auth . accessToken ,
241+ accessToken : accessToken ,
221242 expiresIn : 1 ,
222- refreshToken : dummy . auth . refreshToken ,
243+ refreshToken : ( dummy as any ) . oidcAuth ? .refreshToken ,
223244 } ) ,
224245 } ) ;
225246 // force the use of refreshToken
226- conn . auth . expiresAt = 0 ;
247+ ( conn as any ) . oidcAuth ?. resetExpiresAt ( ) ;
227248
228249 return conn
229250 . login ( )
@@ -293,7 +314,7 @@ describe('connection', () => {
293314 } ) ,
294315 } ) ;
295316 // force the use of refreshToken
296- conn . auth . expiresAt = 0 ;
317+ ( conn as any ) . oidcAuth ?. resetExpiresAt ( ) ;
297318
298319 await conn
299320 . login ( )
@@ -309,4 +330,21 @@ describe('connection', () => {
309330 'AuthAccessTokenCredentials not provided with refreshToken, cannot refresh'
310331 ) ;
311332 } ) ;
333+
334+ it ( 'fails to create client with both OIDC creds and API key set' , ( ) => {
335+ expect ( ( ) => {
336+ // eslint-disable-next-line no-new
337+ new Connection ( {
338+ scheme : 'http' ,
339+ host : 'localhost:8085' ,
340+ authClientSecret : new AuthAccessTokenCredentials ( {
341+ accessToken : 'abcd1234' ,
342+ expiresIn : 1 ,
343+ } ) ,
344+ apiKey : new ApiKey ( 'some-key' ) ,
345+ } ) ;
346+ } ) . toThrow (
347+ 'must provide one of authClientSecret (OIDC) or apiKey, cannot provide both'
348+ ) ;
349+ } ) ;
312350} ) ;
0 commit comments