bump libre graph api

Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
This commit is contained in:
Jörn Friedrich Dreyer
2024-08-19 14:20:20 +02:00
parent eac382aebb
commit a3c7bd3182
46 changed files with 932 additions and 190 deletions
+3 -3
View File
@@ -32,7 +32,7 @@ type Backend interface {
// DeleteUser deletes a given user, identified by username or id, from the backend
DeleteUser(ctx context.Context, nameOrID string) error
// UpdateUser applies changes to given user, identified by username or id
UpdateUser(ctx context.Context, nameOrID string, user libregraph.User) (*libregraph.User, error)
UpdateUser(ctx context.Context, nameOrID string, user libregraph.UserUpdate) (*libregraph.User, error)
GetUser(ctx context.Context, nameOrID string, oreq *godata.GoDataRequest) (*libregraph.User, error)
GetUsers(ctx context.Context, oreq *godata.GoDataRequest) ([]*libregraph.User, error)
@@ -124,9 +124,9 @@ func CreateUserModelFromCS3(u *cs3user.User) *libregraph.User {
},
},
UserType: &userType,
DisplayName: &u.DisplayName,
DisplayName: u.DisplayName,
Mail: &u.Mail,
OnPremisesSamAccountName: &u.Username,
OnPremisesSamAccountName: u.Username,
Id: &u.Id.OpaqueId,
}
}
+1 -1
View File
@@ -37,7 +37,7 @@ func (i *CS3) DeleteUser(ctx context.Context, nameOrID string) error {
}
// UpdateUser implements the Backend Interface. It's currently not supported for the CS3 backend
func (i *CS3) UpdateUser(ctx context.Context, nameOrID string, user libregraph.User) (*libregraph.User, error) {
func (i *CS3) UpdateUser(ctx context.Context, nameOrID string, user libregraph.UserUpdate) (*libregraph.User, error) {
return nil, errNotImplemented
}
+6 -6
View File
@@ -264,7 +264,7 @@ func (i *LDAP) DeleteUser(ctx context.Context, nameOrID string) error {
}
// UpdateUser implements the Backend Interface for the LDAP Backend
func (i *LDAP) UpdateUser(ctx context.Context, nameOrID string, user libregraph.User) (*libregraph.User, error) {
func (i *LDAP) UpdateUser(ctx context.Context, nameOrID string, user libregraph.UserUpdate) (*libregraph.User, error) {
logger := i.logger.SubloggerWithRequestID(ctx)
logger.Debug().Str("backend", "ldap").Msg("UpdateUser")
if !i.writeEnabled {
@@ -804,9 +804,9 @@ func (i *LDAP) createUserModelFromLDAP(e *ldap.Entry) *libregraph.User {
if id != "" && opsan != "" {
user := &libregraph.User{
DisplayName: pointerOrNil(e.GetEqualFoldAttributeValue(i.userAttributeMap.displayName)),
DisplayName: e.GetEqualFoldAttributeValue(i.userAttributeMap.displayName),
Mail: pointerOrNil(e.GetEqualFoldAttributeValue(i.userAttributeMap.mail)),
OnPremisesSamAccountName: &opsan,
OnPremisesSamAccountName: opsan,
Id: &id,
GivenName: pointerOrNil(e.GetEqualFoldAttributeValue(i.userAttributeMap.givenName)),
Surname: &surname,
@@ -874,7 +874,7 @@ func (i *LDAP) userToLDAPAttrValues(user libregraph.User) (map[string][]string,
if user.Surname != nil && *user.Surname != "" {
sn = *user.Surname
} else {
sn = *user.OnPremisesSamAccountName
sn = user.OnPremisesSamAccountName
}
attrs[i.userAttributeMap.surname] = []string{sn}
@@ -921,7 +921,7 @@ func (i *LDAP) getUserAttrTypes() []string {
func (i *LDAP) getUserLDAPDN(user libregraph.User) string {
attributeTypeAndValue := ldap.AttributeTypeAndValue{
Type: "uid",
Value: *user.OnPremisesSamAccountName,
Value: user.OnPremisesSamAccountName,
}
return fmt.Sprintf("%s,%s", attributeTypeAndValue.String(), i.userBaseDN)
}
@@ -1256,7 +1256,7 @@ func (i *LDAP) mapLDAPError(err error, errmap ldapResultToErrMap) errorcode.Erro
return errorcode.New(errorcode.GeneralException, err.Error())
}
func isUserEnabledUpdate(user libregraph.User) bool {
func isUserEnabledUpdate(user libregraph.UserUpdate) bool {
switch {
case user.Id != nil, user.DisplayName != nil,
user.Drive != nil, user.Mail != nil, user.OnPremisesSamAccountName != nil,
@@ -511,7 +511,7 @@ func TestLDAP_UpdateEducationClass(t *testing.T) {
args: args{
id: "abcd-defg",
class: libregraph.EducationClass{
Members: []libregraph.User{*libregraph.NewUser()},
Members: []libregraph.User{*libregraph.NewUser("display name", "username")},
},
},
assertion: func(tt assert.TestingT, err error, i ...interface{}) bool { return assert.Error(tt, err) },
@@ -250,12 +250,10 @@ func (i *LDAP) GetEducationUsers(ctx context.Context) ([]*libregraph.EducationUs
}
func (i *LDAP) educationUserToUser(eduUser libregraph.EducationUser) *libregraph.User {
user := libregraph.NewUser()
user.OnPremisesSamAccountName = eduUser.OnPremisesSamAccountName
user := libregraph.NewUser(*eduUser.DisplayName, *eduUser.OnPremisesSamAccountName)
user.Surname = eduUser.Surname
user.AccountEnabled = eduUser.AccountEnabled
user.GivenName = eduUser.GivenName
user.DisplayName = eduUser.DisplayName
user.Mail = eduUser.Mail
user.UserType = eduUser.UserType
user.Identities = eduUser.Identities
@@ -266,11 +264,11 @@ func (i *LDAP) educationUserToUser(eduUser libregraph.EducationUser) *libregraph
func (i *LDAP) userToEducationUser(user libregraph.User, e *ldap.Entry) *libregraph.EducationUser {
eduUser := libregraph.NewEducationUser()
eduUser.Id = user.Id
eduUser.OnPremisesSamAccountName = user.OnPremisesSamAccountName
eduUser.OnPremisesSamAccountName = &user.OnPremisesSamAccountName
eduUser.Surname = user.Surname
eduUser.AccountEnabled = user.AccountEnabled
eduUser.GivenName = user.GivenName
eduUser.DisplayName = user.DisplayName
eduUser.DisplayName = &user.DisplayName
eduUser.Mail = user.Mail
eduUser.UserType = user.UserType
+8 -10
View File
@@ -135,10 +135,8 @@ func TestCreateUser(t *testing.T) {
l.On("Add", ar).Return(nil)
logger := log.NewLogger(log.Level("debug"))
user := libregraph.NewUser()
user.SetDisplayName(displayName)
user := libregraph.NewUser(displayName, userName)
user.SetMail(mail)
user.SetOnPremisesSamAccountName(userName)
user.SetSurname(surname)
user.SetGivenName(givenName)
user.SetAccountEnabled(true)
@@ -171,14 +169,14 @@ func TestCreateUserModelFromLDAP(t *testing.T) {
if user == nil {
t.Error("Converting a valid LDAP Entry should succeed")
} else {
if *user.OnPremisesSamAccountName != userEntry.GetEqualFoldAttributeValue(b.userAttributeMap.userName) {
if user.OnPremisesSamAccountName != userEntry.GetEqualFoldAttributeValue(b.userAttributeMap.userName) {
t.Errorf("Error creating msGraph User from LDAP Entry: %v != %v", user.OnPremisesSamAccountName, pointerOrNil(userEntry.GetEqualFoldAttributeValue(b.userAttributeMap.userName)))
}
if *user.Mail != userEntry.GetEqualFoldAttributeValue(b.userAttributeMap.mail) {
t.Errorf("Error creating msGraph User from LDAP Entry: %s != %s", *user.Mail, userEntry.GetEqualFoldAttributeValue(b.userAttributeMap.mail))
}
if *user.DisplayName != userEntry.GetEqualFoldAttributeValue(b.userAttributeMap.displayName) {
t.Errorf("Error creating msGraph User from LDAP Entry: %s != %s", *user.DisplayName, userEntry.GetEqualFoldAttributeValue(b.userAttributeMap.displayName))
if user.DisplayName != userEntry.GetEqualFoldAttributeValue(b.userAttributeMap.displayName) {
t.Errorf("Error creating msGraph User from LDAP Entry: %s != %s", user.DisplayName, userEntry.GetEqualFoldAttributeValue(b.userAttributeMap.displayName))
}
if *user.Id != userEntry.GetEqualFoldAttributeValue(b.userAttributeMap.id) {
t.Errorf("Error creating msGraph User from LDAP Entry: %s != %s", *user.Id, userEntry.GetEqualFoldAttributeValue(b.userAttributeMap.id))
@@ -1447,7 +1445,7 @@ func TestUpdateUser(t *testing.T) {
ldapConfig.DisableUserMechanism = tt.args.disableUserMechanism
i, _ := getMockedBackend(lm, ldapConfig, &logger)
user := libregraph.User{
user := libregraph.UserUpdate{
Id: &tt.args.userProps.id,
Mail: &tt.args.userProps.mail,
DisplayName: &tt.args.userProps.displayName,
@@ -1462,15 +1460,15 @@ func TestUpdateUser(t *testing.T) {
want = &libregraph.User{
Id: &tt.want.id,
Mail: &tt.want.mail,
DisplayName: &tt.want.displayName,
OnPremisesSamAccountName: &tt.want.onPremisesSamAccountName,
DisplayName: tt.want.displayName,
OnPremisesSamAccountName: tt.want.onPremisesSamAccountName,
Surname: &emptyString,
GivenName: tt.want.givenName,
UserType: tt.want.userType,
}
if tt.want.accountEnabled != nil {
want.AccountEnabled = *&tt.want.accountEnabled
want.AccountEnabled = tt.want.accountEnabled
}
}
+9 -9
View File
@@ -1,4 +1,4 @@
// Code generated by mockery v2.40.2. DO NOT EDIT.
// Code generated by mockery v2.43.2. DO NOT EDIT.
package mocks
@@ -682,7 +682,7 @@ func (_c *Backend_UpdateGroupName_Call) RunAndReturn(run func(context.Context, s
}
// UpdateUser provides a mock function with given fields: ctx, nameOrID, user
func (_m *Backend) UpdateUser(ctx context.Context, nameOrID string, user libregraph.User) (*libregraph.User, error) {
func (_m *Backend) UpdateUser(ctx context.Context, nameOrID string, user libregraph.UserUpdate) (*libregraph.User, error) {
ret := _m.Called(ctx, nameOrID, user)
if len(ret) == 0 {
@@ -691,10 +691,10 @@ func (_m *Backend) UpdateUser(ctx context.Context, nameOrID string, user libregr
var r0 *libregraph.User
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, string, libregraph.User) (*libregraph.User, error)); ok {
if rf, ok := ret.Get(0).(func(context.Context, string, libregraph.UserUpdate) (*libregraph.User, error)); ok {
return rf(ctx, nameOrID, user)
}
if rf, ok := ret.Get(0).(func(context.Context, string, libregraph.User) *libregraph.User); ok {
if rf, ok := ret.Get(0).(func(context.Context, string, libregraph.UserUpdate) *libregraph.User); ok {
r0 = rf(ctx, nameOrID, user)
} else {
if ret.Get(0) != nil {
@@ -702,7 +702,7 @@ func (_m *Backend) UpdateUser(ctx context.Context, nameOrID string, user libregr
}
}
if rf, ok := ret.Get(1).(func(context.Context, string, libregraph.User) error); ok {
if rf, ok := ret.Get(1).(func(context.Context, string, libregraph.UserUpdate) error); ok {
r1 = rf(ctx, nameOrID, user)
} else {
r1 = ret.Error(1)
@@ -719,14 +719,14 @@ type Backend_UpdateUser_Call struct {
// UpdateUser is a helper method to define mock.On call
// - ctx context.Context
// - nameOrID string
// - user libregraph.User
// - user libregraph.UserUpdate
func (_e *Backend_Expecter) UpdateUser(ctx interface{}, nameOrID interface{}, user interface{}) *Backend_UpdateUser_Call {
return &Backend_UpdateUser_Call{Call: _e.mock.On("UpdateUser", ctx, nameOrID, user)}
}
func (_c *Backend_UpdateUser_Call) Run(run func(ctx context.Context, nameOrID string, user libregraph.User)) *Backend_UpdateUser_Call {
func (_c *Backend_UpdateUser_Call) Run(run func(ctx context.Context, nameOrID string, user libregraph.UserUpdate)) *Backend_UpdateUser_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(context.Context), args[1].(string), args[2].(libregraph.User))
run(args[0].(context.Context), args[1].(string), args[2].(libregraph.UserUpdate))
})
return _c
}
@@ -736,7 +736,7 @@ func (_c *Backend_UpdateUser_Call) Return(_a0 *libregraph.User, _a1 error) *Back
return _c
}
func (_c *Backend_UpdateUser_Call) RunAndReturn(run func(context.Context, string, libregraph.User) (*libregraph.User, error)) *Backend_UpdateUser_Call {
func (_c *Backend_UpdateUser_Call) RunAndReturn(run func(context.Context, string, libregraph.UserUpdate) (*libregraph.User, error)) *Backend_UpdateUser_Call {
_c.Call.Return(run)
return _c
}
@@ -1,4 +1,4 @@
// Code generated by mockery v2.40.2. DO NOT EDIT.
// Code generated by mockery v2.43.2. DO NOT EDIT.
package mocks
@@ -1,4 +1,4 @@
// Code generated by mockery v2.40.2. DO NOT EDIT.
// Code generated by mockery v2.43.2. DO NOT EDIT.
package mocks