(t *testing.T)
| 95 | } |
| 96 | |
| 97 | func 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() { |
nothing calls this directly
no test coverage detected