Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

1.1 KB
Raw Blame
// SiYuan - https://github.com/siyuan-note/siyuan
// Copyright (c) 2020-present, b3log.org
// SPDX-License-Identifier: AGPL-3.0-or-later

package tools

import (
	"os"
	"path/filepath"
	"strings"
	"testing"

	"github.com/88250/lute/ast"
	"github.com/siyuan-note/siyuan/kernel/util"
)

func TestInboxConvertRejectsEncryptedNotebookBeforeCloudAccess(t *testing.T) {
	originalDataDir := util.DataDir
	util.DataDir = t.TempDir()
	t.Cleanup(func() { util.DataDir = originalDataDir })
	boxID := ast.NewNodeID()
	confDir := filepath.Join(util.DataDir, boxID, ".siyuan")
	if err := os.MkdirAll(confDir, 0755); err != nil {
		t.Fatal(err)
	}
	if err := os.WriteFile(filepath.Join(confDir, "conf.json"), []byte(`{"encrypted":true}`), 0644); err != nil {
		t.Fatal(err)
	}
	result, err := inboxConvert(map[string]any{"notebook": boxID, "ids": "1700000000000"})
	if err != nil || !result.IsError || len(result.Content) != 1 || !strings.Contains(result.Content[0].Text, "non-encrypted notebook") {
		t.Fatalf("expected encrypted target rejection before cloud access, got %+v, %v", result, err)
	}
}