From 809792c152ea0639339000689ee8d48da2d0a1ce Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 23 Dec 2025 08:20:47 +0800 Subject: [PATCH] Add Authorized Data Sharing in Script Runner Execution - Introduced functionality to set shared data with authorized information for Process calls in the ScriptRunner. - Enhanced the executeTestFunction to include error handling for setting share data, improving robustness during script execution. - This change ensures that authorization context is properly managed when calling JavaScript functions directly, enhancing security and functionality. --- agent/test/script.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/agent/test/script.go b/agent/test/script.go index ba54a370..6f048c17 100644 --- a/agent/test/script.go +++ b/agent/test/script.go @@ -424,6 +424,22 @@ func (r *ScriptRunner) executeTestFunction(tc *ScriptTestCase, scriptInfo *Scrip // Get the V8 context v8ctx := scriptCtx.Context + // Set share data with authorized info for Process calls + // This is needed because we call fn.Call directly instead of scriptCtx.Call + var authorized map[string]interface{} + if agentCtx.Authorized != nil { + authorized = agentCtx.Authorized.AuthorizedToMap() + } + err = bridge.SetShareData(v8ctx, v8ctx.Global(), &bridge.Share{ + Sid: "", + Root: false, + Global: nil, + Authorized: authorized, + }) + if err != nil { + return fmt.Errorf("failed to set share data: %w", err) + } + // Create testing.T JavaScript object testingTObj, err := NewTestingTObject(v8ctx, testingT) if err != nil {