@@ -2572,6 +2572,7 @@ const addAbacAttributesToUserDirectly = async (userId: string, abacAttributes: I
25722572 describe ( '[Admin Rooms - Announcement] (ABAC managed rooms)' , ( ) => {
25732573 const announceKey = `attr_announce_${ Date . now ( ) } ` ;
25742574 const createdRids : string [ ] = [ ] ;
2575+ let announceAttrId : string ;
25752576 let owner : IUser ;
25762577 let ownerCredentials : Credentials ;
25772578
@@ -2589,18 +2590,6 @@ const addAbacAttributesToUserDirectly = async (userId: string, abacAttributes: I
25892590 return { rid : created . _id , name } ;
25902591 } ;
25912592
2592- const assignAbacAttribute = async ( rid : string ) : Promise < void > => {
2593- await request
2594- . post ( `${ v1 } /abac/rooms/${ rid } /attributes/${ announceKey } ` )
2595- . set ( credentials )
2596- . send ( { values : [ 'v1' ] } )
2597- . expect ( 200 ) ;
2598- } ;
2599-
2600- const removeAllAbacAttributes = async ( rid : string ) : Promise < void > => {
2601- await request . delete ( `${ v1 } /abac/rooms/${ rid } /attributes` ) . set ( credentials ) . expect ( 200 ) ;
2602- } ;
2603-
26042593 before ( async ( ) => {
26052594 await updateSetting ( 'ABAC_Enabled' , true ) ;
26062595
@@ -2610,25 +2599,28 @@ const addAbacAttributesToUserDirectly = async (userId: string, abacAttributes: I
26102599 . send ( { key : announceKey , values : [ 'v1' ] } )
26112600 . expect ( 200 ) ;
26122601
2602+ const listRes = await request . get ( `${ v1 } /abac/attributes` ) . query ( { key : announceKey } ) . set ( credentials ) . expect ( 200 ) ;
2603+ const attr = listRes . body . attributes . find ( ( a : { _id : string ; key : string } ) => a . key === announceKey ) ;
2604+ expect ( attr , 'attribute should have been created' ) . to . exist ;
2605+ announceAttrId = attr . _id ;
2606+
26132607 owner = await createUser ( ) ;
26142608 ownerCredentials = await login ( owner . username , password ) ;
26152609 } ) ;
26162610
26172611 after ( async ( ) => {
26182612 await Promise . all ( createdRids . map ( ( rid ) => deleteRoom ( { type : 'p' , roomId : rid } ) ) ) ;
2619-
2620- const listRes = await request . get ( `${ v1 } /abac/attributes` ) . query ( { key : announceKey } ) . set ( credentials ) . expect ( 200 ) ;
2621- const attr = listRes . body . attributes . find ( ( a : { _id : string ; key : string } ) => a . key === announceKey ) ;
2622- if ( attr ) {
2623- await request . delete ( `${ v1 } /abac/attributes/${ attr . _id } ` ) . set ( credentials ) . expect ( 200 ) ;
2624- }
2625-
2613+ await request . delete ( `${ v1 } /abac/attributes/${ announceAttrId } ` ) . set ( credentials ) . expect ( 200 ) ;
26262614 await deleteUser ( owner ) ;
26272615 } ) ;
26282616
26292617 it ( 'should strip announcement from rooms.adminRooms.getRoom on ABAC managed room' , async ( ) => {
26302618 const { rid } = await createPrivateRoomWithAnnouncement ( 'SECRET' ) ;
2631- await assignAbacAttribute ( rid ) ;
2619+ await request
2620+ . post ( `${ v1 } /abac/rooms/${ rid } /attributes/${ announceKey } ` )
2621+ . set ( credentials )
2622+ . send ( { values : [ 'v1' ] } )
2623+ . expect ( 200 ) ;
26322624
26332625 const res = await request . get ( `${ v1 } /rooms.adminRooms.getRoom` ) . set ( credentials ) . query ( { rid } ) . expect ( 200 ) ;
26342626
@@ -2645,7 +2637,11 @@ const addAbacAttributesToUserDirectly = async (userId: string, abacAttributes: I
26452637
26462638 it ( 'should strip announcement from rooms.adminRooms list on ABAC managed rows' , async ( ) => {
26472639 const { rid, name } = await createPrivateRoomWithAnnouncement ( 'LIST_SECRET' ) ;
2648- await assignAbacAttribute ( rid ) ;
2640+ await request
2641+ . post ( `${ v1 } /abac/rooms/${ rid } /attributes/${ announceKey } ` )
2642+ . set ( credentials )
2643+ . send ( { values : [ 'v1' ] } )
2644+ . expect ( 200 ) ;
26492645
26502646 const res = await request . get ( `${ v1 } /rooms.adminRooms` ) . set ( credentials ) . query ( { 'filter' : name , 'types[]' : 'p' } ) . expect ( 200 ) ;
26512647
@@ -2656,7 +2652,11 @@ const addAbacAttributesToUserDirectly = async (userId: string, abacAttributes: I
26562652
26572653 it ( 'should reject roomAnnouncement save on ABAC managed room (admin)' , async ( ) => {
26582654 const { rid } = await createPrivateRoomWithAnnouncement ( 'original' ) ;
2659- await assignAbacAttribute ( rid ) ;
2655+ await request
2656+ . post ( `${ v1 } /abac/rooms/${ rid } /attributes/${ announceKey } ` )
2657+ . set ( credentials )
2658+ . send ( { values : [ 'v1' ] } )
2659+ . expect ( 200 ) ;
26602660
26612661 const res = await request
26622662 . post ( `${ v1 } /rooms.saveRoomSettings` )
@@ -2673,7 +2673,11 @@ const addAbacAttributesToUserDirectly = async (userId: string, abacAttributes: I
26732673 await request . post ( `${ v1 } /groups.invite` ) . set ( credentials ) . send ( { roomId : rid , userId : owner . _id } ) . expect ( 200 ) ;
26742674 await request . post ( `${ v1 } /groups.addOwner` ) . set ( credentials ) . send ( { roomId : rid , userId : owner . _id } ) . expect ( 200 ) ;
26752675
2676- await assignAbacAttribute ( rid ) ;
2676+ await request
2677+ . post ( `${ v1 } /abac/rooms/${ rid } /attributes/${ announceKey } ` )
2678+ . set ( credentials )
2679+ . send ( { values : [ 'v1' ] } )
2680+ . expect ( 200 ) ;
26772681
26782682 const res = await request
26792683 . post ( `${ v1 } /rooms.saveRoomSettings` )
@@ -2686,7 +2690,11 @@ const addAbacAttributesToUserDirectly = async (userId: string, abacAttributes: I
26862690
26872691 it ( 'should accept idempotent roomAnnouncement re-submit on ABAC managed room' , async ( ) => {
26882692 const { rid } = await createPrivateRoomWithAnnouncement ( 'keep-me' ) ;
2689- await assignAbacAttribute ( rid ) ;
2693+ await request
2694+ . post ( `${ v1 } /abac/rooms/${ rid } /attributes/${ announceKey } ` )
2695+ . set ( credentials )
2696+ . send ( { values : [ 'v1' ] } )
2697+ . expect ( 200 ) ;
26902698
26912699 await request . post ( `${ v1 } /rooms.saveRoomSettings` ) . set ( credentials ) . send ( { rid, roomAnnouncement : 'keep-me' } ) . expect ( 200 ) ;
26922700 } ) ;
@@ -2699,14 +2707,22 @@ const addAbacAttributesToUserDirectly = async (userId: string, abacAttributes: I
26992707
27002708 it ( 'should accept roomTopic save on ABAC managed room (control — only announcement is blocked)' , async ( ) => {
27012709 const { rid } = await createPrivateRoomWithAnnouncement ( undefined ) ;
2702- await assignAbacAttribute ( rid ) ;
2710+ await request
2711+ . post ( `${ v1 } /abac/rooms/${ rid } /attributes/${ announceKey } ` )
2712+ . set ( credentials )
2713+ . send ( { values : [ 'v1' ] } )
2714+ . expect ( 200 ) ;
27032715
27042716 await request . post ( `${ v1 } /rooms.saveRoomSettings` ) . set ( credentials ) . send ( { rid, roomTopic : 'new topic' } ) . expect ( 200 ) ;
27052717 } ) ;
27062718
27072719 it ( 'should reject empty-string unset on ABAC managed room with announcement set' , async ( ) => {
27082720 const { rid } = await createPrivateRoomWithAnnouncement ( 'X' ) ;
2709- await assignAbacAttribute ( rid ) ;
2721+ await request
2722+ . post ( `${ v1 } /abac/rooms/${ rid } /attributes/${ announceKey } ` )
2723+ . set ( credentials )
2724+ . send ( { values : [ 'v1' ] } )
2725+ . expect ( 200 ) ;
27102726
27112727 const res = await request . post ( `${ v1 } /rooms.saveRoomSettings` ) . set ( credentials ) . send ( { rid, roomAnnouncement : '' } ) . expect ( 400 ) ;
27122728
@@ -2715,22 +2731,26 @@ const addAbacAttributesToUserDirectly = async (userId: string, abacAttributes: I
27152731
27162732 it ( 'should accept idempotent empty submit on ABAC room with no announcement set (direct API contract)' , async ( ) => {
27172733 const { rid } = await createPrivateRoomWithAnnouncement ( undefined ) ;
2718- await assignAbacAttribute ( rid ) ;
2734+ await request
2735+ . post ( `${ v1 } /abac/rooms/${ rid } /attributes/${ announceKey } ` )
2736+ . set ( credentials )
2737+ . send ( { values : [ 'v1' ] } )
2738+ . expect ( 200 ) ;
27192739
2720- // Form path cannot reach this state — field is hidden and never registered.
2721- // This test locks the server-side `?? ''` normalization for direct API callers.
27222740 await request . post ( `${ v1 } /rooms.saveRoomSettings` ) . set ( credentials ) . send ( { rid, roomAnnouncement : '' } ) . expect ( 200 ) ;
27232741 } ) ;
27242742
27252743 it ( 'should accept roomAnnouncement save after the last ABAC attribute is removed (transition)' , async ( ) => {
27262744 const { rid } = await createPrivateRoomWithAnnouncement ( 'initial' ) ;
2727- await assignAbacAttribute ( rid ) ;
2745+ await request
2746+ . post ( `${ v1 } /abac/rooms/${ rid } /attributes/${ announceKey } ` )
2747+ . set ( credentials )
2748+ . send ( { values : [ 'v1' ] } )
2749+ . expect ( 200 ) ;
27282750
2729- // Sanity: room is currently ABAC-managed and the save is rejected.
27302751 await request . post ( `${ v1 } /rooms.saveRoomSettings` ) . set ( credentials ) . send ( { rid, roomAnnouncement : 'changed' } ) . expect ( 400 ) ;
27312752
2732- // Remove the last attribute, room is no longer ABAC-managed.
2733- await removeAllAbacAttributes ( rid ) ;
2753+ await request . delete ( `${ v1 } /abac/rooms/${ rid } /attributes` ) . set ( credentials ) . expect ( 200 ) ;
27342754
27352755 await request . post ( `${ v1 } /rooms.saveRoomSettings` ) . set ( credentials ) . send ( { rid, roomAnnouncement : 'changed' } ) . expect ( 200 ) ;
27362756 } ) ;
0 commit comments