2021-12-03 22:50:58 -05:00
|
|
|
//go:build extended
|
2021-11-10 09:31:03 -05:00
|
|
|
// +build extended
|
|
|
|
|
|
|
|
package test_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"path"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
. "github.com/smartystreets/goconvey/convey"
|
2022-01-19 14:54:17 -05:00
|
|
|
"zotregistry.io/zot/pkg/test"
|
2021-11-10 09:31:03 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestCopyFiles(t *testing.T) {
|
|
|
|
Convey("sourceDir does not exist", t, func() {
|
2022-01-19 14:54:17 -05:00
|
|
|
err := test.CopyFiles("/path/to/some/unexisting/directory", os.TempDir())
|
2021-11-10 09:31:03 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
|
|
|
Convey("destDir is a file", t, func() {
|
2022-03-07 03:55:12 -05:00
|
|
|
dir := t.TempDir()
|
2021-11-10 09:31:03 -05:00
|
|
|
|
2022-03-07 03:55:12 -05:00
|
|
|
err := test.CopyFiles("../../test/data", dir)
|
2021-11-10 09:31:03 -05:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2022-01-19 14:54:17 -05:00
|
|
|
err = test.CopyFiles(dir, "/etc/passwd")
|
2021-11-10 09:31:03 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
|
|
|
Convey("sourceDir does not have read permissions", t, func() {
|
2022-03-07 03:55:12 -05:00
|
|
|
dir := t.TempDir()
|
2021-11-10 09:31:03 -05:00
|
|
|
|
2022-03-07 03:55:12 -05:00
|
|
|
err := os.Chmod(dir, 0o300)
|
2021-11-10 09:31:03 -05:00
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
2022-01-19 14:54:17 -05:00
|
|
|
err = test.CopyFiles(dir, os.TempDir())
|
2021-11-10 09:31:03 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
|
|
|
Convey("sourceDir has a subfolder that does not have read permissions", t, func() {
|
2022-03-07 03:55:12 -05:00
|
|
|
dir := t.TempDir()
|
2021-11-10 09:31:03 -05:00
|
|
|
|
|
|
|
sdir := "subdir"
|
2022-03-07 03:55:12 -05:00
|
|
|
err := os.Mkdir(path.Join(dir, sdir), 0o300)
|
2021-11-10 09:31:03 -05:00
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
2022-01-19 14:54:17 -05:00
|
|
|
err = test.CopyFiles(dir, os.TempDir())
|
2021-11-10 09:31:03 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
|
|
|
Convey("sourceDir has a file that does not have read permissions", t, func() {
|
2022-03-07 03:55:12 -05:00
|
|
|
dir := t.TempDir()
|
2021-11-10 09:31:03 -05:00
|
|
|
|
|
|
|
filePath := path.Join(dir, "file.txt")
|
2022-03-07 03:55:12 -05:00
|
|
|
err := ioutil.WriteFile(filePath, []byte("some dummy file content"), 0o644) //nolint: gosec
|
2021-11-10 09:31:03 -05:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
err = os.Chmod(filePath, 0o300)
|
2021-11-10 09:31:03 -05:00
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
2022-01-19 14:54:17 -05:00
|
|
|
err = test.CopyFiles(dir, os.TempDir())
|
2021-11-10 09:31:03 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
|
|
|
}
|