26%macro group_scope_compare(desc=);
30 select distinct name into :json_globals separated by
' '
31 from dictionary.macros
32 where scope=
'GLOBAL' and prxmatch(
33 '/^MC(\d{1,6}|LIB\d{1,3})_JAD(P\d+LEN|PNUM|VLEN)$/i',strip(name));
35 %mp_assertscope(COMPARE,ignorelist=&json_globals
36 ,desc=&desc,outds=work.test_results)
37%mend group_scope_compare;
39%macro run_group_fixture_test();
40%local fixture_name1 fixture_name2 fixture_desc1 fixture_desc2
41 fixture_status1 fixture_status2 fixture_valid1 fixture_valid2 mismatch_all
42 mismatch_uid mismatch_raw unknown_user all_fixture1 all_fixture2
43 user_fixture1 user_fixture2 uid_fixture1 uid_fixture2 rawheader rawbody rawlib
44 saved_mode desktop_match;
46%let fixture_name1=%substr(%mf_getuniquename(prefix=g),1,16);
47%let fixture_name2=%substr(%mf_getuniquename(prefix=g),1,16);
48%let fixture_desc1=Getgroups member fixture;
49%let fixture_desc2=Getgroups nonmember fixture;
53%ms_creategroup(&fixture_name1,desc=&fixture_desc1,outds=work.fixture1)
54%let fixture_status1=&SYS_PROCHTTP_STATUS_CODE;
57 call symputx(
'fixture_uid1',uid,
'g');
59%let fixture_valid1=%sysfunc(prxmatch(
60 %str(/^[0-9a-fA-F]{24}$/),%superq(fixture_uid1)));
61%mp_assert(iftrue=(&fixture_status1=200 and &fixture_valid1=1)
62 ,desc=Created member fixture with UID,outds=work.test_results)
63%
if &fixture_status1 ne 200 or &fixture_valid1 ne 1 %then %
return;
65%ms_creategroup(&fixture_name2,desc=&fixture_desc2,outds=work.fixture2)
66%let fixture_status2=&SYS_PROCHTTP_STATUS_CODE;
69 call symputx(
'fixture_uid2',uid,
'g');
71%let fixture_valid2=%sysfunc(prxmatch(
72 %str(/^[0-9a-fA-F]{24}$/),%superq(fixture_uid2)));
73%mp_assert(iftrue=(&fixture_status2=200 and &fixture_valid2=1)
74 ,desc=Created nonmember fixture with UID,outds=work.test_results)
75%
if &fixture_status2 ne 200 or &fixture_valid2 ne 1 %then %
return;
77%ms_adduser2group(uid=&_sasjs_userid,gid=&fixture_uid1,outds=work.members)
78%mp_assert(iftrue=(&SYS_PROCHTTP_STATUS_CODE=200)
79 ,desc=Added current local user to fixture,outds=work.test_results)
80%
if &SYS_PROCHTTP_STATUS_CODE ne 200 %then %
return;
82%mddl_getgroups(work.groupmodel)
84%mp_assertscope(SNAPSHOT)
85%ms_getgroups(outds=work.allgroups,mdebug=&sasjs_mdebug)
86%group_scope_compare(desc=All groups scope)
87%mp_assertmodel(work.allgroups,base=work.groupmodel,key=groupuri
88 ,desc=All groups model and key,outds=work.test_results)
89%mp_assertdsobs(work.allgroups,test=ATLEAST 1
90 ,desc=All groups not empty,outds=work.test_results)
92%mp_assertscope(SNAPSHOT)
93%ms_getgroups(user=%mf_getuser(),outds=work.usergroups)
94%group_scope_compare(desc=User groups scope)
95%mp_assertmodel(work.usergroups,base=work.groupmodel,key=groupuri
96 ,desc=User groups model and key,outds=work.test_results)
98%mp_assertscope(SNAPSHOT)
99%ms_getgroups(uid=&_sasjs_userid,outds=work.uidgroups)
100%group_scope_compare(desc=UID groups scope)
101%mp_assertmodel(work.uidgroups,base=work.groupmodel,key=groupuri
102 ,desc=UID groups model and key,outds=work.test_results)
105 select count(*) into :mismatch_all trimmed
106 from work.usergroups as u left join work.allgroups as a
107 on u.groupuri=a.groupuri
108 where u.groupuri in (
"&fixture_uid1",
"&fixture_uid2")
109 and (missing(a.groupuri) or u.groupname ne a.groupname
110 or u.groupdesc ne a.groupdesc);
111 select count(*) into :mismatch_uid trimmed
112 from work.usergroups as u full join work.uidgroups as g
113 on u.groupuri=g.groupuri
114 where coalesce(u.groupuri,g.groupuri) in (
"&fixture_uid1",
"&fixture_uid2")
115 and (missing(u.groupuri) or missing(g.groupuri)
116 or u.groupname ne g.groupname or u.groupdesc ne g.groupdesc);
118%mp_assert(iftrue=(&mismatch_all=0)
119 ,desc=User groups values match all groups,outds=work.test_results)
120%mp_assert(iftrue=(&mismatch_uid=0)
121 ,desc=Username and UID groups agree,outds=work.test_results)
125 select count(*) into :all_fixture1 trimmed from work.allgroups
126 where groupuri=
"&fixture_uid1" and groupname=
"&fixture_name1"
127 and groupdesc=
"&fixture_desc1";
128 select count(*) into :all_fixture2 trimmed from work.allgroups
129 where groupuri=
"&fixture_uid2" and groupname=
"&fixture_name2"
130 and groupdesc=
"&fixture_desc2";
131 select count(*) into :user_fixture1 trimmed from work.usergroups
132 where groupuri=
"&fixture_uid1" and groupname=
"&fixture_name1"
133 and groupdesc=
"&fixture_desc1";
134 select count(*) into :user_fixture2 trimmed from work.usergroups
135 where groupuri=
"&fixture_uid2";
136 select count(*) into :uid_fixture1 trimmed from work.uidgroups
137 where groupuri=
"&fixture_uid1" and groupname=
"&fixture_name1"
138 and groupdesc=
"&fixture_desc1";
139 select count(*) into :uid_fixture2 trimmed from work.uidgroups
140 where groupuri=
"&fixture_uid2";
142%mp_assert(iftrue=(&all_fixture1=1 and &all_fixture2=1)
143 ,desc=All groups contain exact fixture values,outds=work.test_results)
144%mp_assert(iftrue=(&user_fixture1=1)
145 ,desc=Username groups contain exact member fixture,outds=work.test_results)
146%mp_assert(iftrue=(&user_fixture2=0)
147 ,desc=Username groups exclude nonmember fixture,outds=work.test_results)
148%mp_assert(iftrue=(&uid_fixture1=1)
149 ,desc=UID groups contain exact member fixture,outds=work.test_results)
150%mp_assert(iftrue=(&uid_fixture2=0)
151 ,desc=UID groups exclude nonmember fixture,outds=work.test_results)
155%let unknown_user=%substr(%mf_getuniquename(prefix=u),1,16);
156%mp_assertscope(SNAPSHOT)
157%ms_getgroups(user=&unknown_user,outds=work.nogroups)
158%group_scope_compare(desc=Unknown user scope)
159%mp_assertmodel(work.nogroups,base=work.groupmodel,key=groupuri
160 ,desc=Unknown user model and key,outds=work.test_results)
161%mp_assertdsobs(work.nogroups,test=EMPTY
162 ,desc=Unknown user has no groups,outds=work.test_results)
165%let rawheader=%mf_getuniquefileref();
166%let rawbody=%mf_getuniquefileref();
167%let rawlib=%mf_getuniquelibref();
169 file &rawheader lrecl=1000;
170 infile
"&_sasjs_tokenfile" lrecl=1000;
172 if _n_=1 then put 'accept: application/json';
175proc http method='GET' headerin=&rawheader out=&rawbody
176 url=
"&_sasjs_apiserverurl/SASjsApi/group";
178%mp_assert(iftrue=(&SYS_PROCHTTP_STATUS_CODE=200)
179 ,desc=Independent API status,outds=work.test_results)
180libname &rawlib JSON fileref=&rawbody;
182 select count(*) into :mismatch_raw trimmed
183 from &rawlib..root as r full join work.allgroups as g
185 where coalesce(r.uid,g.groupuri) in (
"&fixture_uid1",
"&fixture_uid2")
186 and (missing(r.uid) or missing(g.groupuri) or r.name ne g.groupname
187 or r.description ne g.groupdesc);
189%mp_assert(iftrue=(&mismatch_raw=0)
190 ,desc=Fixture values match API uid name and description
191 ,outds=work.test_results)
192libname &rawlib clear;
193filename &rawheader clear;
194filename &rawbody clear;
197%let saved_mode=%sysget(MODE);
198options set=MODE 'desktop';
199%mp_assertscope(SNAPSHOT)
200%ms_getgroups(outds=work.desktopgroups)
201%mp_assertscope(COMPARE
202 ,desc=Desktop groups scope,outds=work.test_results)
203options set=MODE
"&saved_mode";
204%mp_assertmodel(work.desktopgroups,base=work.groupmodel,key=groupuri
205 ,desc=Desktop group model and key,outds=work.test_results)
206%mp_assertdsobs(work.desktopgroups,test=EQUALS 1
207 ,desc=Desktop returns one group,outds=work.test_results)
210 set work.desktopgroups;
211 if groupuri=
'1' and groupname=symget('sysuserid') and
212 groupdesc=cats(symget('sysuserid'),' (group - desktop mode)') then
213 call symputx('desktop_match',1);
215%mp_assert(iftrue=(&desktop_match=1)
216 ,desc=Desktop group values,outds=work.test_results)
217%mend run_group_fixture_test;
220%global fixture_uid1 fixture_uid2 _SYSINCLUDEFILEDEVICE;
223%let saved_include_device=%superq(_SYSINCLUDEFILEDEVICE);
224%let saved_syntaxcheck=%sysfunc(getoption(syntaxcheck,keyword));
225%let saved_obs=%sysfunc(getoption(obs,keyword));
226%let saved_replace=%sysfunc(getoption(replace,keyword));
227%let saved_bomfile=%sysfunc(getoption(bomfile,keyword));
228%let saved_fixture_mode=%sysget(MODE);
229%let test_body=%mf_getuniquefileref();
230%let cleanup_header=%mf_getuniquefileref();
231%let cleanup_body=%mf_getuniquefileref();
233 file &cleanup_header lrecl=1000;
234 infile
"&_sasjs_tokenfile" lrecl=1000;
236 if _n_=1 then put 'accept: application/json';
241 put '%run_group_fixture_test()';
243%let _SYSINCLUDEFILEDEVICE=TEMP;
245%let _SYSINCLUDEFILEDEVICE=&saved_include_device;
246options set=MODE
"&saved_fixture_mode";
249%let test_syscc=&syscc;
251options nosyntaxcheck obs=max replace;
253%macro cleanup_group_fixture(uid=,label=);
254 %local valid delete_status verify_status;
256 %let cleanup_syscc=%sysfunc(max(&cleanup_syscc,&syscc));
258 %let valid=%sysfunc(prxmatch(%str(/^[0-9a-fA-F]{24}$/),%superq(uid)));
259 %
if &valid=1 %then %
do;
260 %let SYS_PROCHTTP_STATUS_CODE=0;
261 proc http method=
'DELETE' headerin=&cleanup_header out=&cleanup_body
262 url=
"&_sasjs_apiserverurl/SASjsApi/group/&uid";
264 %let delete_status=&SYS_PROCHTTP_STATUS_CODE;
265 %let cleanup_syscc=%sysfunc(max(&cleanup_syscc,&syscc));
267 %let SYS_PROCHTTP_STATUS_CODE=0;
268 proc http method=
'GET' headerin=&cleanup_header out=&cleanup_body
269 url=
"&_sasjs_apiserverurl/SASjsApi/group/&uid";
271 %let verify_status=&SYS_PROCHTTP_STATUS_CODE;
272 %let cleanup_syscc=%sysfunc(max(&cleanup_syscc,&syscc));
274 %mp_assert(iftrue=(&delete_status=200 and &verify_status=404)
275 ,desc=Deleted and verified &label fixture,outds=work.test_results)
278 %mp_assert(iftrue=(0=1)
279 ,desc=Could not safely clean &label fixture UID,outds=work.test_results)
281%mend cleanup_group_fixture;
282%cleanup_group_fixture(uid=&fixture_uid1,label=member)
283%cleanup_group_fixture(uid=&fixture_uid2,label=nonmember)
284filename &test_body clear;
285filename &cleanup_header clear;
286filename &cleanup_body clear;
287%let cleanup_syscc=%sysfunc(max(&cleanup_syscc,&syscc));
288options &saved_syntaxcheck &saved_obs &saved_replace &saved_bomfile;
289%let syscc=%sysfunc(max(&test_syscc,&cleanup_syscc,&syscc));