mirror of
https://github.com/empayre/fleet.git
synced 2024-11-07 01:15:22 +00:00
9dba07395b
* check for errors when setting test logs on new services * fix tests that fail because a log file wasn't specified * remove unnecessary nil check
40 lines
1.0 KiB
Go
40 lines
1.0 KiB
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/fleetdm/fleet/v4/server/authz"
|
|
"github.com/fleetdm/fleet/v4/server/fleet"
|
|
"github.com/fleetdm/fleet/v4/server/mock"
|
|
"github.com/fleetdm/fleet/v4/server/test"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestListActivities(t *testing.T) {
|
|
ds := new(mock.Store)
|
|
svc := newTestService(t, ds, nil, nil)
|
|
|
|
ds.ListActivitiesFunc = func(ctx context.Context, opts fleet.ListOptions) ([]*fleet.Activity, error) {
|
|
return []*fleet.Activity{
|
|
{ID: 1},
|
|
{ID: 2},
|
|
}, nil
|
|
}
|
|
|
|
// admin user
|
|
activities, err := svc.ListActivities(test.UserContext(test.UserAdmin), fleet.ListOptions{})
|
|
require.NoError(t, err)
|
|
require.Len(t, activities, 2)
|
|
|
|
// anyone can read activities
|
|
activities, err = svc.ListActivities(test.UserContext(test.UserNoRoles), fleet.ListOptions{})
|
|
require.NoError(t, err)
|
|
require.Len(t, activities, 2)
|
|
|
|
// no user in context
|
|
_, err = svc.ListActivities(context.Background(), fleet.ListOptions{})
|
|
require.Error(t, err)
|
|
require.Contains(t, err.Error(), authz.ForbiddenErrorMessage)
|
|
}
|