|
4 | 4 | "errors" |
5 | 5 | "os" |
6 | 6 | "path/filepath" |
7 | | - "strings" |
8 | 7 | "syscall" |
9 | 8 |
|
10 | 9 | fakeblob "github.com/cloudfoundry/bosh-utils/blobstore/fakes" |
@@ -115,6 +114,12 @@ var _ = Describe("FSIndexBlobs", func() { |
115 | 114 | Expect(err).To(HaveOccurred()) |
116 | 115 | Expect(err.Error()).To(Equal("Cannot find blob named 'name' with SHA1 'sha1'")) |
117 | 116 | }) |
| 117 | + |
| 118 | + It("returns error if sha1 is a path", func() { |
| 119 | + _, err := blobs.Get("name", "blob-id", "../../file") |
| 120 | + Expect(err).To(HaveOccurred()) |
| 121 | + Expect(err.Error()).To(ContainSubstring("safe local path")) |
| 122 | + }) |
118 | 123 | }) |
119 | 124 |
|
120 | 125 | Context("when configured with a blobstore", func() { |
@@ -160,12 +165,10 @@ var _ = Describe("FSIndexBlobs", func() { |
160 | 165 | Expect(reporter.IndexEntryDownloadFinishedCallCount()).To(Equal(1)) |
161 | 166 | }) |
162 | 167 |
|
163 | | - It("returns error if parsing digest string fails", func() { |
164 | | - //currently, the only way to cause a digest parse failure is with an empty string |
| 168 | + It("returns error if sha1 is empty", func() { |
165 | 169 | _, err := blobs.Get("name", "blob-id", "") |
166 | 170 | Expect(err).To(HaveOccurred()) |
167 | | - Expect(strings.ToLower(err.Error())).To(ContainSubstring( |
168 | | - "no digest algorithm found. supported algorithms: sha1, sha256, sha512")) |
| 171 | + Expect(err.Error()).To(ContainSubstring("safe local path")) |
169 | 172 | }) |
170 | 173 |
|
171 | 174 | Context("when downloading blob fails", func() { |
@@ -284,6 +287,24 @@ var _ = Describe("FSIndexBlobs", func() { |
284 | 287 | Expect(err).ToNot(HaveOccurred()) |
285 | 288 | }) |
286 | 289 |
|
| 290 | + Context("when sha1 is a path", func() { |
| 291 | + BeforeEach(func() { |
| 292 | + blobs = boshidx.NewFSIndexBlobs(filepath.Join("/", "dir", "sub-dir"), reporter, nil, fs) |
| 293 | + }) |
| 294 | + |
| 295 | + It("returns error for a path with ..", func() { |
| 296 | + _, _, err := blobs.Add("name", filepath.Join("/", "tmp", "payload"), "../../.file") |
| 297 | + Expect(err).To(HaveOccurred()) |
| 298 | + Expect(err.Error()).To(ContainSubstring("safe local path")) |
| 299 | + }) |
| 300 | + |
| 301 | + It("returns error for an absolute path sha1", func() { |
| 302 | + _, _, err := blobs.Add("name", filepath.Join("/", "tmp", "payload"), "/etc/file") |
| 303 | + Expect(err).To(HaveOccurred()) |
| 304 | + Expect(err.Error()).To(ContainSubstring("safe local path")) |
| 305 | + }) |
| 306 | + }) |
| 307 | + |
287 | 308 | itCopiesFileIntoDir := func() { |
288 | 309 | It("copies file into cache dir", func() { |
289 | 310 | blobID, path, err := blobs.Add("name", filepath.Join("/", "tmp", "sha1"), "sha1") |
|
0 commit comments