Skip to content

Commit

Permalink
events search: improve test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
drakkan committed Dec 4, 2021
1 parent 78eb1c1 commit 9632b6e
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 37 deletions.
22 changes: 22 additions & 0 deletions httpd/httpd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5774,6 +5774,17 @@ func TestSearchEvents(t *testing.T) {
setBearerForReq(req, token)
rr := executeRequest(req)
checkResponseCode(t, http.StatusOK, rr)
events := make([]map[string]interface{}, 0)
err = json.Unmarshal(rr.Body.Bytes(), &events)
assert.NoError(t, err)
if assert.Len(t, events, 1) {
ev := events[0]
for _, field := range []string{"id", "timestamp", "action", "username", "fs_path", "status", "protocol",
"ip", "session_id", "instance_id"} {
_, ok := ev[field]
assert.True(t, ok, field)
}
}

// the test eventsearcher plugin returns error if start_timestamp < 0
req, err = http.NewRequest(http.MethodGet, fsEventsPath+"?start_timestamp=-1&end_timestamp=123456&statuses=1,2", nil)
Expand All @@ -5793,6 +5804,17 @@ func TestSearchEvents(t *testing.T) {
setBearerForReq(req, token)
rr = executeRequest(req)
checkResponseCode(t, http.StatusOK, rr)
events = make([]map[string]interface{}, 0)
err = json.Unmarshal(rr.Body.Bytes(), &events)
assert.NoError(t, err)
if assert.Len(t, events, 1) {
ev := events[0]
for _, field := range []string{"id", "timestamp", "action", "username", "object_type", "object_name",
"object_data", "instance_id"} {
_, ok := ev[field]
assert.True(t, ok, field)
}
}

// the test eventsearcher plugin returns error if start_timestamp < 0
req, err = http.NewRequest(http.MethodGet, providerEventsPath+"?start_timestamp=-1", nil)
Expand Down
12 changes: 6 additions & 6 deletions tests/eventsearcher/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/drakkan/sftpgo/tests/eventsearcher
go 1.17

require (
github.com/drakkan/sftpgo/v2 v2.1.1-0.20211020173949-97d0a4855756
github.com/drakkan/sftpgo/v2 v2.2.1-0.20211204162724-a7c0b07a2ab8
github.com/hashicorp/go-plugin v1.4.3
)

Expand All @@ -12,15 +12,15 @@ require (
github.com/golang/protobuf v1.5.2 // indirect
github.com/hashicorp/go-hclog v1.0.0 // indirect
github.com/hashicorp/yamux v0.0.0-20211028200310-0bc27b27de87 // indirect
github.com/mattn/go-colorable v0.1.11 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/oklog/run v1.1.0 // indirect
golang.org/x/net v0.0.0-20211020060615-d418f374d309 // indirect
golang.org/x/sys v0.0.0-20211029165221-6e7872819dc8 // indirect
golang.org/x/net v0.0.0-20211201190559-0a0e4e1bb54c // indirect
golang.org/x/sys v0.0.0-20211124211545-fe61309f8881 // indirect
golang.org/x/text v0.3.7 // indirect
google.golang.org/genproto v0.0.0-20211029142109-e255c875f7c7 // indirect
google.golang.org/grpc v1.41.0 // indirect
google.golang.org/genproto v0.0.0-20211129164237-f09f9a12af12 // indirect
google.golang.org/grpc v1.42.0 // indirect
google.golang.org/protobuf v1.27.1 // indirect
)

Expand Down
Loading

0 comments on commit 9632b6e

Please sign in to comment.