@@ -72,7 +72,14 @@ function assertJsonValid($json, $message) {
7272assertTrue (strpos ($ settings ->logout , '?site_token= ' ) === false , 'logout v1 path has no query token ' );
7373assertTrue (strpos ($ settings ->systemApiBasePath , '?user_token= ' ) === false , 'systemApiBasePath has no query token ' );
7474$ existingReferer = isset ($ _SERVER ['HTTP_REFERER ' ]) ? $ _SERVER ['HTTP_REFERER ' ] : null ;
75- $ existingRequestUri = isset ($ _SERVER ['REQUEST_URI ' ]) ? $ _SERVER ['REQUEST_URI ' ] : null ;
75+ $ existingRequestUri = isset ($ _SERVER ['REQUEST_URI ' ]) ? $ _SERVER ['REQUEST_URI ' ] : null ;
76+ $ existingAuthHeader = isset ($ _SERVER ['HTTP_AUTHORIZATION ' ]) ? $ _SERVER ['HTTP_AUTHORIZATION ' ] : null ;
77+ $ existingRefreshCookie = isset ($ _COOKIE ['haxcms_refresh_token ' ]) ? $ _COOKIE ['haxcms_refresh_token ' ] : null ;
78+ $ existingSessionJwt = isset ($ HAXCMS ->sessionJwt ) ? $ HAXCMS ->sessionJwt : null ;
79+ $ existingIamSetting = isset ($ HAXCMS ->config ->iam ) ? $ HAXCMS ->config ->iam : null ;
80+ $ existingUserName = isset ($ HAXCMS ->user ->name ) ? $ HAXCMS ->user ->name : null ;
81+ $ existingUserPassword = isset ($ HAXCMS ->user ->password ) ? $ HAXCMS ->user ->password : null ;
82+ $ existingServerSoftware = isset ($ _SERVER ['SERVER_SOFTWARE ' ]) ? $ _SERVER ['SERVER_SOFTWARE ' ] : null ;
7683$ _SERVER ['REQUEST_URI ' ] = '/ ' ;
7784$ _SERVER ['HTTP_REFERER ' ] = 'https://example.com/ ' ;
7885$ dashboardRefererSettings = $ HAXCMS ->appJWTConnectionSettings ();
@@ -108,6 +115,51 @@ function assertJsonValid($json, $message) {
108115 assertTrue (strpos ($ siteRefererSettings ->logout , '/ ' ) === 0 , 'site-context logout path is root-absolute at root install ' );
109116 assertTrue (strpos ($ siteRefererSettings ->systemApiBasePath , '/ ' ) === 0 , 'site-context systemApiBasePath is root-absolute at root install ' );
110117}
118+ $ HAXCMS ->config ->iam = true ;
119+ $ HAXCMS ->user ->name = null ;
120+ $ HAXCMS ->user ->password = null ;
121+ $ _SERVER ['SERVER_SOFTWARE ' ] = 'TestServer ' ;
122+ $ HAXCMS ->addEventListener ('haxcms-validate-user ' , function (&$ usr ) {
123+ if (isset ($ usr ->name ) && $ usr ->name === 'tenant-user ' ) {
124+ $ usr ->grantAccess = true ;
125+ }
126+ });
127+ $ tenantJwt = $ HAXCMS ->getJWT ('tenant-user ' );
128+ $ _SERVER ['HTTP_AUTHORIZATION ' ] = 'Bearer ' . $ tenantJwt ;
129+ $ _COOKIE ['haxcms_refresh_token ' ] = $ HAXCMS ->getRefreshToken ('tenant-user ' );
130+ $ HAXCMS ->sessionJwt = $ tenantJwt ;
131+ $ _SERVER ['REQUEST_URI ' ] = '/tenant-user/system/api/v1/sites ' ;
132+ $ _SERVER ['HTTP_REFERER ' ] = 'https://example.com/tenant-user/ ' ;
133+ $ iamActiveUser = $ HAXCMS ->getActiveUserName ();
134+ $ legacyIamUserToken = $ HAXCMS ->getRequestToken ($ iamActiveUser );
135+ assertTrue (
136+ !$ HAXCMS ->validateRequestToken ($ legacyIamUserToken , $ iamActiveUser ),
137+ 'IAM token mismatch: active-user token is invalid when authenticated tenant differs '
138+ );
139+ $ requestTokenUser = $ HAXCMS ->getRequestTokenUserName ();
140+ $ requestScopedToken = $ HAXCMS ->getRequestToken ($ requestTokenUser );
141+ assertTrue (
142+ $ HAXCMS ->validateRequestToken ($ requestScopedToken , $ iamActiveUser ),
143+ 'IAM token match: request-token user token validates for legacy active-user value '
144+ );
145+ $ lifecycleHandler = include $ repoRoot . '/system/backend/php/lib/systemRoutes/v1/lifecycle.php ' ;
146+ $ lifecycleContext = new stdClass ();
147+ $ lifecycleContext ->apiBasePath = '/tenant-user/system/api ' ;
148+ $ lifecycleContext ->body = array ();
149+ $ lifecycleContext ->params = array ();
150+ $ lifecycleContext ->routeSuffix = 'v1/sites ' ;
151+ $ lifecycleContext ->method = 'GET ' ;
152+ ob_start ();
153+ $ lifecycleHandler ($ lifecycleContext );
154+ $ iamSitesResponseRaw = ob_get_clean ();
155+ $ iamSitesResponse = json_decode ($ iamSitesResponseRaw , true );
156+ assertTrue (is_array ($ iamSitesResponse ), 'IAM lifecycle listSites returns JSON ' );
157+ assertEquals (
158+ 200 ,
159+ isset ($ iamSitesResponse ['status ' ]) ? $ iamSitesResponse ['status ' ] : null ,
160+ 'IAM lifecycle listSites returns 200 with request-scoped token user '
161+ );
162+ $ HAXCMS ->addEventListener ('haxcms-validate-user ' , false );
111163if ($ existingReferer !== null ) {
112164 $ _SERVER ['HTTP_REFERER ' ] = $ existingReferer ;
113165}
@@ -120,6 +172,38 @@ function assertJsonValid($json, $message) {
120172else {
121173 unset($ _SERVER ['REQUEST_URI ' ]);
122174}
175+ if ($ existingAuthHeader !== null ) {
176+ $ _SERVER ['HTTP_AUTHORIZATION ' ] = $ existingAuthHeader ;
177+ }
178+ else {
179+ unset($ _SERVER ['HTTP_AUTHORIZATION ' ]);
180+ }
181+ if ($ existingRefreshCookie !== null ) {
182+ $ _COOKIE ['haxcms_refresh_token ' ] = $ existingRefreshCookie ;
183+ }
184+ else {
185+ unset($ _COOKIE ['haxcms_refresh_token ' ]);
186+ }
187+ if ($ existingSessionJwt !== null ) {
188+ $ HAXCMS ->sessionJwt = $ existingSessionJwt ;
189+ }
190+ else {
191+ $ HAXCMS ->sessionJwt = null ;
192+ }
193+ if ($ existingIamSetting !== null ) {
194+ $ HAXCMS ->config ->iam = $ existingIamSetting ;
195+ }
196+ else {
197+ unset($ HAXCMS ->config ->iam );
198+ }
199+ $ HAXCMS ->user ->name = $ existingUserName ;
200+ $ HAXCMS ->user ->password = $ existingUserPassword ;
201+ if ($ existingServerSoftware !== null ) {
202+ $ _SERVER ['SERVER_SOFTWARE ' ] = $ existingServerSoftware ;
203+ }
204+ else {
205+ unset($ _SERVER ['SERVER_SOFTWARE ' ]);
206+ }
123207
124208// Test 3: SystemApiRouter file existence and route map
125209echo "[3/13] SystemApiRouter route map... \n" ;
@@ -161,7 +245,11 @@ function assertJsonValid($json, $message) {
161245assertEquals ('admin ' , $ getRouteSecurity ->invoke (null , 'v1/configuration/api-keys ' , 'GET ' ), 'v1/configuration/api-keys is admin ' );
162246assertEquals ('admin ' , $ getRouteSecurity ->invoke (null , 'v1/blocks ' , 'GET ' ), 'v1/blocks is admin ' );
163247assertEquals ('authenticated ' , $ getRouteSecurity ->invoke (null , 'v1/sites ' , 'GET ' ), 'v1/sites is authenticated ' );
164- assertEquals ('admin ' , $ getRouteSecurity ->invoke (null , 'v1/haxiamAddUserAccess ' , 'POST ' ), 'haxiamAddUserAccess is admin ' );
248+ assertEquals ('authenticated ' , $ getRouteSecurity ->invoke (null , 'v1/themes ' , 'GET ' ), 'v1/themes GET is authenticated ' );
249+ assertEquals ('admin ' , $ getRouteSecurity ->invoke (null , 'v1/themes ' , 'POST ' ), 'v1/themes POST is admin ' );
250+ assertEquals ('authenticated ' , $ getRouteSecurity ->invoke (null , 'v1/skeletons ' , 'GET ' ), 'v1/skeletons GET is authenticated ' );
251+ assertEquals ('admin ' , $ getRouteSecurity ->invoke (null , 'v1/skeletons ' , 'POST ' ), 'v1/skeletons POST is admin ' );
252+ assertEquals ('authenticated ' , $ getRouteSecurity ->invoke (null , 'v1/haxiamAddUserAccess ' , 'POST ' ), 'haxiamAddUserAccess is authenticated ' );
165253
166254// Test 6: SystemApiSecurity bearer token validation stub (no real token)
167255echo "[6/13] SystemApiSecurity bearer validation (no token)... \n" ;
0 commit comments