Skip to content

Commit 119ceb8

Browse files
fix: rootless permission bits (new actions cache) (#2242)
* fix: rootless permission bits (new actions cache) * add test * fix lint / more tests
1 parent 352ad41 commit 119ceb8

File tree

2 files changed

+80
-1
lines changed

2 files changed

+80
-1
lines changed

pkg/container/docker_run.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ func (cr *containerReference) CopyTarStream(ctx context.Context, destPath string
679679
tw := tar.NewWriter(buf)
680680
_ = tw.WriteHeader(&tar.Header{
681681
Name: destPath,
682-
Mode: 777,
682+
Mode: 0o777,
683683
Typeflag: tar.TypeDir,
684684
})
685685
tw.Close()

pkg/container/docker_run_test.go

+79
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package container
22

33
import (
44
"bufio"
5+
"bytes"
56
"context"
7+
"fmt"
68
"io"
79
"net"
810
"strings"
@@ -75,6 +77,11 @@ func (m *mockDockerClient) ContainerExecInspect(ctx context.Context, execID stri
7577
return args.Get(0).(types.ContainerExecInspect), args.Error(1)
7678
}
7779

80+
func (m *mockDockerClient) CopyToContainer(ctx context.Context, id string, path string, content io.Reader, options types.CopyToContainerOptions) error {
81+
args := m.Called(ctx, id, path, content, options)
82+
return args.Error(0)
83+
}
84+
7885
type endlessReader struct {
7986
io.Reader
8087
}
@@ -165,5 +172,77 @@ func TestDockerExecFailure(t *testing.T) {
165172
client.AssertExpectations(t)
166173
}
167174

175+
func TestDockerCopyTarStream(t *testing.T) {
176+
ctx := context.Background()
177+
178+
conn := &mockConn{}
179+
180+
client := &mockDockerClient{}
181+
client.On("CopyToContainer", ctx, "123", "/", mock.Anything, mock.AnythingOfType("types.CopyToContainerOptions")).Return(nil)
182+
client.On("CopyToContainer", ctx, "123", "/var/run/act", mock.Anything, mock.AnythingOfType("types.CopyToContainerOptions")).Return(nil)
183+
cr := &containerReference{
184+
id: "123",
185+
cli: client,
186+
input: &NewContainerInput{
187+
Image: "image",
188+
},
189+
}
190+
191+
_ = cr.CopyTarStream(ctx, "/var/run/act", &bytes.Buffer{})
192+
193+
conn.AssertExpectations(t)
194+
client.AssertExpectations(t)
195+
}
196+
197+
func TestDockerCopyTarStreamErrorInCopyFiles(t *testing.T) {
198+
ctx := context.Background()
199+
200+
conn := &mockConn{}
201+
202+
merr := fmt.Errorf("Failure")
203+
204+
client := &mockDockerClient{}
205+
client.On("CopyToContainer", ctx, "123", "/", mock.Anything, mock.AnythingOfType("types.CopyToContainerOptions")).Return(merr)
206+
client.On("CopyToContainer", ctx, "123", "/", mock.Anything, mock.AnythingOfType("types.CopyToContainerOptions")).Return(merr)
207+
cr := &containerReference{
208+
id: "123",
209+
cli: client,
210+
input: &NewContainerInput{
211+
Image: "image",
212+
},
213+
}
214+
215+
err := cr.CopyTarStream(ctx, "/var/run/act", &bytes.Buffer{})
216+
assert.ErrorIs(t, err, merr)
217+
218+
conn.AssertExpectations(t)
219+
client.AssertExpectations(t)
220+
}
221+
222+
func TestDockerCopyTarStreamErrorInMkdir(t *testing.T) {
223+
ctx := context.Background()
224+
225+
conn := &mockConn{}
226+
227+
merr := fmt.Errorf("Failure")
228+
229+
client := &mockDockerClient{}
230+
client.On("CopyToContainer", ctx, "123", "/", mock.Anything, mock.AnythingOfType("types.CopyToContainerOptions")).Return(nil)
231+
client.On("CopyToContainer", ctx, "123", "/var/run/act", mock.Anything, mock.AnythingOfType("types.CopyToContainerOptions")).Return(merr)
232+
cr := &containerReference{
233+
id: "123",
234+
cli: client,
235+
input: &NewContainerInput{
236+
Image: "image",
237+
},
238+
}
239+
240+
err := cr.CopyTarStream(ctx, "/var/run/act", &bytes.Buffer{})
241+
assert.ErrorIs(t, err, merr)
242+
243+
conn.AssertExpectations(t)
244+
client.AssertExpectations(t)
245+
}
246+
168247
// Type assert containerReference implements ExecutionsEnvironment
169248
var _ ExecutionsEnvironment = &containerReference{}

0 commit comments

Comments
 (0)