diff --git a/app/components/editor/hooks/useRunTest.tsx b/app/components/editor/hooks/useRunTest.tsx index 21879c5..71b592e 100755 --- a/app/components/editor/hooks/useRunTest.tsx +++ b/app/components/editor/hooks/useRunTest.tsx @@ -84,7 +84,7 @@ function parseABACRequest(line: string): any[] { async function enforcer(props: RunTestProps) { const startTime = performance.now(); - const result = []; + const result: { request: string; okEx: boolean; reason: string[]; }[] = []; try { const e = await newEnforcer(newModel(props.model), props.policy ? new StringAdapter(props.policy) : undefined); @@ -172,8 +172,8 @@ async function enforcer(props: RunTestProps) { const rvals = parseABACRequest(n); const ctx = newEnforceContext(props.enforceContextData); - // @ts-ignore - result.push(await e.enforce(ctx, ...rvals)); + const [okEx, reason] = await e.enforceEx(ctx, ...rvals); + result.push({ request: n, okEx, reason }); } const stopTime = performance.now(); diff --git a/app/components/editor/index.tsx b/app/components/editor/index.tsx index a417bee..085571d 100755 --- a/app/components/editor/index.tsx +++ b/app/components/editor/index.tsx @@ -72,7 +72,16 @@ export const EditorScreen = () => { if (isValidElement(v)) { setEcho(v); } else if (Array.isArray(v)) { - setRequestResult(v.join('\n')); + const formattedResults = v.map((res) => { + if (typeof res === 'object') { + const reasonString = Array.isArray(res.reason) && res.reason.length > 0 + ? ` Reason: ${JSON.stringify(res.reason)}` + : ''; + return `${res.okEx}${reasonString}`; + } + return res; + }); + setRequestResult(formattedResults.join('\n')); } }, }); @@ -350,7 +359,16 @@ export const EditorScreen = () => { if (isValidElement(v)) { setEcho(v); } else if (Array.isArray(v)) { - setRequestResult(v.join('\n')); + const formattedResults = v.map((res) => { + if (typeof res === 'object') { + const reasonString = Array.isArray(res.reason) && res.reason.length > 0 + ? ` Reason: ${JSON.stringify(res.reason)}` + : ''; + return `${res.okEx}${reasonString}`; + } + return res; + }); + setRequestResult(formattedResults.join('\n')); } }, });