Merge pull request #1326 from greut/add-to-err-on-404

add should fail on 40x
This commit is contained in:
Tejal Desai 2020-07-28 21:30:29 -07:00 committed by GitHub
commit 92917bab3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 44 additions and 0 deletions

View File

@ -0,0 +1,4 @@
FROM debian:9.11
# Testing that any HTTP failure is handled properly
ADD https://httpstat.us/404 .

View File

@ -167,6 +167,7 @@ type DockerFileBuilder struct {
func NewDockerFileBuilder() *DockerFileBuilder {
d := DockerFileBuilder{filesBuilt: map[string]struct{}{}}
d.DockerfilesToIgnore = map[string]struct{}{
"Dockerfile_test_add_404": {},
// TODO: remove test_user_run from this when https://github.com/GoogleContainerTools/container-diff/issues/237 is fixed
"Dockerfile_test_user_run": {},
}

View File

@ -386,6 +386,40 @@ func TestBuildWithLabels(t *testing.T) {
checkContainerDiffOutput(t, diff, expected)
}
func TestBuildWithHTTPError(t *testing.T) {
repo := getGitRepo()
dockerfile := fmt.Sprintf("%s/%s/Dockerfile_test_add_404", integrationPath, dockerfilesPath)
// Build with docker
dockerImage := GetDockerImage(config.imageRepo, "Dockerfile_test_add_404")
dockerCmd := exec.Command("docker",
append([]string{"build",
"-t", dockerImage,
"-f", dockerfile,
repo})...)
out, err := RunCommandWithoutTest(dockerCmd)
if err == nil {
t.Errorf("an error was expected, got %s", string(out))
}
// Build with kaniko
kanikoImage := GetKanikoImage(config.imageRepo, "Dockerfile_test_add_404")
dockerRunFlags := []string{"run", "--net=host"}
dockerRunFlags = addServiceAccountFlags(dockerRunFlags, config.serviceAccount)
dockerRunFlags = append(dockerRunFlags, ExecutorImage,
"-f", dockerfile,
"-d", kanikoImage,
"-c", fmt.Sprintf("git://%s", repo),
)
kanikoCmd := exec.Command("docker", dockerRunFlags...)
out, err = RunCommandWithoutTest(kanikoCmd)
if err == nil {
t.Errorf("an error was expected, got %s", string(out))
}
}
func TestLayers(t *testing.T) {
offset := map[string]int{
"Dockerfile_test_add": 12,

View File

@ -545,6 +545,11 @@ func DownloadFileToDest(rawurl, dest string, uid, gid int64) error {
return err
}
defer resp.Body.Close()
if resp.StatusCode >= 400 {
return fmt.Errorf("invalid response status %d", resp.StatusCode)
}
if err := CreateFile(dest, resp.Body, 0600, uint32(uid), uint32(gid)); err != nil {
return err
}