mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2026-09-21 18:17:05 +00:00
Use profile storage for TURN source settings
This commit is contained in:
@@ -9,7 +9,6 @@
|
||||
export const liveSyncProvisionalEnglishMessages = {
|
||||
"Configure TURN when a direct connection cannot be established or when you select TURN relay only.":
|
||||
"Configure TURN when a direct connection cannot be established or when you select TURN relay only.",
|
||||
"TURN configuration could not be decrypted.": "TURN configuration could not be decrypted.",
|
||||
"TURN configuration": "TURN configuration",
|
||||
Manual: "Manual",
|
||||
Cloudflare: "Cloudflare",
|
||||
|
||||
@@ -10,14 +10,13 @@ vi.mock("@vrtmrz/livesync-commonlib/compat/common/coreEnvFunctions", () => ({
|
||||
}));
|
||||
|
||||
describe("TURN credentials in diagnostic reports", () => {
|
||||
it("redacts top-level, encrypted, and inactive encoded source copies", async () => {
|
||||
it("redacts top-level and inactive encoded source copies", async () => {
|
||||
const token = "private+token/with=symbols";
|
||||
const source = { version: 1, id: "cloudflare", configuration: { turnKeyId: "private-key", apiToken: token } };
|
||||
const settings = {
|
||||
...DEFAULT_SETTINGS,
|
||||
remoteType: REMOTE_P2P,
|
||||
P2P_iceServerSource: source,
|
||||
encryptedP2PIceServerSource: "encrypted-private-copy",
|
||||
remoteConfigurations: {
|
||||
inactive: {
|
||||
id: "inactive",
|
||||
@@ -33,9 +32,7 @@ describe("TURN credentials in diagnostic reports", () => {
|
||||
expect(text).not.toContain(token);
|
||||
expect(text).not.toContain(encodeURIComponent(token));
|
||||
expect(text).not.toContain("private-key");
|
||||
expect(text).not.toContain("encrypted-private-copy");
|
||||
expect(report.pluginConfig.remoteConfigurations.inactive.uri).toBe("sls+p2p://");
|
||||
expect(settings.P2P_iceServerSource).toEqual(source);
|
||||
expect(settings.encryptedP2PIceServerSource).toBe("encrypted-private-copy");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,15 +1,24 @@
|
||||
import {
|
||||
hasManagedP2PIceServerSource as hasManagedTurnSettings,
|
||||
hasManagedP2PIceServerSource,
|
||||
type ObsidianLiveSyncSettings,
|
||||
} from "@vrtmrz/livesync-commonlib/compat/common/types";
|
||||
|
||||
import { iceServerSourceDefinitions } from "@/integrations/iceServerSources";
|
||||
|
||||
export { hasManagedTurnSettings };
|
||||
/** Include inactive profiles when deciding whether Markdown would disclose source settings. */
|
||||
export function hasManagedTurnSettings(settings: Partial<ObsidianLiveSyncSettings>): boolean {
|
||||
return (
|
||||
hasManagedP2PIceServerSource(settings) ||
|
||||
Object.values(settings.remoteConfigurations ?? {}).some(({ uri }) => {
|
||||
if (!uri.startsWith("sls+p2p://")) return false;
|
||||
const queryStart = uri.indexOf("?");
|
||||
return queryStart >= 0 && new URLSearchParams(uri.slice(queryStart + 1).split("#", 1)[0]).has("source");
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
/** Reports retain the selected source label, but no opaque source configuration. */
|
||||
export function redactTurnSourceForReport(settings: Partial<ObsidianLiveSyncSettings>): void {
|
||||
if (settings.encryptedP2PIceServerSource) settings.encryptedP2PIceServerSource = "REDACTED";
|
||||
if (settings.P2P_iceServerSource !== undefined) {
|
||||
settings.P2P_iceServerSource = {
|
||||
version: 1,
|
||||
@@ -25,7 +34,6 @@ export function redactTurnSourceForReport(settings: Partial<ObsidianLiveSyncSett
|
||||
export function omitManagedTurnProfilesFromMarkdown(settings: Partial<ObsidianLiveSyncSettings>): void {
|
||||
if (!hasManagedTurnSettings(settings)) return;
|
||||
delete settings.P2P_iceServerSource;
|
||||
delete settings.encryptedP2PIceServerSource;
|
||||
delete settings.remoteConfigurations;
|
||||
delete settings.activeConfigurationId;
|
||||
delete settings.P2P_ActiveRemoteConfigurationId;
|
||||
@@ -48,5 +56,4 @@ export function preserveManagedTurnProfilesOnMarkdownImport(
|
||||
merged.activeConfigurationId = current.activeConfigurationId;
|
||||
merged.P2P_ActiveRemoteConfigurationId = current.P2P_ActiveRemoteConfigurationId;
|
||||
merged.P2P_iceServerSource = structuredClone(current.P2P_iceServerSource);
|
||||
merged.encryptedP2PIceServerSource = current.encryptedP2PIceServerSource;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user