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 <h4> SAS Macros </h4>
9 @li mx_testservice.sas
10 @li mp_assert.sas
11
12
13**/
14
15%let _program=&appLoc/services/editors/stagedata;
16
17/**
18 * Prep - register a DCTEST table with REPLACE loadtype (direct insert,
19 * bypassing stagedata) and create the physical table
20 */
21data dctest.dc_replace;
22 x=1;
23run;
24proc sql noprint;
25delete from &dc_libref..mpe_tables where libref="DCTEST" and dsn='DC_REPLACE';
26insert into &dc_libref..mpe_tables
27 set tx_from=0
28 ,tx_to='31DEC5999:23:59:59'dt
29 ,libref="DCTEST"
30 ,dsn='DC_REPLACE'
31 ,buskey='X'
32 ,loadtype='REPLACE'
33 ,num_of_approvals_required=1;
34quit;
35
36/**
37 * Test 1 - submitting an RLS EDIT rule against a REPLACE table should abort
38 */
39data work.sascontroltable;
40 action='LOAD';
41 message='RLS EDIT rule on REPLACE table should abort';
42 libds="&dc_libref..MPE_ROW_LEVEL_SECURITY";
43 output;
44 stop;
45run;
46
47data work.jsdata;
48 length RLS_SCOPE $8 RLS_GROUP $128 RLS_LIBREF $8 RLS_TABLE $32
49 RLS_GROUP_LOGIC $3 RLS_SUBGROUP_LOGIC $3 RLS_VARIABLE_NM $32
50 RLS_OPERATOR_NM $12 RLS_RAW_VALUE $4000
51 _____DELETE__THIS__RECORD_____ $3;
52 RLS_SCOPE='EDIT';
53 RLS_GROUP='SASAdministrators';
54 RLS_LIBREF='DCTEST';
55 RLS_TABLE='DC_REPLACE';
56 RLS_GROUP_LOGIC='AND';
57 RLS_SUBGROUP_LOGIC='OR';
58 RLS_SUBGROUP_ID=0;
59 RLS_VARIABLE_NM='X';
60 RLS_OPERATOR_NM='NE';
61 RLS_RAW_VALUE='1';
62 RLS_ACTIVE=1;
63 _____DELETE__THIS__RECORD_____='No';
64 output;
65run;
66
67%mx_testservice(&_program,
68 viyacontext=&defaultcontext,
69 inputdatasets=work.sascontroltable work.jsdata,
70 outlib=web1,
71 outref=wb1,
72 mdebug=&sasjs_mdebug
73)
74
75/* search terms may span multiple lines, so track matches across records */
76%let abort1=0;
77data _null_;
78 retain foundabort foundmsg 0;
79 infile wb1;
80 input;
81 putlog _infile_;
82 if index(_infile_,'sasjsAbort') then foundabort=1;
83 if index(_infile_,'REPLACE loadtype') then foundmsg=1;
84 if foundabort=1 and foundmsg=1 then call symputx('abort1',1);
85run;
86
87%mp_assert(
88 iftrue=(&abort1=1),
89 desc=Checking RLS EDIT rule is rejected for REPLACE loadtype table (#211),
90 outds=work.test_results
91)
92
93/**
94 * Test 2 - applying REPLACE loadtype to a table with RLS EDIT security
95 * should abort. First insert an active EDIT rule directly.
96 */
97proc sql noprint;
98delete from &dc_libref..mpe_row_level_security
99 where rls_libref="DCTEST" and rls_table='WIDEBOY';
100select coalesce(max(rls_rk),0)+1 into: rlsrk
101 from &dc_libref..mpe_row_level_security;
102insert into &dc_libref..mpe_row_level_security
103 set tx_from=0
104 ,tx_to='31DEC5999:23:59:59'dt
105 ,rls_rk=&rlsrk
106 ,rls_scope='EDIT'
107 ,rls_group='SASAdministrators'
108 ,rls_libref='DCTEST'
109 ,rls_table='WIDEBOY'
110 ,rls_group_logic='AND'
111 ,rls_subgroup_logic='OR'
112 ,rls_subgroup_id=0
113 ,rls_variable_nm='ROW_ID'
114 ,rls_operator_nm='NE'
115 ,rls_raw_value='1'
116 ,rls_active=1;
117quit;
118
119/* now stage a REPLACE loadtype for DCTEST.WIDEBOY */
120data work.sascontroltable;
121 action='LOAD';
122 message='REPLACE loadtype on RLS-secured table should abort';
123 libds="&dc_libref..MPE_TABLES";
124 output;
125 stop;
126run;
127
128data work.jsdata;
129 set &dc_libref..mpe_tables(where=(libref='DCTEST' and dsn='WIDEBOY'));
130 loadtype='REPLACE';
131 length _____DELETE__THIS__RECORD_____ $3;
132 _____DELETE__THIS__RECORD_____='No';
133run;
134
135%mx_testservice(&_program,
136 viyacontext=&defaultcontext,
137 inputdatasets=work.sascontroltable work.jsdata,
138 outlib=web2,
139 outref=wb2,
140 mdebug=&sasjs_mdebug
141)
142
143%let abort2=0;
144data _null_;
145 retain foundabort foundmsg 0;
146 infile wb2;
147 input;
148 putlog _infile_;
149 if index(_infile_,'sasjsAbort') then foundabort=1;
150 if index(_infile_,'EDIT security') then foundmsg=1;
151 if foundabort=1 and foundmsg=1 then call symputx('abort2',1);
152run;
153
154%mp_assert(
155 iftrue=(&abort2=1),
156 desc=Checking REPLACE loadtype is rejected for RLS EDIT-secured table (#211),
157 outds=work.test_results
158)
159
160/**
161 * Test 3 - sanity check: REPLACE loadtype on an unsecured table is fine
162 */
163data work.jsdata;
164 set &dc_libref..mpe_tables(where=(libref='DCTEST' and dsn='WIDEBOY'));
165 loadtype='UPDATE';
166 length _____DELETE__THIS__RECORD_____ $3;
167 _____DELETE__THIS__RECORD_____='No';
168run;
169
170/* remove the RLS rule first (cleanup of test 2) */
171proc sql noprint;
172delete from &dc_libref..mpe_row_level_security
173 where rls_libref="DCTEST" and rls_table='WIDEBOY';
174quit;
175
176%mx_testservice(&_program,
177 viyacontext=&defaultcontext,
178 inputdatasets=work.sascontroltable work.jsdata,
179 outlib=web3,
180 mdebug=&sasjs_mdebug
181)
182
183%let status3=0;
184data _null_;
185 set web3.sasparams;
186 putlog (_all_)(=);
187 if status='SUCCESS' then call symputx('status3',1);
188run;
189
190%mp_assert(
191 iftrue=(&status3=1),
192 desc=Checking non-REPLACE loadtype still stages successfully after cleanup,
193 outds=work.test_results
194)
195
196/* final cleanup - remove the REPLACE table registration */
197proc sql noprint;
198delete from &dc_libref..mpe_tables where libref="DCTEST" and dsn='DC_REPLACE';
199quit;