Loading...
Searching...
No Matches
getcols.test.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief testing getcols service - input validation (security)
4 @details The libds in the IWANT input table must be a well-formed
5 LIBREF.DATASET. An invalid value aborts the service before it
6 reaches proc contents. The abort shows up as a canceled child job
7 (an aborted service registers no webout).
8
9 The payload in test 1 resolves to a REAL table when the request
10 content is executed as macro code, so on a vulnerable service the
11 job completes, and only the validating service cancels it - the
12 assertion cannot pass against a service that does not validate.
13
14 <h4> SAS Macros </h4>
15 @li mp_assert.sas
16 @li mx_execute.sas
17 @li mf_getuniquefileref.sas
18
19**/
20
21%let _program=&appLoc/services/public/getcols;
22
23/**
24 * Test 1 - macro content in libds must abort the service
25 */
26%let f1=%mf_getuniquefileref();
27data _null_;
28 file &f1 termstr=crlf;
29 put 'LIBDS:$41.';
30 put '%sysfunc(coalescec(&dclib..MPE_X_TEST,))';
31run;
32
33%mx_execute(&_program,
34 viyacontext=&defaultcontext,
35 inputfiles=&f1:iwant,
36 outref=web1,
37 viyaresult=WEBOUT_TXT
38)
39
40%let abort1=0;
41data _null_;
42 set work.results;
43 if state='canceled' then call symputx('abort1',1);
44run;
45
46%mp_assert(
47 iftrue=(&abort1=1),
48 desc=Macro content in libds aborts the service,
49 outds=work.test_results
50)
51
52/**
53 * Test 2 - valid libds still returns columns
54 */
55%let f2=%mf_getuniquefileref();
56data _null_;
57 file &f2 termstr=crlf;
58 put 'LIBDS:$41.';
59 put "&dclib..MPE_X_TEST";
60run;
61
62%mx_execute(&_program,
63 viyacontext=&defaultcontext,
64 inputfiles=&f2:iwant,
65 outlib=web2
66)
67
68%let nobs=0;
69%let nbad=0;
70proc sql noprint;
71select count(*) into: nobs from web2.cols;
72/**
73 * The service keeps the SAS vocabulary this public contract has always used:
74 * TYPE is C/N, and DDTYPE separates the date and time types. The client maps
75 * TYPE to its own num/char vocabulary in sas-store.getCols, so a change here
76 * that silently switched vocabulary would not be caught by the client suite.
77 * Every column must be C or N, and the two must agree with ddtype.
78 */
79select count(*) into: nbad from web2.cols
80 where type not in ('C','N')
81 or (ddtype='C' and type ne 'C')
82 or (ddtype in ('N','DATE','DATETIME','TIME') and type ne 'N');
83quit;
84
85%mp_assert(
86 iftrue=(&nobs>0),
87 desc=Valid libds returns columns,
88 outds=work.test_results
89)
90
91%mp_assert(
92 iftrue=(&nbad=0),
93 desc=%str(TYPE stays in the SAS C/N vocabulary and agrees with ddtype),
94 outds=work.test_results
95)
96
97/**
98 * dump results to the log for offline inspection
99 */
100data _null_;
101 set work.test_results;
102 putlog 'TEST_RESULT_LINE: ' test_result ' - ' test_description;
103run;