feat(sync): encrypt snippet sync snapshots
This commit is contained in:
21 files changed
+1412
-124
No files matched your search
@@ -0,0 +1,30 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
const settingsDialogSource = readFileSync(new URL("../../../components/editor/EditorSettingsDialog.vue", import.meta.url), "utf8");
|
||||
const httpBackendSource = readFileSync(new URL("../../backend/http.ts", import.meta.url), "utf8");
|
||||
const tauriBackendSource = readFileSync(new URL("../../backend/tauri.ts", import.meta.url), "utf8");
|
||||
|
||||
describe("snippet migration cleanup recovery", () => {
|
||||
it("restores pending cleanup state and keeps it visible after restart", () => {
|
||||
expect(settingsDialogSource).toContain('pendingLegacyCleanupId.value = settings.legacyCleanupRequiredId || ""');
|
||||
expect(settingsDialogSource).toContain('v-if="pendingLegacyCleanupId"');
|
||||
expect(settingsDialogSource).toContain('t("settings.syncSnippetMigrateLegacyCleanupRequired", { id: pendingLegacyCleanupId })');
|
||||
});
|
||||
|
||||
it("clears the UI state only after the retry response confirms cleanup", () => {
|
||||
const retryStart = settingsDialogSource.indexOf("async function retryLegacySnippetCleanup()");
|
||||
const retryEnd = settingsDialogSource.indexOf("async function downloadSnippetSnapshot()", retryStart);
|
||||
const retrySource = settingsDialogSource.slice(retryStart, retryEnd);
|
||||
expect(retrySource).toContain("await retrySnippetLegacyCleanup(currentSnippetConfig())");
|
||||
expect(retrySource).toContain('pendingLegacyCleanupId.value = settings.legacyCleanupRequiredId || ""');
|
||||
expect(retrySource).toContain("if (settings.legacyCleanupRequiredId)");
|
||||
});
|
||||
|
||||
it("wires the retry operation through both Web and Tauri backends", () => {
|
||||
expect(httpBackendSource).toContain('post("/api/cloud-sync/snippet/retry-legacy-cleanup", { config })');
|
||||
expect(tauriBackendSource).toContain('invoke("retry_snippet_legacy_cleanup", { config })');
|
||||
expect(httpBackendSource).toContain("legacyCleanupRequiredId?: string");
|
||||
expect(tauriBackendSource).toContain("legacyCleanupRequiredId?: string");
|
||||
});
|
||||
});
|
||||
@@ -302,6 +302,9 @@ export const snippetSyncTest = forward("snippetSyncTest");
|
||||
export const snippetTokenStatus = forward("snippetTokenStatus");
|
||||
export const saveSnippetSavedToken = forward("saveSnippetSavedToken");
|
||||
export const forgetSnippetSavedToken = forward("forgetSnippetSavedToken");
|
||||
export const snippetSyncSettings = forward("snippetSyncSettings");
|
||||
export const saveSnippetSyncId = forward("saveSnippetSyncId");
|
||||
export const retrySnippetLegacyCleanup = forward("retrySnippetLegacyCleanup");
|
||||
export const snippetSyncUpload = forward("snippetSyncUpload");
|
||||
export const snippetSyncDownload = forward("snippetSyncDownload");
|
||||
export const saveAiConversation = forward("saveAiConversation");
|
||||
@@ -636,6 +639,7 @@ export type {
|
||||
WebDavDownloadResult,
|
||||
SnippetProvider,
|
||||
SnippetSyncConfig,
|
||||
SnippetSyncSettings,
|
||||
SnippetSyncSummary,
|
||||
SnippetDownloadResult,
|
||||
SnippetTokenStatus,
|
||||
|
||||
@@ -1613,6 +1613,12 @@ export interface SnippetSyncConfig {
|
||||
provider: SnippetProvider;
|
||||
token?: string;
|
||||
snippetId?: string;
|
||||
replaceLegacySnippet?: boolean;
|
||||
}
|
||||
|
||||
export interface SnippetSyncSettings {
|
||||
snippetId?: string;
|
||||
legacyCleanupRequiredId?: string;
|
||||
}
|
||||
|
||||
export interface SnippetSyncSummary {
|
||||
@@ -1621,6 +1627,7 @@ export interface SnippetSyncSummary {
|
||||
bytes: number;
|
||||
exportedAt?: string;
|
||||
appVersion?: string;
|
||||
legacyCleanupRequiredId?: string;
|
||||
}
|
||||
|
||||
export interface SnippetDownloadResult {
|
||||
@@ -1693,17 +1700,33 @@ export async function forgetSnippetSavedToken(config: SnippetSyncConfig): Promis
|
||||
await post("/api/cloud-sync/snippet/forget-token", { config });
|
||||
}
|
||||
|
||||
export async function snippetSyncUpload(config: SnippetSyncConfig, editorSettings?: unknown, secretsPassphrase?: string): Promise<SnippetSyncSummary> {
|
||||
export async function snippetSyncSettings(provider: SnippetProvider): Promise<SnippetSyncSettings> {
|
||||
return post("/api/cloud-sync/snippet/settings", { provider });
|
||||
}
|
||||
|
||||
export async function saveSnippetSyncId(provider: SnippetProvider, snippetId?: string): Promise<void> {
|
||||
await post("/api/cloud-sync/snippet/save-id", { provider, snippetId });
|
||||
}
|
||||
|
||||
export async function retrySnippetLegacyCleanup(config: SnippetSyncConfig): Promise<SnippetSyncSettings> {
|
||||
return post("/api/cloud-sync/snippet/retry-legacy-cleanup", { config });
|
||||
}
|
||||
|
||||
export async function snippetSyncUpload(config: SnippetSyncConfig, editorSettings?: unknown, snippetPassphrase?: string, includeSecrets = false, secretsPassphrase?: string): Promise<SnippetSyncSummary> {
|
||||
return post("/api/cloud-sync/snippet/upload", {
|
||||
config,
|
||||
editorSettings,
|
||||
snippetPassphrase,
|
||||
includeSecrets,
|
||||
secretsPassphrase,
|
||||
});
|
||||
}
|
||||
|
||||
export async function snippetSyncDownload(config: SnippetSyncConfig, secretsPassphrase?: string): Promise<SnippetDownloadResult> {
|
||||
export async function snippetSyncDownload(config: SnippetSyncConfig, snippetPassphrase?: string, restoreSecrets = false, secretsPassphrase?: string): Promise<SnippetDownloadResult> {
|
||||
return post("/api/cloud-sync/snippet/download", {
|
||||
config,
|
||||
snippetPassphrase,
|
||||
restoreSecrets,
|
||||
secretsPassphrase,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -238,6 +238,12 @@ export interface SnippetSyncConfig {
|
||||
provider: SnippetProvider;
|
||||
token?: string;
|
||||
snippetId?: string;
|
||||
replaceLegacySnippet?: boolean;
|
||||
}
|
||||
|
||||
export interface SnippetSyncSettings {
|
||||
snippetId?: string;
|
||||
legacyCleanupRequiredId?: string;
|
||||
}
|
||||
|
||||
export interface SnippetSyncSummary {
|
||||
@@ -246,6 +252,7 @@ export interface SnippetSyncSummary {
|
||||
bytes: number;
|
||||
exportedAt?: string;
|
||||
appVersion?: string;
|
||||
legacyCleanupRequiredId?: string;
|
||||
}
|
||||
|
||||
export interface SnippetDownloadResult {
|
||||
@@ -677,16 +684,30 @@ export async function forgetSnippetSavedToken(config: SnippetSyncConfig): Promis
|
||||
return invoke("forget_snippet_saved_token", { config });
|
||||
}
|
||||
|
||||
export async function snippetSyncUpload(config: SnippetSyncConfig, editorSettings?: unknown, secretsPassphrase?: string): Promise<SnippetSyncSummary> {
|
||||
export async function snippetSyncSettings(provider: SnippetProvider): Promise<SnippetSyncSettings> {
|
||||
return invoke("snippet_sync_settings", { provider });
|
||||
}
|
||||
|
||||
export async function saveSnippetSyncId(provider: SnippetProvider, snippetId?: string): Promise<void> {
|
||||
return invoke("save_snippet_sync_id", { provider, snippetId });
|
||||
}
|
||||
|
||||
export async function retrySnippetLegacyCleanup(config: SnippetSyncConfig): Promise<SnippetSyncSettings> {
|
||||
return invoke("retry_snippet_legacy_cleanup", { config });
|
||||
}
|
||||
|
||||
export async function snippetSyncUpload(config: SnippetSyncConfig, editorSettings?: unknown, snippetPassphrase?: string, includeSecrets = false, secretsPassphrase?: string): Promise<SnippetSyncSummary> {
|
||||
return invoke("snippet_sync_upload", {
|
||||
config,
|
||||
editorSettings,
|
||||
snippetPassphrase,
|
||||
includeSecrets,
|
||||
secretsPassphrase,
|
||||
});
|
||||
}
|
||||
|
||||
export async function snippetSyncDownload(config: SnippetSyncConfig, secretsPassphrase?: string): Promise<SnippetDownloadResult> {
|
||||
return invoke("snippet_sync_download", { config, secretsPassphrase });
|
||||
export async function snippetSyncDownload(config: SnippetSyncConfig, snippetPassphrase?: string, restoreSecrets = false, secretsPassphrase?: string): Promise<SnippetDownloadResult> {
|
||||
return invoke("snippet_sync_download", { config, snippetPassphrase, restoreSecrets, secretsPassphrase });
|
||||
}
|
||||
|
||||
export async function loadPinnedTreeNodeIds(): Promise<string[]> {
|
||||
|
||||
Reference in new issue
Block a user