Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add should fail on 40x #1326

Merged
merged 4 commits into from
Jul 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions integration/dockerfiles/Dockerfile_test_add_404
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM debian:9.11

# Testing that any HTTP failure is handled properly
ADD https://httpstat.us/404 .
1 change: 1 addition & 0 deletions integration/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -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": {},
}
Expand Down
34 changes: 34 additions & 0 deletions integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions pkg/util/fs_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down