AuthN: Readd user protection service to user sync (#61534)

* add user protection service to user sync

* fix tests
This commit is contained in:
Jo
2023-01-16 11:15:14 +00:00
committed by GitHub
parent dcfeab2c73
commit be3b81fecd
3 changed files with 31 additions and 24 deletions
@@ -4,10 +4,10 @@ import (
"context"
"testing"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/authn"
"github.com/grafana/grafana/pkg/services/login"
"github.com/grafana/grafana/pkg/services/login/authinfoservice"
"github.com/grafana/grafana/pkg/services/login/logintest"
"github.com/grafana/grafana/pkg/services/quota"
"github.com/grafana/grafana/pkg/services/quota/quotatest"
@@ -29,6 +29,8 @@ func ptrInt64(i int64) *int64 {
}
func TestUserSync_SyncUser(t *testing.T) {
userProtection := &authinfoservice.OSSUserProtectionImpl{}
authFakeNil := &logintest.AuthInfoServiceFake{
ExpectedUser: nil,
ExpectedError: user.ErrUserNotFound,
@@ -82,7 +84,6 @@ func TestUserSync_SyncUser(t *testing.T) {
userService user.Service
authInfoService login.AuthInfoService
quotaService quota.Service
log log.Logger
}
type args struct {
ctx context.Context
@@ -101,7 +102,6 @@ func TestUserSync_SyncUser(t *testing.T) {
userService: userService,
authInfoService: authFakeNil,
quotaService: &quotatest.FakeQuotaService{},
log: log.NewNopLogger(),
},
args: args{
ctx: context.Background(),
@@ -140,7 +140,6 @@ func TestUserSync_SyncUser(t *testing.T) {
userService: userService,
authInfoService: authFakeNil,
quotaService: &quotatest.FakeQuotaService{},
log: log.NewNopLogger(),
},
args: args{
ctx: context.Background(),
@@ -182,7 +181,6 @@ func TestUserSync_SyncUser(t *testing.T) {
userService: userService,
authInfoService: authFakeNil,
quotaService: &quotatest.FakeQuotaService{},
log: log.NewNopLogger(),
},
args: args{
ctx: context.Background(),
@@ -224,7 +222,6 @@ func TestUserSync_SyncUser(t *testing.T) {
userService: userService,
authInfoService: authFakeNil,
quotaService: &quotatest.FakeQuotaService{},
log: log.NewNopLogger(),
},
args: args{
ctx: context.Background(),
@@ -266,7 +263,6 @@ func TestUserSync_SyncUser(t *testing.T) {
userService: userService,
authInfoService: authFakeUserID,
quotaService: &quotatest.FakeQuotaService{},
log: log.NewNopLogger(),
},
args: args{
ctx: context.Background(),
@@ -309,7 +305,6 @@ func TestUserSync_SyncUser(t *testing.T) {
userService: userService,
authInfoService: authFakeNil,
quotaService: &quotatest.FakeQuotaService{},
log: log.NewNopLogger(),
},
args: args{
ctx: context.Background(),
@@ -338,7 +333,6 @@ func TestUserSync_SyncUser(t *testing.T) {
userService: userServiceNil,
authInfoService: authFakeNil,
quotaService: &quotatest.FakeQuotaService{},
log: log.NewNopLogger(),
},
args: args{
ctx: context.Background(),
@@ -389,7 +383,6 @@ func TestUserSync_SyncUser(t *testing.T) {
userService: userServiceMod,
authInfoService: authFakeNil,
quotaService: &quotatest.FakeQuotaService{},
log: log.NewNopLogger(),
},
args: args{
ctx: context.Background(),
@@ -433,12 +426,7 @@ func TestUserSync_SyncUser(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
s := &UserSync{
userService: tt.fields.userService,
authInfoService: tt.fields.authInfoService,
quotaService: tt.fields.quotaService,
log: tt.fields.log,
}
s := ProvideUserSync(tt.fields.userService, userProtection, tt.fields.authInfoService, tt.fields.quotaService)
err := s.SyncUser(tt.args.ctx, tt.args.id, nil)
if tt.wantErr {
require.Error(t, err)