Loading...
Searching...
No Matches
stagedata.test.3.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief testing stagedata RLS / REPLACE loadtype incompatibility (#211)
4 @details Backend validations should abort when:
5 1. loading row level EDIT security against a table with LOADTYPE=REPLACE
6 2. applying LOADTYPE=REPLACE to a table with row level EDIT security
7
8 The staged loads are aborted by the post edit hooks. The assertion fetches
9 the sasjsAbort object that mp_abort writes to the webout before the hook
10 aborts.
11
12 <h4> SAS Macros </h4>
13 @li mx_execute.sas
14 @li mpe_execute.sas
15 @li mpe_assert_abort.sas
16 @li mp_assert.sas
17
18
19**/
20
21%let _program=&appLoc/services/editors/stagedata;
22
23/**
24 * Prep - register a DCTEST table with REPLACE loadtype (direct insert,
25 * bypassing stagedata) and create the physical table
26 */
27data dctest.dc_replace;
28 x=1;
29run;
30proc sql noprint;
31delete from &dc_libref..mpe_tables where libref="DCTEST" and dsn='DC_REPLACE';
32insert into &dc_libref..mpe_tables
33 set tx_from=0
34 ,tx_to='31DEC5999:23:59:59'dt
35 ,libref="DCTEST"
36 ,dsn='DC_REPLACE'
37 ,buskey='X'
38 ,loadtype='REPLACE'
39 ,num_of_approvals_required=1;
40/* ensure the RLS table's post edit hook is registered (matches the
41 * mpe_makedata registration - some estates were initialised before the
42 * hook existed, which would silently skip the test 1 validation) */
43update &dc_libref..mpe_tables
44 set post_edit_hook='services/hooks/mpe_row_level_security_postedit'
45 where upcase(dsn)='MPE_ROW_LEVEL_SECURITY'
46 and post_edit_hook='';
47/* insert an active EDIT rule for DCTEST.WIDEBOY up front - the child
48 * services run in separate (possibly pooled) compute sessions, so the
49 * rule must be committed to the shared filesystem well before the test
50 * 2 child reads it */
51delete from &dc_libref..mpe_row_level_security
52 where rls_libref="DCTEST" and rls_table='WIDEBOY';
53select coalesce(max(rls_rk),0)+1 into: rlsrk
54 from &dc_libref..mpe_row_level_security;
55insert into &dc_libref..mpe_row_level_security
56 set tx_from=0
57 ,tx_to='31DEC5999:23:59:59'dt
58 ,rls_rk=&rlsrk
59 ,rls_scope='EDIT'
60 ,rls_group='SASAdministrators'
61 ,rls_libref='DCTEST'
62 ,rls_table='WIDEBOY'
63 ,rls_group_logic='AND'
64 ,rls_subgroup_logic='OR'
65 ,rls_subgroup_id=0
66 ,rls_variable_nm='ROW_ID'
67 ,rls_operator_nm='NE'
68 ,rls_raw_value='1'
69 ,rls_active=1;
70quit;
71
72/**
73 * Test 1 - submitting an RLS EDIT rule against a REPLACE table should abort
74 */
75data work.sascontroltable;
76 action='LOAD';
77 message='RLS EDIT rule on REPLACE table should abort';
78 libds="&dc_libref..MPE_ROW_LEVEL_SECURITY";
79 output;
80 stop;
81run;
82
83data work.jsdata;
84 length RLS_SCOPE $8 RLS_GROUP $128 RLS_LIBREF $8 RLS_TABLE $32
85 RLS_GROUP_LOGIC $3 RLS_SUBGROUP_LOGIC $3 RLS_VARIABLE_NM $32
86 RLS_OPERATOR_NM $12 RLS_RAW_VALUE $4000
87 _____DELETE__THIS__RECORD_____ $3;
88 RLS_SCOPE='EDIT';
89 RLS_GROUP='SASAdministrators';
90 RLS_LIBREF='DCTEST';
91 RLS_TABLE='DC_REPLACE';
92 RLS_GROUP_LOGIC='AND';
93 RLS_SUBGROUP_LOGIC='OR';
94 RLS_SUBGROUP_ID=0;
95 RLS_VARIABLE_NM='X';
96 RLS_OPERATOR_NM='NE';
97 RLS_RAW_VALUE='1';
98 RLS_ACTIVE=1;
99 _____DELETE__THIS__RECORD_____='No';
100 output;
101run;
102
103%mpe_execute(&_program,
104 viyacontext=&defaultcontext,
105 inputdatasets=work.sascontroltable work.jsdata,
106 outlib=web1,
107 outref=wb1,
108 outstatus=work.ab1,
109 failfast=0,
110 mdebug=&sasjs_mdebug
111)
112
113%mpe_assert_abort(
114 desc=Checking RLS EDIT rule is rejected for REPLACE loadtype table (#211),
115 outstatus=work.ab1
116)
117
118/**
119 * Test 3 - an RLS rule naming a DERIVED variable must be rejected at save
120 * time: the rule is evaluated against the submitted data, where a derived
121 * column does not exist
122 */
123
124/* define a derived variable on the target table */
125proc sql noprint;
126delete from &dc_libref..mpe_derived
127 where upcase(libref)='DCTEST' and upcase(dsn)='DC_REPLACE';
128insert into &dc_libref..mpe_derived
129 set tx_from=0
130 ,tx_to='31DEC5999:23:59:59'dt
131 ,libref='DCTEST'
132 ,dsn='DC_REPLACE'
133 ,var_nm='DERIVED_X'
134 ,var_deps='X'
135 ,var_type='N'
136 ,var_len=8
137 ,var_fmt=''
138 ,var_logic='X + 1'
139 ,active=1;
140quit;
141
142data work.sascontroltable;
143 action='LOAD';
144 message='RLS rule on a derived variable should abort';
145 libds="&dc_libref..MPE_ROW_LEVEL_SECURITY";
146 output;
147 stop;
148run;
149
150data work.jsdata;
151 length RLS_SCOPE $8 RLS_GROUP $128 RLS_LIBREF $8 RLS_TABLE $32
152 RLS_GROUP_LOGIC $3 RLS_SUBGROUP_LOGIC $3 RLS_VARIABLE_NM $32
153 RLS_OPERATOR_NM $12 RLS_RAW_VALUE $4000
154 _____DELETE__THIS__RECORD_____ $3;
155 RLS_SCOPE='EDIT';
156 RLS_GROUP='SASAdministrators';
157 RLS_LIBREF='DCTEST';
158 RLS_TABLE='DC_REPLACE';
159 RLS_GROUP_LOGIC='AND';
160 RLS_SUBGROUP_LOGIC='OR';
161 RLS_SUBGROUP_ID=0;
162 RLS_VARIABLE_NM='DERIVED_X';
163 RLS_OPERATOR_NM='NE';
164 RLS_RAW_VALUE='1';
165 RLS_ACTIVE=1;
166 _____DELETE__THIS__RECORD_____='No';
167 output;
168run;
169
170%mpe_execute(&_program,
171 viyacontext=&defaultcontext,
172 inputdatasets=work.sascontroltable work.jsdata,
173 outlib=web3,
174 outref=wb3,
175 outstatus=work.ab3,
176 failfast=0,
177 mdebug=&sasjs_mdebug
178)
179
180%mpe_assert_abort(
181 desc=Checking an RLS rule on a derived variable is rejected,
182 outstatus=work.ab3
183)
184
185/* tidy up the derived configuration */
186proc sql noprint;
187delete from &dc_libref..mpe_derived
188 where upcase(libref)='DCTEST' and upcase(dsn)='DC_REPLACE';
189quit;
190
191/**
192 * Test 2 - applying REPLACE loadtype to a table with RLS EDIT security
193 * should abort. The active EDIT rule was inserted in the prep section,
194 * long before this child service reads it.
195 */
196
197/* now stage a REPLACE loadtype for DCTEST.WIDEBOY */
198data work.sascontroltable;
199 action='LOAD';
200 message='REPLACE loadtype on RLS-secured table should abort';
201 libds="&dc_libref..MPE_TABLES";
202 output;
203 stop;
204run;
205
206data work.jsdata;
207 set &dc_libref..mpe_tables(where=(libref='DCTEST' and dsn='WIDEBOY'));
208 loadtype='REPLACE';
209 length _____DELETE__THIS__RECORD_____ $3;
210 _____DELETE__THIS__RECORD_____='No';
211run;
212
213%mpe_execute(&_program,
214 viyacontext=&defaultcontext,
215 inputdatasets=work.sascontroltable work.jsdata,
216 outlib=web2,
217 outref=wb2,
218 outstatus=work.ab2,
219 failfast=0,
220 mdebug=&sasjs_mdebug
221)
222
223%mpe_assert_abort(
224 desc=Checking REPLACE loadtype is rejected for RLS EDIT-secured table (#211),
225 outstatus=work.ab2
226)
227
228/**
229 * Test 3 - sanity check: REPLACE loadtype on an unsecured table is fine
230 */
231data work.jsdata;
232 set &dc_libref..mpe_tables(where=(libref='DCTEST' and dsn='WIDEBOY'));
233 loadtype='UPDATE';
234 length _____DELETE__THIS__RECORD_____ $3;
235 _____DELETE__THIS__RECORD_____='No';
236run;
237
238/* remove the RLS rule first (cleanup of test 2) */
239proc sql noprint;
240delete from &dc_libref..mpe_row_level_security
241 where rls_libref="DCTEST" and rls_table='WIDEBOY';
242quit;
243
244%mx_execute(&_program,
245 viyacontext=&defaultcontext,
246 inputdatasets=work.sascontroltable work.jsdata,
247 outlib=web3,
248 mdebug=&sasjs_mdebug
249)
250
251%let status3=0;
252data _null_;
253 set web3.sasparams;
254 putlog (_all_)(=);
255 if status='SUCCESS' then call symputx('status3',1);
256run;
257
258%mp_assert(
259 iftrue=(&status3=1),
260 desc=Checking non-REPLACE loadtype still stages successfully after cleanup,
261 outds=work.test_results
262)
263
264/* final cleanup - remove the REPLACE table registration */
265proc sql noprint;
266delete from &dc_libref..mpe_tables where libref="DCTEST" and dsn='DC_REPLACE';
267quit;