forked from 99designs/keyring
-
Notifications
You must be signed in to change notification settings - Fork 0
/
file_test.go
61 lines (49 loc) · 1.26 KB
/
file_test.go
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package keyring
import (
"os"
"testing"
)
func TestFileKeyringSetWhenEmpty(t *testing.T) {
k := &fileKeyring{
dir: os.TempDir(),
passwordFunc: FixedStringPrompt("no more secrets"),
}
item := Item{Key: "llamas", Data: []byte("llamas are great")}
if err := k.Set(item); err != nil {
t.Fatal(err)
}
foundItem, err := k.Get("llamas")
if err != nil {
t.Fatal(err)
}
if string(foundItem.Data) != "llamas are great" {
t.Fatalf("Value stored was not the value retrieved: %q", foundItem.Data)
}
if foundItem.Key != "llamas" {
t.Fatalf("Key wasn't persisted: %q", foundItem.Key)
}
}
func TestFileKeyringGetWithSlashes(t *testing.T) {
k := &fileKeyring{
dir: os.TempDir(),
passwordFunc: FixedStringPrompt("no more secrets"),
}
item := Item{Key: "https://aws-sso-portal.awsapps.com/start", Data: []byte("https://aws-sso-portal.awsapps.com/start")}
if err := k.Set(item); err != nil {
t.Fatal(err)
}
if err := k.Remove(item.Key); err != nil {
t.Fatal(err)
}
}
func TestFilenameWithBadChars(t *testing.T) {
a := `abc/.././123`
e := filenameEscape(a)
if e != `abc%2F..%2F.%2F123` {
t.Fatalf("Unexpected result from filenameEscape: %s", e)
}
b := filenameUnescape(e)
if b != a {
t.Fatal("Unexpected filenameEscape")
}
}