mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-10-31 02:42:31 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1551fa8355 |
No files matched your search
@@ -19,7 +19,7 @@ export function PluginLogSettings() {
|
||||
const disclosure = zh
|
||||
? '插件编写的日志文字可能包含敏感数据。截断和字段过滤不能保证任意文字安全。只为排查问题临时开启,导出前请检查。重启应用后自动关闭详细日志。'
|
||||
: 'Plugin-authored text may contain sensitive data. Truncation and field filtering cannot make arbitrary text safe. Enable temporarily for troubleshooting and review files before sharing. Verbose diagnostics turn off after app restart.';
|
||||
return <div data-host-security-surface="">
|
||||
return <div>
|
||||
<Dialog open={open} onOpenChange={setOpen}>
|
||||
<SettingRow label={title} description={zh ? '选择是否在此设备保存审计记录和诊断日志。' : 'Choose whether to keep audit records and diagnostics on this device.'}>
|
||||
<div className="flex items-center gap-3">
|
||||
@@ -53,6 +53,6 @@ export function PluginLogSettings() {
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
<ConfirmDialog open={confirmVerbose} title={zh ? '开启插件详细诊断?' : 'Enable verbose plugin diagnostics?'} message={disclosure} confirmLabel={zh ? '临时开启' : 'Enable temporarily'} onOpenChange={setConfirmVerbose} onConfirm={() => { setConfirmVerbose(false); void run('configure', { saveToDisk: true, verbose: true }); }} />
|
||||
<ConfirmDialog hostSecuritySurface open={confirmVerbose} title={zh ? '开启插件详细诊断?' : 'Enable verbose plugin diagnostics?'} message={disclosure} confirmLabel={zh ? '临时开启' : 'Enable temporarily'} onOpenChange={setConfirmVerbose} onConfirm={() => { setConfirmVerbose(false); void run('configure', { saveToDisk: true, verbose: true }); }} />
|
||||
</div>;
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { EventEmitter } from 'node:events';
|
||||
import { createRequire } from 'node:module';
|
||||
import { JSDOM } from 'jsdom';
|
||||
const require = createRequire(import.meta.url);
|
||||
|
||||
test('real Settings landing leaves views visible while idle; log and Ask dialogs suspend and restore them', async () => {
|
||||
const dom = new JSDOM('<!doctype html><html><body><div id="root"></div><div id="native-view-mount"></div></body></html>', { pretendToBeVisual: true, url: 'http://localhost' });
|
||||
const previous = new Map<string, PropertyDescriptor | undefined>();
|
||||
const install = (key: string, value: unknown) => {
|
||||
previous.set(key, Object.getOwnPropertyDescriptor(globalThis, key));
|
||||
Object.defineProperty(globalThis, key, { configurable: true, writable: true, value });
|
||||
};
|
||||
for (const key of ['window', 'document', 'navigator', 'HTMLElement', 'HTMLInputElement', 'Element', 'Node', 'NodeFilter', 'Event', 'MouseEvent', 'KeyboardEvent', 'MutationObserver', 'DocumentFragment', 'CustomEvent']) install(key, key === 'window' ? dom.window : dom.window[key as keyof typeof dom.window]);
|
||||
install('getComputedStyle', dom.window.getComputedStyle.bind(dom.window));
|
||||
install('requestAnimationFrame', dom.window.requestAnimationFrame.bind(dom.window));
|
||||
install('cancelAnimationFrame', dom.window.cancelAnimationFrame.bind(dom.window));
|
||||
install('IS_REACT_ACT_ENVIRONMENT', true);
|
||||
const { default: React, act } = await import('react');
|
||||
const { createRoot } = await import('react-dom/client');
|
||||
const { I18nProvider } = await import('../../../application/i18n/I18nProvider');
|
||||
const { PluginSettingsLanding } = await import('./PluginSettingsLanding');
|
||||
const { PluginPermissionHost } = await import('../../plugins/PluginPermissionHost');
|
||||
const { observePluginHostSecurityVisibility } = await import('../../../application/state/pluginHostSecurityVisibility');
|
||||
const { PluginPermissionDecisionHost } = require('../../../electron/plugins/permissionDecisionHost.cjs');
|
||||
type Prompt = NetcattyPluginPermissionPrompt | { requestId: string; closed: true };
|
||||
const listeners = new Set<(event: Prompt) => void>();
|
||||
const sender = Object.assign(new EventEmitter(), { isDestroyed: () => false, send: (_channel: string, event: Prompt) => { for (const listener of listeners) listener(event); } });
|
||||
const owner = Object.assign(new EventEmitter(), { webContents: sender, isFocused: () => true, isVisible: () => true, isDestroyed: () => false });
|
||||
const host = new PluginPermissionDecisionHost({ getWindows: () => [owner], isLocked: () => false });
|
||||
let logStatus = { saveToDisk: false, verbose: false, droppedRecords: 0, writeErrors: 0, pendingBytes: 0, maxBytes: 3145728, retentionDays: 7 };
|
||||
Object.assign(dom.window, { netcatty: {
|
||||
async getPluginLogStatus() { return logStatus; },
|
||||
async configurePluginLogs(value: { saveToDisk: boolean; verbose: boolean }) { logStatus = { ...logStatus, ...value }; return logStatus; },
|
||||
onPluginPermission(listener: (event: Prompt) => void) { listeners.add(listener); return () => listeners.delete(listener); },
|
||||
setPluginPermissionReady: async (ready: boolean) => host.setReady(sender, ready),
|
||||
respondPluginPermission: async (response: unknown) => host.respond(sender, response),
|
||||
} });
|
||||
const manager = { plugins: [], available: true, statusKnown: true, busy: false, error: null, credentialStorageAvailable: true,
|
||||
async refresh() {}, async setEnabled() {}, async importPackage() {}, async uninstall() {} };
|
||||
let visible = true;
|
||||
const transitions: boolean[] = [];
|
||||
const stopVisibility = observePluginHostSecurityVisibility(document.getElementById('native-view-mount')!, (next) => { visible = next; transitions.push(next); });
|
||||
const root = createRoot(document.getElementById('root')!);
|
||||
const button = (label: string) => [...document.querySelectorAll<HTMLButtonElement>('button')].find((element) => element.textContent === label)!;
|
||||
const flushVisibility = () => new Promise<void>((resolve) => dom.window.queueMicrotask(resolve));
|
||||
try {
|
||||
await act(async () => root.render(<I18nProvider locale="en"><PluginSettingsLanding manager={manager} settingsAvailable={new Set()} onManage={() => {}} /><PluginPermissionHost /></I18nProvider>));
|
||||
await flushVisibility();
|
||||
assert.equal(document.querySelector('[role="dialog"]'), null);
|
||||
assert.ok(button('Configure'), 'real idle logging row is present');
|
||||
assert.equal(visible, true, 'idle Settings landing must not hide the native child');
|
||||
assert.deepEqual(transitions, []);
|
||||
await act(async () => button('Configure').click());
|
||||
await flushVisibility();
|
||||
assert.ok(document.querySelector('[role="dialog"][data-host-security-surface]'));
|
||||
assert.equal(visible, false, 'actual logging security dialog must hide the child');
|
||||
await act(async () => document.querySelectorAll<HTMLButtonElement>('[role="switch"]')[0].click());
|
||||
await act(async () => document.querySelectorAll<HTMLButtonElement>('[role="switch"]')[1].click());
|
||||
await flushVisibility();
|
||||
assert.equal(document.querySelectorAll('[role="dialog"]').length, 2);
|
||||
assert.equal(visible, false, 'the verbose security confirmation must also keep the child hidden');
|
||||
await act(async () => button('Cancel').click());
|
||||
await flushVisibility();
|
||||
assert.equal(visible, false, 'cancelling verbose returns to the protected logging dialog');
|
||||
await act(async () => button('Close').click());
|
||||
await flushVisibility();
|
||||
assert.equal(document.querySelector('[role="dialog"]'), null);
|
||||
assert.equal(visible, true, 'closing logs must restore the child while its idle row remains');
|
||||
let pending!: Promise<{ decision: string }>;
|
||||
await act(async () => {
|
||||
pending = host.request({ requestId: 'settings-visibility-ask', pluginId: 'com.example.settings-visibility', pluginName: 'Settings visibility fixture', pluginVersion: '1.0.0',
|
||||
permission: 'settings.read', resources: ['*'], reason: 'Read own synthetic setting' });
|
||||
});
|
||||
await flushVisibility();
|
||||
assert.ok(document.querySelector('[role="dialog"][data-host-security-surface]'));
|
||||
assert.equal(visible, false, 'Ask must still hide the child above the real landing');
|
||||
await act(async () => { button('Deny').click(); await pending; });
|
||||
await flushVisibility();
|
||||
assert.equal((await pending).decision, 'deny');
|
||||
assert.equal(visible, true, 'dismissing Ask must restore the same child');
|
||||
assert.deepEqual(transitions, [false, true, false, true]);
|
||||
} finally {
|
||||
await act(async () => root.unmount()); stopVisibility(); host.shutdown(); dom.window.close();
|
||||
for (const [key, descriptor] of previous) { if (descriptor) Object.defineProperty(globalThis, key, descriptor); else Reflect.deleteProperty(globalThis, key); }
|
||||
}
|
||||
});
|
||||
@@ -17,6 +17,7 @@ interface ConfirmDialogProps {
|
||||
confirmLabel: string;
|
||||
busy?: boolean;
|
||||
destructive?: boolean;
|
||||
hostSecuritySurface?: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
onConfirm: () => void;
|
||||
}
|
||||
@@ -28,6 +29,7 @@ export const ConfirmDialog = memo(function ConfirmDialog({
|
||||
confirmLabel,
|
||||
busy = false,
|
||||
destructive = false,
|
||||
hostSecuritySurface = false,
|
||||
onOpenChange,
|
||||
onConfirm,
|
||||
}: ConfirmDialogProps) {
|
||||
@@ -35,7 +37,7 @@ export const ConfirmDialog = memo(function ConfirmDialog({
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="max-w-[calc(100vw-2rem)] overflow-hidden sm:max-w-[380px]">
|
||||
<DialogContent data-host-security-surface={hostSecuritySurface ? "" : undefined} className="max-w-[calc(100vw-2rem)] overflow-hidden sm:max-w-[380px]">
|
||||
<DialogHeader className="min-w-0 pr-6">
|
||||
<DialogTitle className="truncate">{title}</DialogTitle>
|
||||
</DialogHeader>
|
||||
|
||||
@@ -85,6 +85,32 @@ initial-checkpoint evidence.
|
||||
|
||||
## Latest checks and remaining environment blockers
|
||||
|
||||
- The native candidate `2433cf0130d1c3274c56c39e5765349c2945de01` retains the
|
||||
same idle logging-row marker as `89beeb9` (source blob
|
||||
`4dd5a7cea4ae5a6addc5db5c162038d8fa44075c`). Actual Settings landing plus the
|
||||
existing observer reproduces native-child suppression with no dialog open.
|
||||
This source defect is separate from the worker's earlier GPU exit and does
|
||||
not alone establish the cause of the recorded blank native body.
|
||||
- The scoped correction removes only the idle-row marker. Actual logging and
|
||||
Ask dialogs remain marked. A real nested verbose confirmation test also
|
||||
reproduced premature restoration when its parent became accessibility-hidden;
|
||||
that confirmation now opts into the existing marker on its own dialog content.
|
||||
The observer, window trust, permissions and data access are unchanged. The real
|
||||
landing regression verifies idle visible, each security dialog hidden, and
|
||||
restored on dismissal. Focused group **six passed**; Settings boundary group
|
||||
**36 passed**. Both pre-fix failures are retained outside the source tree.
|
||||
Production build and full lint pass (zero lint errors/seven existing warnings).
|
||||
Full TypeScript remains baseline-equivalent at 774 diagnostics with zero
|
||||
added/removed. Exact-head CI and the next frozen native recheck are separate
|
||||
gates; neither is inferred from these local tests.
|
||||
- QA-only **Settings Ask QA 0.1.0** uses its supported `location: settings` entry
|
||||
and public SDK to read only its synthetic own setting after an explicit click.
|
||||
Exact archive SHA-256:
|
||||
`9502a58a4804862e4b13de9fc0d1baf6ad8c2bc681c08b5c0664b552ef0aafc4`.
|
||||
Its HTML/CSS/JS each return 200 with proper MIME/CSP through the actual plugin
|
||||
protocol. It contains no raw IPC/test hook or external access. No GUI or running
|
||||
app was changed by this correction; parent will build a new frozen candidate
|
||||
after current cleanup and repeat native Settings acceptance.
|
||||
- A registered regression reproduces `Plugin permission decision provider failed`
|
||||
on exact `79a9bd6` when a Settings-owned view activates a real `settings.get`
|
||||
API configured Ask while main is unfocused. The follow-up uses the existing
|
||||
|
||||
@@ -47,6 +47,9 @@ focus handoff is needed. Close, cancel, timeout, lock, hide/blur, reload, crash
|
||||
and stale runtime/source fail closed. The dialog uses the existing host security
|
||||
surface marker so attached native plugin views yield while it is visible and
|
||||
restore through their existing lifecycle on dismissal.
|
||||
Ordinary landing rows do not suspend native views. The logging dialog and its
|
||||
verbose confirmation are marked security surfaces; the confirmation opts into
|
||||
the existing marker because it temporarily accessibility-hides its parent dialog.
|
||||
A plugin DOM click never becomes a host gesture. Choosers, drafts, terminal and
|
||||
clipboard sharing use their existing host-owned action tokens. Ask integrates
|
||||
with that workflow instead of opening a second capability dialog. Allow skips
|
||||
|
||||
Reference in new issue
Block a user