Skip to content

Commit 9c222f2

Browse files
committed
feat(test): add permission checks for ts and diffusion apis
Added comprehensive permission tests to verify that: - add_child, update_parent_data, and save_order actions are blocked for users without write permissions - get_ontology_map is restricted to admin users only - tool_request properly blocks access to non-public/non-static methods These tests ensure proper security boundaries are maintained in the API layer by validating that unauthorized actions return appropriate permission errors.
1 parent bb22d37 commit 9c222f2

1 file changed

Lines changed: 110 additions & 0 deletions

File tree

test/server/api/SecurityAudit_Test.php

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,116 @@ public function test_read_raw_permission_check() : void {
156156
$this->assertContains('insufficient permissions', $response->errors, "Should return insufficient permissions error for read_raw");
157157
}
158158

159+
/**
160+
* TEST_TS_ADD_CHILD_PERMISSION_CHECK
161+
* Verify that add_child is blocked for sections the user cannot write to.
162+
*/
163+
public function test_ts_add_child_permission_check() : void {
164+
$this->force_limited_user_login(999);
165+
166+
$rqo = (object)[
167+
'action' => 'add_child',
168+
'dd_api' => 'dd_ts_api',
169+
'source' => (object)[
170+
'section_tipo' => self::$section_tipo,
171+
'section_id' => '1'
172+
]
173+
];
174+
175+
$response = dd_ts_api::add_child($rqo);
176+
177+
$this->assertContains('insufficient permissions', $response->errors, "Should return insufficient permissions error for add_child");
178+
}
179+
180+
/**
181+
* TEST_TS_UPDATE_PARENT_PERMISSION_CHECK
182+
* Verify that update_parent_data is blocked for sections the user cannot write to.
183+
*/
184+
public function test_ts_update_parent_permission_check() : void {
185+
$this->force_limited_user_login(999);
186+
187+
$rqo = (object)[
188+
'action' => 'update_parent_data',
189+
'dd_api' => 'dd_ts_api',
190+
'source' => (object)[
191+
'section_tipo' => self::$section_tipo,
192+
'section_id' => '1',
193+
'old_parent_section_tipo' => self::$section_tipo,
194+
'old_parent_section_id' => '2',
195+
'new_parent_section_tipo' => self::$section_tipo,
196+
'new_parent_section_id' => '3'
197+
]
198+
];
199+
200+
$response = dd_ts_api::update_parent_data($rqo);
201+
202+
$this->assertContains('insufficient permissions', $response->errors, "Should return insufficient permissions error for update_parent_data");
203+
}
204+
205+
/**
206+
* TEST_TS_SAVE_ORDER_PERMISSION_CHECK
207+
* Verify that save_order is blocked for sections the user cannot write to.
208+
*/
209+
public function test_ts_save_order_permission_check() : void {
210+
$this->force_limited_user_login(999);
211+
212+
$rqo = (object)[
213+
'action' => 'save_order',
214+
'dd_api' => 'dd_ts_api',
215+
'source' => (object)[
216+
'section_tipo' => self::$section_tipo,
217+
'ar_locators' => [],
218+
'parent_section_tipo' => self::$section_tipo,
219+
'parent_section_id' => '1'
220+
]
221+
];
222+
223+
$response = dd_ts_api::save_order($rqo);
224+
225+
$this->assertContains('insufficient permissions', $response->errors, "Should return insufficient permissions error for save_order");
226+
}
227+
228+
/**
229+
* TEST_DIFFUSION_ONTOLOGY_MAP_PERMISSION_CHECK
230+
* Verify that get_ontology_map is blocked for non-admin users.
231+
*/
232+
public function test_diffusion_ontology_map_permission_check() : void {
233+
$this->force_limited_user_login(999);
234+
235+
$rqo = (object)[
236+
'action' => 'get_ontology_map',
237+
'dd_api' => 'dd_diffusion_api',
238+
'options' => (object)[
239+
'diffusion_tipo' => 'rsc450'
240+
]
241+
];
242+
243+
$response = dd_diffusion_api::get_ontology_map($rqo);
244+
245+
$this->assertContains('insufficient permissions', $response->errors, "Should return insufficient permissions error for get_ontology_map for non-admins");
246+
}
247+
248+
/**
249+
* TEST_TOOL_REQUEST_REFLECTION_CHECK
250+
* Verify that tool_request blocks non-public/non-static methods.
251+
*/
252+
public function test_tool_request_reflection_check() : void {
253+
$this->user_login();
254+
255+
$rqo = (object)[
256+
'action' => 'tool_request',
257+
'dd_api' => 'dd_tools_api',
258+
'source' => (object)[
259+
'model' => 'tool_time_machine', // valid standard tool
260+
'action' => '__construct'
261+
]
262+
];
263+
264+
$response = dd_tools_api::tool_request($rqo);
265+
266+
$this->assertContains('unauthorized_method', $response->errors, "Should return unauthorized_method error for non-callable methods");
267+
}
268+
159269
private function force_limited_user_login(int $user_id) : void {
160270
login_test::force_login($user_id);
161271
$_SESSION['dedalo']['auth']['is_global_admin'] = false;

0 commit comments

Comments
 (0)