summaryrefslogtreecommitdiff
path: root/internal/cli/kdbx_store_test.go
blob: fc79ca632ad96117e55f53d13bc8192c4f217a3e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package cli

import "testing"

func TestSplitDescriptionPath(t *testing.T) {
	group, title, err := splitDescriptionPath("foo/bar/baz")
	if err != nil {
		t.Fatalf("splitDescriptionPath: %v", err)
	}
	if title != "baz" {
		t.Fatalf("title = %q; want baz", title)
	}
	if len(group) != 2 || group[0] != "foo" || group[1] != "bar" {
		t.Fatalf("group path = %v; want [foo bar]", group)
	}
}

func TestSanitizeRelativePathRejectsTraversal(t *testing.T) {
	if _, err := sanitizeRelativePath("../secret"); err == nil {
		t.Fatal("sanitizeRelativePath should reject traversal path")
	}
}

func TestExtractPasswordFromContent(t *testing.T) {
	password, notes := extractPasswordFromContent("user: alice\npassword: s3cr3t\nurl: example.com\n")
	if password != "s3cr3t" {
		t.Fatalf("password = %q; want s3cr3t", password)
	}
	if notes != "user: alice\nurl: example.com" {
		t.Fatalf("notes = %q; want without password line", notes)
	}
}