1- import { StartedWeaviateContainer , WeaviateContainer } from '@testcontainers/weaviate' ;
21import weaviate , { ApiKey , Permission , Role , WeaviateClient } from '..' ;
3- import { WeaviateInsufficientPermissionsError , WeaviateUnexpectedStatusCodeError } from '../errors' ;
2+ import {
3+ WeaviateInsufficientPermissionsError ,
4+ WeaviateStartUpError ,
5+ WeaviateUnexpectedStatusCodeError ,
6+ } from '../errors' ;
47import { DbVersion } from '../utils/dbVersion' ;
58
69const only = DbVersion . fromString ( `v${ process . env . WEAVIATE_VERSION ! } ` ) . isAtLeast ( 1 , 28 , 0 )
@@ -9,53 +12,32 @@ const only = DbVersion.fromString(`v${process.env.WEAVIATE_VERSION!}`).isAtLeast
912
1013only ( 'Integration testing of the roles namespace' , ( ) => {
1114 let client : WeaviateClient ;
12- let container : StartedWeaviateContainer ;
1315
1416 beforeAll ( async ( ) => {
15- container = await new WeaviateContainer ( `semitechnologies/weaviate:${ process . env . WEAVIATE_VERSION } ` )
16- . withExposedPorts ( 8080 , 50051 )
17- . withEnvironment ( {
18- AUTHENTICATION_APIKEY_ENABLED : 'true' ,
19- AUTHENTICATION_APIKEY_ALLOWED_KEYS : 'admin-key,custom-key' ,
20- AUTHENTICATION_APIKEY_USERS : 'admin-user,custom-user' ,
21- AUTHORIZATION_ADMIN_USERS : 'admin-user' ,
22- AUTHORIZATION_ENABLE_RBAC : 'true' ,
23- } )
24- . start ( ) ;
25- expect ( container ) . toBeDefined ( ) ;
2617 client = await weaviate . connectToLocal ( {
27- host : container . getHost ( ) ,
28- port : container . getMappedPort ( 8080 ) ,
29- grpcPort : container . getMappedPort ( 50051 ) ,
18+ port : 8091 ,
19+ grpcPort : 50062 ,
3020 authCredentials : new ApiKey ( 'admin-key' ) ,
3121 } ) ;
3222 } ) ;
3323
34- afterAll ( async ( ) => {
35- await container . stop ( ) ;
36- } ) ;
37-
3824 it ( 'should be able to retrieve the default roles' , async ( ) => {
3925 const roles = await client . roles . listAll ( ) ;
4026 expect ( Object . values ( roles ) . length ) . toBeGreaterThan ( 0 ) ;
4127 } ) ;
4228
43- it ( 'should fail with insufficient permissions if no key provided' , async ( ) => {
44- const unauthenticatedClient = await weaviate . connectToLocal ( {
45- host : container . getHost ( ) ,
46- port : container . getMappedPort ( 8080 ) ,
47- grpcPort : container . getMappedPort ( 50051 ) ,
48- } ) ;
49- await expect ( unauthenticatedClient . roles . listAll ( ) ) . rejects . toThrowError (
50- WeaviateInsufficientPermissionsError
51- ) ; // should be unauthenticated error, needs fixing on server
52- } ) ;
29+ it ( 'should fail to start up if no key provided' , ( ) =>
30+ expect (
31+ weaviate . connectToLocal ( {
32+ port : 8091 ,
33+ grpcPort : 50062 ,
34+ } )
35+ ) . rejects . toThrowError ( WeaviateStartUpError ) ) ;
5336
5437 it ( 'should fail with insufficient permissions if permission-less key provided' , async ( ) => {
5538 const unauthenticatedClient = await weaviate . connectToLocal ( {
56- host : container . getHost ( ) ,
57- port : container . getMappedPort ( 8080 ) ,
58- grpcPort : container . getMappedPort ( 50051 ) ,
39+ port : 8091 ,
40+ grpcPort : 50062 ,
5941 authCredentials : new ApiKey ( 'custom-key' ) ,
6042 } ) ;
6143 await expect ( unauthenticatedClient . roles . listAll ( ) ) . rejects . toThrowError (
0 commit comments