Loading...
Searching...
No Matches
loadfile.test.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief testing loadfile with values that hold a quote character
4 @details An uploaded CSV is a user's file, so a value such as `'N/A'` is
5 ordinary data and the quotes are part of it - the same row submitted
6 through the EDIT screen (stagedata) keeps them. SAS list input with the
7 dsd option does not: a field that starts with a quote character is read as
8 a quoted field and the quotes are removed, so the row reached the RLS post
9 edit hook as `N/A` and was rejected as an invalid filter.
10
11 Both rows below carry the encoding the client writes for such a value: the
12 value is wrapped in double quotes and any double quote inside it is
13 doubled. The payload is built from the expected values so the assertion
14 cannot drift from what is sent.
15
16 <h4> SAS Macros </h4>
17 @li mf_getuniquefileref.sas
18 @li mpe_execute.sas
19 @li mp_assert.sas
20
21 @sasjslint {"maxLineLength": 80}
22
23**/
24
25%let _program=&appLoc/services/editors/loadfile;
26
27/**
28 * the values to stage, and the CSV encoding the client writes for them
29 */
30
31data work.want;
32 length rls_raw_value $200 enc $400;
33 dq=byte(34);
34 /* a single quoted value, and a quoted literal holding a double quote */
35 rls_raw_value="'N/A'";
36 enc=dq!!tranwrd(rls_raw_value,dq,dq!!dq)!!dq;
37 output;
38 rls_raw_value="'he said "!!dq!!"hi"!!dq!!"'";
39 enc=dq!!tranwrd(rls_raw_value,dq,dq!!dq)!!dq;
40 output;
41run;
42
43%let f1=%mf_getuniquefileref();
44data _null_;
45 file &f1 termstr=crlf lrecl=32767;
46 length line $600;
47 if _n_=1 then put
48 '_____DELETE__THIS__RECORD_____,RLS_SCOPE,RLS_GROUP,RLS_LIBREF,'
49 'RLS_TABLE,RLS_GROUP_LOGIC,RLS_SUBGROUP_LOGIC,RLS_SUBGROUP_ID,'
50 'RLS_VARIABLE_NM,RLS_OPERATOR_NM,RLS_RAW_VALUE,RLS_ACTIVE';
51 set work.want;
52 line=cats(",ALL,dcviewers,&dclib,MPE_SECURITY,AND,OR,0,ACCESS_LEVEL,NE,"
53 ,enc,",1");
54 put line;
55run;
56
57data work.lf_params;
58 length name $32 value $1000;
59 name='table';
60 value=cats("&dclib..MPE_ROW_LEVEL_SECURITY");
61 output;
62run;
63
64%mpe_execute(&_program,
65 viyacontext=&defaultcontext,
66 inputfiles=&f1:test,
67 inputparams=work.lf_params,
68 outlib=web1,
69 outstatus=work.child1,
70 failfast=0
71)
72
73%let state=;
74%let childmsg=;
75data _null_;
76 set work.child1;
77 call symputx('state',state);
78 call symputx('childmsg',errmsg);
79 putlog state= errmsg=;
80run;
81
82%mp_assert(
83 iftrue=("%upcase(&state)"="COMPLETED"),
84 desc=Checking loadfile completes with values holding a quote character,
85 outds=work.test_results
86)
87
88/* the staged values are what the approver sees - read the changeset itself */
89%macro read_staged();
90 %let dsid=;
91 %if %sysfunc(exist(web1.sasparams)) %then %do;
92 data _null_;
93 set web1.sasparams;
94 call symputx('dsid',dsid);
95 run;
96 %end;
97 %if %length(&dsid)>0 %then %do;
98 libname lfappr "&dc_staging_area/&dsid";
99 proc sql noprint;
100 select count(*) into: staged
101 from lfappr.&dsid
102 where rls_variable_nm='ACCESS_LEVEL'
103 and rls_raw_value in (select rls_raw_value from work.want);
104 quit;
105 data _null_;
106 set lfappr.&dsid(where=(rls_variable_nm='ACCESS_LEVEL'));
107 putlog (_all_)(=);
108 run;
109 libname lfappr clear;
110 %end;
111%mend read_staged;
112
113%let staged=0;
114%read_staged()
115
116%mp_assert(
117 iftrue=(&staged=2),
118 desc=Checking both staged RLS_RAW_VALUEs hold their quote characters,
119 outds=work.test_results
120)