@@ -1550,7 +1550,6 @@ const addAbacAttributesToUserDirectly = async (userId: string, abacAttributes: I
15501550 it ( 'INVITE: after room loses attributes user without attributes can be invited' , async ( ) => {
15511551 await request . delete ( `${ v1 } /abac/rooms/${ roomWithAttr . _id } /attributes/${ accessAttrKey } ` ) . set ( credentials ) . expect ( 200 ) ;
15521552
1553- // Try inviting again - should now succeed
15541553 await request
15551554 . post ( `${ v1 } /groups.invite` )
15561555 . set ( credentials )
@@ -1560,6 +1559,82 @@ const addAbacAttributesToUserDirectly = async (userId: string, abacAttributes: I
15601559 expect ( res . body ) . to . have . property ( 'success' , true ) ;
15611560 } ) ;
15621561 } ) ;
1562+
1563+ describe ( 'ABAC disabled with ABAC-managed room' , ( ) => {
1564+ let enabledAccessAttrKey : string ;
1565+ let enabledUser : IUser ;
1566+ let managedRoom : IRoom ;
1567+
1568+ before ( async ( ) => {
1569+ enabledAccessAttrKey = `${ accessAttrKey } _disabled_case` ;
1570+
1571+ await request
1572+ . post ( `${ v1 } /abac/attributes` )
1573+ . set ( credentials )
1574+ . send ( { key : enabledAccessAttrKey , values : [ 'v1' ] } )
1575+ . expect ( 200 ) ;
1576+
1577+ await addAbacAttributesToUserDirectly ( credentials [ 'X-User-Id' ] , [ { key : enabledAccessAttrKey , values : [ 'v1' ] } ] ) ;
1578+
1579+ managedRoom = ( await createRoom ( { type : 'p' , name : `abac-access-disabled-${ Date . now ( ) } ` } ) ) . body . group ;
1580+
1581+ await request
1582+ . post ( `${ v1 } /abac/rooms/${ managedRoom . _id } /attributes/${ enabledAccessAttrKey } ` )
1583+ . set ( credentials )
1584+ . send ( { values : [ 'v1' ] } )
1585+ . expect ( 200 ) ;
1586+
1587+ const username = `abac-enabled-user-${ Date . now ( ) } ` ;
1588+ const createUserRes = await request
1589+ . post ( `${ v1 } /users.create` )
1590+ . set ( credentials )
1591+ . send ( {
1592+ email : `${ username } @example.com` ,
1593+ name : username ,
1594+ username,
1595+ password : 'pass@123' ,
1596+ } )
1597+ . expect ( 200 ) ;
1598+
1599+ enabledUser = createUserRes . body . user ;
1600+ await addAbacAttributesToUserDirectly ( enabledUser . _id , [ { key : enabledAccessAttrKey , values : [ 'v1' ] } ] ) ;
1601+
1602+ await updateSetting ( 'ABAC_Enabled' , false ) ;
1603+ } ) ;
1604+
1605+ after ( async ( ) => {
1606+ await updateSetting ( 'ABAC_Enabled' , true ) ;
1607+
1608+ await deleteRoom ( { type : 'p' , roomId : managedRoom . _id } ) ;
1609+ await deleteUser ( enabledUser ) ;
1610+ } ) ;
1611+
1612+ it ( 'INVITE: should fail adding user to ABAC-managed private room when ABAC is disabled' , async ( ) => {
1613+ await request
1614+ . post ( `${ v1 } /groups.invite` )
1615+ . set ( credentials )
1616+ . send ( { roomId : managedRoom . _id , usernames : [ enabledUser . username ] } )
1617+ . expect ( 400 )
1618+ . expect ( ( res ) => {
1619+ expect ( res . body ) . to . have . property ( 'success' , false ) ;
1620+ expect ( res . body ) . to . have . property ( 'errorType' , 'error-room-is-abac-managed' ) ;
1621+ } ) ;
1622+ } ) ;
1623+
1624+ it ( 'INVITE: should still fail after user loses attributes when ABAC is disabled' , async ( ) => {
1625+ await addAbacAttributesToUserDirectly ( enabledUser . _id , [ { key : enabledAccessAttrKey , values : [ ] } ] ) ;
1626+
1627+ await request
1628+ . post ( `${ v1 } /groups.invite` )
1629+ . set ( credentials )
1630+ . send ( { roomId : managedRoom . _id , usernames : [ enabledUser . username ] } )
1631+ . expect ( 400 )
1632+ . expect ( ( res ) => {
1633+ expect ( res . body ) . to . have . property ( 'success' , false ) ;
1634+ expect ( res . body ) . to . have . property ( 'errorType' , 'error-room-is-abac-managed' ) ;
1635+ } ) ;
1636+ } ) ;
1637+ } ) ;
15631638 } ) ;
15641639
15651640 describe ( 'Room access (after subscribed)' , ( ) => {
0 commit comments