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

Fixed bug in eof check for client uploader. #645

Merged
merged 2 commits into from
Sep 22, 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
2 changes: 1 addition & 1 deletion uploads/client_uploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (self *VelociraptorUploader) Upload(
// iteration to prevent overwriting in flight buffers.
buffer := make([]byte, BUFF_SIZE)
read_bytes, err := reader.Read(buffer)
if err != nil {
if err != nil && err != io.EOF {
return nil, err
}

Expand Down
34 changes: 34 additions & 0 deletions uploads/client_uploader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package uploads
import (
"bytes"
"context"
"io/ioutil"
"os"
"testing"

"github.com/sebdah/goldie"
Expand Down Expand Up @@ -109,6 +111,38 @@ func TestClientUploaderSparseWithEOF(t *testing.T) {
assert.Equal(t, CombineOutput("foo", responses), "Hello hi")
}

func TestClientUploader(t *testing.T) {
responder_obj := responder.TestResponder()
uploader := &VelociraptorUploader{
Responder: responder_obj,
}

BUFF_SIZE = 10

tmpfile, err := ioutil.TempFile("", "tmp*")
assert.NoError(t, err)
defer os.Remove(tmpfile.Name())

_, err = tmpfile.Write([]byte("Hello world"))
assert.NoError(t, err)

name := tmpfile.Name()
tmpfile.Close()

fd, err := os.Open(name)
assert.NoError(t, err)

ctx := context.Background()
scope := vql_subsystem.MakeScope()

resp, err := uploader.Upload(ctx, scope, name, "file", "", 1000, fd)
assert.NoError(t, err)
assert.Equal(t, resp.Path, name)
assert.Equal(t, resp.Size, uint64(11))
assert.Equal(t, resp.StoredSize, uint64(11))
assert.Equal(t, resp.Error, "")
}

// Trying to upload a completely sparse file with no data but real
// size.
func TestClientUploaderCompletelySparse(t *testing.T) {
Expand Down