Add createFolder, rename, move, copyNode, trash and emptyTrash to the new client, following the SDK's nodesManagement.ts: names and passphrases are re-encrypted to the new parent with their session keys and signed by the share's address; the node passphrase signature is sent on move and copy only for an anonymous node; API code 2500 maps to errExists and 2501 to errNotFound. Every mutation updates the node cache, and nodeCache.put forgets both parents' listings when a node's parent changes. The fake gains the matching routes plus checkAvailableHashes. It rejects SEIPDv2 or v6 PKESK names, passphrases, hash keys and extended attributes, and folder keys which are not v4, advertise AEAD or are not locked with an iterated and salted S2K. It enforces name hash uniqueness, OriginalHash, no move into a descendant and the anonymous signature rule. Dump now also checks every name hash, and SeedAnonymousFile seeds a public-link upload. Wire format: the create folder request sends SignatureEmail as the SDK does, although CreateFolderDto lists SignatureAddress. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
96 lines
2.3 KiB
Go
96 lines
2.3 KiB
Go
package protondrive
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestNodeCacheDisabled(t *testing.T) {
|
|
c := newNodeCache(false)
|
|
require.Nil(t, c)
|
|
n := &node{ID: "a", ParentID: "root"}
|
|
c.put(n)
|
|
c.setChildren("root", []*node{n})
|
|
assert.Nil(t, c.get("a"))
|
|
_, ok := c.children("root")
|
|
assert.False(t, ok)
|
|
c.invalidate("a")
|
|
c.invalidateChildren("root")
|
|
c.clear()
|
|
}
|
|
|
|
func TestNodeCache(t *testing.T) {
|
|
c := newNodeCache(true)
|
|
dir := &node{ID: "dir", ParentID: "root", IsFolder: true}
|
|
file := &node{ID: "file", ParentID: "dir"}
|
|
|
|
assert.Nil(t, c.get("dir"))
|
|
_, ok := c.children("root")
|
|
assert.False(t, ok)
|
|
|
|
c.setChildren("root", []*node{dir})
|
|
c.setChildren("dir", []*node{file})
|
|
assert.Same(t, dir, c.get("dir"))
|
|
assert.Same(t, file, c.get("file"))
|
|
got, ok := c.children("dir")
|
|
require.True(t, ok)
|
|
assert.Equal(t, []*node{file}, got)
|
|
|
|
// An empty listing is a listing.
|
|
c.setChildren("empty", nil)
|
|
got, ok = c.children("empty")
|
|
assert.True(t, ok)
|
|
assert.Empty(t, got)
|
|
|
|
// put replaces the node in the listing.
|
|
renamed := &node{ID: "file", ParentID: "dir", Name: "new"}
|
|
c.put(renamed)
|
|
got, ok = c.children("dir")
|
|
require.True(t, ok)
|
|
assert.Equal(t, []*node{renamed}, got)
|
|
|
|
// put of a node with another parent forgets both listings.
|
|
c.setChildren("other", nil)
|
|
moved := &node{ID: "file", ParentID: "other"}
|
|
c.put(moved)
|
|
assert.Same(t, moved, c.get("file"))
|
|
_, ok = c.children("dir")
|
|
assert.False(t, ok)
|
|
_, ok = c.children("other")
|
|
assert.False(t, ok)
|
|
_, ok = c.children("root")
|
|
assert.True(t, ok)
|
|
c.setChildren("dir", []*node{renamed})
|
|
|
|
// invalidate forgets the node and its parent's listing.
|
|
c.invalidate("file")
|
|
assert.Nil(t, c.get("file"))
|
|
_, ok = c.children("dir")
|
|
assert.False(t, ok)
|
|
_, ok = c.children("root")
|
|
assert.True(t, ok)
|
|
|
|
// and a folder's own listing.
|
|
c.setChildren("dir", []*node{file})
|
|
c.invalidate("dir")
|
|
_, ok = c.children("dir")
|
|
assert.False(t, ok)
|
|
_, ok = c.children("root")
|
|
assert.False(t, ok)
|
|
assert.Same(t, file, c.get("file"))
|
|
|
|
c.setChildren("dir", []*node{file})
|
|
c.invalidateChildren("dir")
|
|
_, ok = c.children("dir")
|
|
assert.False(t, ok)
|
|
assert.Same(t, file, c.get("file"))
|
|
|
|
c.setChildren("dir", []*node{file})
|
|
c.clear()
|
|
assert.Nil(t, c.get("file"))
|
|
_, ok = c.children("dir")
|
|
assert.False(t, ok)
|
|
}
|