@@ -6,6 +6,11 @@ import {
66 BUDGET_VIEWER_MFG_HEAD ,
77 BUDGET_VIEWER_KAZOO_PM ,
88 BUDGET_VIEWER_ACCOUNTING_HEAD ,
9+ VIEW_NON_CONFIDENTIAL_BLUEPRINTS ,
10+ VIEW_ALL_BLUEPRINTS ,
11+ BLUEPRINT_VIEWER_ENGINEERING ,
12+ BLUEPRINT_VIEWER_ENGINEERING_ALL ,
13+ BLUEPRINT_VIEWER_MULTI_DEPT ,
914} from './sample-data' ;
1015
1116describe ( 'Multi-dimensional context authorization' , ( ) => {
@@ -138,3 +143,132 @@ describe('Multi-dimensional context authorization', () => {
138143 } ) ;
139144 } ) ;
140145} ) ;
146+
147+ describe ( 'Multi-dimensional IfExists conditions' , ( ) => {
148+ const blueprintFactory = new AuthorizerFactory ( [ VIEW_NON_CONFIDENTIAL_BLUEPRINTS , VIEW_ALL_BLUEPRINTS ] ) ,
149+ mockBlueprint = 'blueprints:a1b2c3d4-e5f6-7890-abcd-ef1234567890' ;
150+
151+ describe ( 'BLUEPRINT_VIEWER_ENGINEERING (non-confidential only via StringDoesNotMatchIfExists)' , ( ) => {
152+ const authorizer = blueprintFactory . makeAuthorizerForSubject ( BLUEPRINT_VIEWER_ENGINEERING ) ;
153+
154+ it ( 'allows viewing engineering blueprint with no classification (field missing)' , ( ) => {
155+ const allowed = authorizer . isAllowed ( 'blueprints:View' , mockBlueprint , {
156+ context : { 'blueprints:OwningDepartment' : 'engineering' } ,
157+ } ) ;
158+
159+ expect ( allowed ) . to . strictlyEqual ( true ) ;
160+ } ) ;
161+
162+ it ( 'allows viewing engineering blueprint classified as public' , ( ) => {
163+ const allowed = authorizer . isAllowed ( 'blueprints:View' , mockBlueprint , {
164+ context : { 'blueprints:OwningDepartment' : 'engineering' , 'blueprints:Classification' : 'public' } ,
165+ } ) ;
166+
167+ expect ( allowed ) . to . strictlyEqual ( true ) ;
168+ } ) ;
169+
170+ it ( 'denies viewing engineering blueprint classified as confidential' , ( ) => {
171+ const allowed = authorizer . isAllowed ( 'blueprints:View' , mockBlueprint , {
172+ context : { 'blueprints:OwningDepartment' : 'engineering' , 'blueprints:Classification' : 'confidential' } ,
173+ } ) ;
174+
175+ expect ( allowed ) . to . strictlyEqual ( false ) ;
176+ } ) ;
177+
178+ it ( 'denies viewing manufacturing blueprint (wrong department)' , ( ) => {
179+ const allowed = authorizer . isAllowed ( 'blueprints:View' , mockBlueprint , {
180+ context : { 'blueprints:OwningDepartment' : 'manufacturing' , 'blueprints:Classification' : 'public' } ,
181+ } ) ;
182+
183+ expect ( allowed ) . to . strictlyEqual ( false ) ;
184+ } ) ;
185+ } ) ;
186+
187+ describe ( 'BLUEPRINT_VIEWER_ENGINEERING_ALL (all blueprints including confidential)' , ( ) => {
188+ const authorizer = blueprintFactory . makeAuthorizerForSubject ( BLUEPRINT_VIEWER_ENGINEERING_ALL ) ;
189+
190+ it ( 'allows viewing engineering blueprint with no classification' , ( ) => {
191+ const allowed = authorizer . isAllowed ( 'blueprints:View' , mockBlueprint , {
192+ context : { 'blueprints:OwningDepartment' : 'engineering' } ,
193+ } ) ;
194+
195+ expect ( allowed ) . to . strictlyEqual ( true ) ;
196+ } ) ;
197+
198+ it ( 'allows viewing engineering blueprint classified as public' , ( ) => {
199+ const allowed = authorizer . isAllowed ( 'blueprints:View' , mockBlueprint , {
200+ context : { 'blueprints:OwningDepartment' : 'engineering' , 'blueprints:Classification' : 'public' } ,
201+ } ) ;
202+
203+ expect ( allowed ) . to . strictlyEqual ( true ) ;
204+ } ) ;
205+
206+ it ( 'allows viewing engineering blueprint classified as confidential' , ( ) => {
207+ const allowed = authorizer . isAllowed ( 'blueprints:View' , mockBlueprint , {
208+ context : { 'blueprints:OwningDepartment' : 'engineering' , 'blueprints:Classification' : 'confidential' } ,
209+ } ) ;
210+
211+ expect ( allowed ) . to . strictlyEqual ( true ) ;
212+ } ) ;
213+
214+ it ( 'denies viewing manufacturing blueprint (wrong department)' , ( ) => {
215+ const allowed = authorizer . isAllowed ( 'blueprints:View' , mockBlueprint , {
216+ context : { 'blueprints:OwningDepartment' : 'manufacturing' , 'blueprints:Classification' : 'public' } ,
217+ } ) ;
218+
219+ expect ( allowed ) . to . strictlyEqual ( false ) ;
220+ } ) ;
221+ } ) ;
222+
223+ describe ( 'BLUEPRINT_VIEWER_MULTI_DEPT (non-confidential across engineering + manufacturing)' , ( ) => {
224+ const authorizer = blueprintFactory . makeAuthorizerForSubject ( BLUEPRINT_VIEWER_MULTI_DEPT ) ;
225+
226+ it ( 'allows viewing engineering blueprint with no classification' , ( ) => {
227+ const allowed = authorizer . isAllowed ( 'blueprints:View' , mockBlueprint , {
228+ context : { 'blueprints:OwningDepartment' : 'engineering' } ,
229+ } ) ;
230+
231+ expect ( allowed ) . to . strictlyEqual ( true ) ;
232+ } ) ;
233+
234+ it ( 'allows viewing manufacturing blueprint with no classification' , ( ) => {
235+ const allowed = authorizer . isAllowed ( 'blueprints:View' , mockBlueprint , {
236+ context : { 'blueprints:OwningDepartment' : 'manufacturing' } ,
237+ } ) ;
238+
239+ expect ( allowed ) . to . strictlyEqual ( true ) ;
240+ } ) ;
241+
242+ it ( 'allows viewing engineering blueprint classified as internal' , ( ) => {
243+ const allowed = authorizer . isAllowed ( 'blueprints:View' , mockBlueprint , {
244+ context : { 'blueprints:OwningDepartment' : 'engineering' , 'blueprints:Classification' : 'internal' } ,
245+ } ) ;
246+
247+ expect ( allowed ) . to . strictlyEqual ( true ) ;
248+ } ) ;
249+
250+ it ( 'denies viewing engineering confidential blueprint' , ( ) => {
251+ const allowed = authorizer . isAllowed ( 'blueprints:View' , mockBlueprint , {
252+ context : { 'blueprints:OwningDepartment' : 'engineering' , 'blueprints:Classification' : 'confidential' } ,
253+ } ) ;
254+
255+ expect ( allowed ) . to . strictlyEqual ( false ) ;
256+ } ) ;
257+
258+ it ( 'denies viewing manufacturing confidential blueprint' , ( ) => {
259+ const allowed = authorizer . isAllowed ( 'blueprints:View' , mockBlueprint , {
260+ context : { 'blueprints:OwningDepartment' : 'manufacturing' , 'blueprints:Classification' : 'confidential' } ,
261+ } ) ;
262+
263+ expect ( allowed ) . to . strictlyEqual ( false ) ;
264+ } ) ;
265+
266+ it ( 'denies viewing HR blueprint (unauthorized department)' , ( ) => {
267+ const allowed = authorizer . isAllowed ( 'blueprints:View' , mockBlueprint , {
268+ context : { 'blueprints:OwningDepartment' : 'hr' , 'blueprints:Classification' : 'public' } ,
269+ } ) ;
270+
271+ expect ( allowed ) . to . strictlyEqual ( false ) ;
272+ } ) ;
273+ } ) ;
274+ } ) ;
0 commit comments