Search users by username instead of by email

As some setups don't have email addresses setup or reuse email
addresses, the keycloak search has to be done by username as that
is guaranteed to always be unique and defined.

This PR changes that.
This commit is contained in:
Daniël Franke
2023-04-18 11:43:13 +02:00
parent 70f825541c
commit 30edab9f69
4 changed files with 86 additions and 18 deletions
+61 -7
View File
@@ -5,9 +5,11 @@ package mocks
import (
context "context"
libregraph "github.com/owncloud/libre-graph-api-go"
gocloak "github.com/Nerzal/gocloak/v13"
keycloak "github.com/owncloud/ocis/v2/ocis-pkg/keycloak"
libregraph "github.com/owncloud/libre-graph-api-go"
mock "github.com/stretchr/testify/mock"
)
@@ -40,17 +42,17 @@ func (_m *Client) CreateUser(ctx context.Context, realm string, user *libregraph
return r0, r1
}
// GetPIIReport provides a mock function with given fields: ctx, realm, email
func (_m *Client) GetPIIReport(ctx context.Context, realm string, email string) (*keycloak.PIIReport, error) {
ret := _m.Called(ctx, realm, email)
// GetPIIReport provides a mock function with given fields: ctx, realm, username
func (_m *Client) GetPIIReport(ctx context.Context, realm string, username string) (*keycloak.PIIReport, error) {
ret := _m.Called(ctx, realm, username)
var r0 *keycloak.PIIReport
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, string, string) (*keycloak.PIIReport, error)); ok {
return rf(ctx, realm, email)
return rf(ctx, realm, username)
}
if rf, ok := ret.Get(0).(func(context.Context, string, string) *keycloak.PIIReport); ok {
r0 = rf(ctx, realm, email)
r0 = rf(ctx, realm, username)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*keycloak.PIIReport)
@@ -58,7 +60,7 @@ func (_m *Client) GetPIIReport(ctx context.Context, realm string, email string)
}
if rf, ok := ret.Get(1).(func(context.Context, string, string) error); ok {
r1 = rf(ctx, realm, email)
r1 = rf(ctx, realm, username)
} else {
r1 = ret.Error(1)
}
@@ -92,6 +94,58 @@ func (_m *Client) GetUserByEmail(ctx context.Context, realm string, email string
return r0, r1
}
// GetUserByParams provides a mock function with given fields: ctx, realm, params
func (_m *Client) GetUserByParams(ctx context.Context, realm string, params gocloak.GetUsersParams) (*libregraph.User, error) {
ret := _m.Called(ctx, realm, params)
var r0 *libregraph.User
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, string, gocloak.GetUsersParams) (*libregraph.User, error)); ok {
return rf(ctx, realm, params)
}
if rf, ok := ret.Get(0).(func(context.Context, string, gocloak.GetUsersParams) *libregraph.User); ok {
r0 = rf(ctx, realm, params)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*libregraph.User)
}
}
if rf, ok := ret.Get(1).(func(context.Context, string, gocloak.GetUsersParams) error); ok {
r1 = rf(ctx, realm, params)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// GetUserByUsername provides a mock function with given fields: ctx, realm, username
func (_m *Client) GetUserByUsername(ctx context.Context, realm string, username string) (*libregraph.User, error) {
ret := _m.Called(ctx, realm, username)
var r0 *libregraph.User
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, string, string) (*libregraph.User, error)); ok {
return rf(ctx, realm, username)
}
if rf, ok := ret.Get(0).(func(context.Context, string, string) *libregraph.User); ok {
r0 = rf(ctx, realm, username)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*libregraph.User)
}
}
if rf, ok := ret.Get(1).(func(context.Context, string, string) error); ok {
r1 = rf(ctx, realm, username)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// SendActionsMail provides a mock function with given fields: ctx, realm, userID, userActions
func (_m *Client) SendActionsMail(ctx context.Context, realm string, userID string, userActions []keycloak.UserAction) error {
ret := _m.Called(ctx, realm, userID, userActions)