Loading...
Searching...
No Matches
stagedata.test.5.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief testing that an RLS rule may use a truncated comparison
4
5 @details The Row Level Security post edit hook validates every submitted
6 rule by running it through mp_filtercheck against the target table.
7
8 Test 1 - a rule using `=:` ("starts with") on a character column must be
9 accepted, so that the operator can be selected in the dropdown and saved.
10
11 Test 2 - the same operator on a numeric column must be rejected, because a
12 truncated comparison has no numeric form: SQL rejects the operand outright,
13 so the rule could never be applied.
14
15 Staging does not write the control table, so no rule is left behind.
16
17 <h4> SAS Macros </h4>
18 @li mpe_execute.sas
19 @li mpe_assert_abort.sas
20 @li mp_assert.sas
21
22 @sasjslint {"maxLineLength": 81}
23
24**/
25
26%let _program=&appLoc/services/editors/stagedata;
27
28/**
29 * Test 1 - a truncated comparison on a character column is accepted
30 */
31data work.sascontroltable;
32 action='LOAD';
33 message='RLS rule with =: on a character column should be accepted';
34 libds="&dc_libref..MPE_ROW_LEVEL_SECURITY";
35 output;
36 stop;
37run;
38
39data work.jsdata;
40 length RLS_SCOPE $8 RLS_GROUP $128 RLS_LIBREF $8 RLS_TABLE $32
41 RLS_GROUP_LOGIC $3 RLS_SUBGROUP_LOGIC $3 RLS_VARIABLE_NM $32
42 RLS_OPERATOR_NM $12 RLS_RAW_VALUE $4000
43 _____DELETE__THIS__RECORD_____ $3;
44 RLS_SCOPE='VIEW';
45 RLS_GROUP='dc_starts_with_test';
46 RLS_LIBREF="&dc_libref";
47 RLS_TABLE='MPE_X_TEST';
48 RLS_GROUP_LOGIC='AND';
49 RLS_SUBGROUP_LOGIC='OR';
50 RLS_SUBGROUP_ID=0;
51 RLS_VARIABLE_NM='SOME_DROPDOWN';
52 RLS_OPERATOR_NM='=:';
53 RLS_RAW_VALUE="'Option 1'";
54 RLS_ACTIVE=1;
55 _____DELETE__THIS__RECORD_____='No';
56 output;
57 stop;
58run;
59
60%mpe_execute(&_program,
61 viyacontext=&defaultcontext,
62 inputdatasets=work.sascontroltable work.jsdata,
63 outlib=web1,
64 outref=wb1,
65 outstatus=work.ab1,
66 failfast=0,
67 mdebug=&sasjs_mdebug
68)
69
70%let accepted=0;
71data _null_;
72 if not exist('work.ab1') then stop;
73 set work.ab1;
74 if state='completed' then call symputx('accepted',1);
75run;
76%mp_assert(iftrue=(&accepted=1),
77 desc=Checking an RLS rule with =: on a character column is accepted,
78 outds=work.test_results
79)
80
81/**
82 * Test 2 - the same operator on a numeric column is rejected, and the
83 * rejection names the operator and the column
84 */
85data work.sascontroltable;
86 action='LOAD';
87 message='RLS rule with =: on a numeric column should abort';
88 libds="&dc_libref..MPE_ROW_LEVEL_SECURITY";
89 output;
90 stop;
91run;
92
93data work.jsdata;
94 length RLS_SCOPE $8 RLS_GROUP $128 RLS_LIBREF $8 RLS_TABLE $32
95 RLS_GROUP_LOGIC $3 RLS_SUBGROUP_LOGIC $3 RLS_VARIABLE_NM $32
96 RLS_OPERATOR_NM $12 RLS_RAW_VALUE $4000
97 _____DELETE__THIS__RECORD_____ $3;
98 RLS_SCOPE='VIEW';
99 RLS_GROUP='dc_starts_with_test';
100 RLS_LIBREF="&dc_libref";
101 RLS_TABLE='MPE_X_TEST';
102 RLS_GROUP_LOGIC='AND';
103 RLS_SUBGROUP_LOGIC='OR';
104 RLS_SUBGROUP_ID=0;
105 RLS_VARIABLE_NM='SOME_BESTNUM';
106 RLS_OPERATOR_NM='=:';
107 RLS_RAW_VALUE="'12'";
108 RLS_ACTIVE=1;
109 _____DELETE__THIS__RECORD_____='No';
110 output;
111 stop;
112run;
113
114%mpe_execute(&_program,
115 viyacontext=&defaultcontext,
116 inputdatasets=work.sascontroltable work.jsdata,
117 outlib=web2,
118 outref=wb2,
119 outstatus=work.ab2,
120 failfast=0,
121 mdebug=&sasjs_mdebug
122)
123
124%mpe_assert_abort(
125 desc=Checking an RLS rule with =: on a numeric column aborts,
126 outstatus=work.ab2
127)
128
129%let reject_msg=0;
130data _null_;
131 set work.ab2;
132 /* both halves of the message: the operator, and the column the rule names */
133 if index(errmsg,'=: is only valid for character variables')>0
134 and index(errmsg,'MPE_X_TEST.SOME_BESTNUM is numeric')>0
135 then call symputx('reject_msg',1);
136run;
137%mp_assert(iftrue=(&reject_msg=1),
138 desc=Checking the numeric rejection names the operator and the column,
139 outds=work.test_results
140)