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 mpe_assert_abort.sas
16 @li mp_assert.sas
17 @li mpe_execute.sas
18 @li mf_getuniquefileref.sas
19
20**/
21
22%let _program=&appLoc/services/public/getcols;
23
24/**
25 * Test 1 - macro content in libds must abort the service
26 */
27%let f1=%mf_getuniquefileref();
28data _null_;
29 file &f1 termstr=crlf;
30 put 'LIBDS:$41.';
31 put '%sysfunc(coalescec(&dclib..MPE_X_TEST,))';
32run;
33
34%mpe_execute(&_program,
35 viyacontext=&defaultcontext,
36 inputfiles=&f1:iwant,
37 outref=web1,
38 outstatus=work.ab1,
39 failfast=0,
40 viyaresult=WEBOUT_TXT
41)
42
43%mpe_assert_abort(
44 desc=Macro content in libds aborts the service,
45 outstatus=work.ab1,
46 msg=Invalid libds
47)
48
49/**
50 * Test 2 - valid libds still returns columns
51 */
52%let f2=%mf_getuniquefileref();
53data _null_;
54 file &f2 termstr=crlf;
55 put 'LIBDS:$41.';
56 put "&dclib..MPE_X_TEST";
57run;
58
59%mpe_execute(&_program,
60 viyacontext=&defaultcontext,
61 inputfiles=&f2:iwant,
62 outlib=web2
63)
64
65%let nobs=0;
66%let nbad=0;
67proc sql noprint;
68select count(*) into: nobs from web2.cols;
69/**
70 * The service keeps the SAS vocabulary this public contract has always used:
71 * TYPE is C/N, and DDTYPE separates the date and time types. The client maps
72 * TYPE to its own num/char vocabulary in sas-store.getCols, so a change here
73 * that silently switched vocabulary would not be caught by the client suite.
74 * Every column must be C or N, and the two must agree with ddtype.
75 */
76select count(*) into: nbad from web2.cols
77 where type not in ('C','N')
78 or (ddtype='C' and type ne 'C')
79 or (ddtype in ('N','DATE','DATETIME','TIME') and type ne 'N');
80quit;
81
82%mp_assert(
83 iftrue=(&nobs>0),
84 desc=Valid libds returns columns,
85 outds=work.test_results
86)
87
88%mp_assert(
89 iftrue=(&nbad=0),
90 desc=%str(TYPE stays in the SAS C/N vocabulary and agrees with ddtype),
91 outds=work.test_results
92)
93
94/**
95 * dump results to the log for offline inspection
96 */
97data _null_;
98 set work.test_results;
99 putlog 'TEST_RESULT_LINE: ' test_result ' - ' test_description;
100run;