MCPcopy
hub / github.com/perkeep/perkeep / TestEncrypt

Function TestEncrypt

pkg/blobserver/encrypt/encrypt_test.go:97–168  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

95}
96
97func TestEncrypt(t *testing.T) {
98 ts := newTestStorage()
99
100 const blobData = "foofoofoo"
101 tb := &test.Blob{Contents: blobData}
102 tb.MustUpload(t, ts.sto)
103 if got := ts.fetchOrErrorString(tb.BlobRef()); got != blobData {
104 t.Errorf("Fetching plaintext blobref %v = %v; want %q", tb.BlobRef(), got, blobData)
105 }
106
107 // Make sure the plaintext doesn't show up anywhere.
108 for _, bs := range []*test.Fetcher{ts.meta, ts.blobs} {
109 c := make(chan blob.SizedRef)
110 go bs.EnumerateBlobs(context.TODO(), c, "", 0)
111 for sb := range c {
112 data, ok := bs.BlobContents(sb.Ref)
113 if !ok {
114 panic("where did it go?")
115 }
116 if strings.Contains(data, blobData) {
117 t.Error("plaintext found in storage")
118 }
119 }
120 }
121
122 const blobData2 = "bar"
123 tb2 := &test.Blob{Contents: blobData2}
124 tb2.MustUpload(t, ts.sto)
125 if got := ts.fetchOrErrorString(tb2.BlobRef()); got != blobData2 {
126 t.Errorf("Fetching plaintext blobref %v = %v; want %q", tb2.BlobRef(), got, blobData2)
127 }
128
129 missingError := "Error: file does not exist"
130 tb3 := &test.Blob{Contents: "xxx"}
131 if got := ts.fetchOrErrorString(tb3.BlobRef()); got != missingError {
132 t.Errorf("Fetching missing blobref %v; want %q", got, missingError)
133 }
134
135 ctx := context.Background()
136 got, err := blobserver.StatBlobs(ctx, ts.sto, []blob.Ref{tb3.BlobRef(), tb.BlobRef(), tb2.BlobRef()})
137 if err != nil {
138 t.Fatalf("StatBlobs: %v", err)
139 }
140 if sr := got[tb.BlobRef()]; sr != tb.SizedRef() {
141 t.Errorf("tb stat = %v; want %v", sr, tb.SizedRef())
142 }
143 if sr := got[tb2.BlobRef()]; sr != tb2.SizedRef() {
144 t.Errorf("tb2 stat = %v; want %v", sr, tb2.SizedRef())
145 }
146 if sr, ok := got[tb3.BlobRef()]; ok {
147 t.Errorf("unexpected stat response for tb3: %v", sr)
148 }
149 if len(got) != 2 {
150 t.Errorf("unexpected blobs in stat response")
151 }
152
153 c := make(chan blob.SizedRef)
154 go func() {

Callers

nothing calls this directly

Calls 11

MustUploadMethod · 0.95
BlobRefMethod · 0.95
SizedRefMethod · 0.95
StatBlobsFunction · 0.92
fetchOrErrorStringMethod · 0.80
BlobContentsMethod · 0.80
ContainsMethod · 0.80
newTestStorageFunction · 0.70
EnumerateBlobsMethod · 0.65
FatalfMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected