LDAP support for GetSchool

This commit is contained in:
Ralf Haferkamp
2022-12-21 15:38:14 +01:00
committed by Ralf Haferkamp
parent bc9f81cc23
commit 644d96e7ad
2 changed files with 43 additions and 1 deletions
+8 -1
View File
@@ -121,7 +121,14 @@ func (i *LDAP) DeleteSchool(ctx context.Context, id string) error {
// GetSchool implements the EducationBackend interface for the LDAP backend.
func (i *LDAP) GetSchool(ctx context.Context, nameOrID string, queryParam url.Values) (*libregraph.EducationSchool, error) {
return nil, errNotImplemented
logger := i.logger.SubloggerWithRequestID(ctx)
logger.Debug().Str("backend", "ldap").Msg("GetSchool")
e, err := i.getSchoolByID(nameOrID)
if err != nil {
return nil, err
}
return i.createSchoolModelFromLDAP(e), nil
}
// GetSchools implements the EducationBackend interface for the LDAP backend.
@@ -107,3 +107,38 @@ func TestDeleteSchool(t *testing.T) {
assert.NotNil(t, err)
assert.Equal(t, "itemNotFound", err.Error())
}
func TestGetSchool(t *testing.T) {
lm := &mocks.Client{}
sr1 := &ldap.SearchRequest{
BaseDN: "",
Scope: 2,
SizeLimit: 1,
Filter: "(&(objectClass=ocEducationSchool)(owncloudUUID=abcd-defg))",
Attributes: []string{"ou", "owncloudUUID", "ocEducationSchoolNumber"},
Controls: []ldap.Control(nil),
}
sr2 := &ldap.SearchRequest{
BaseDN: "",
Scope: 2,
SizeLimit: 1,
Filter: "(&(objectClass=ocEducationSchool)(owncloudUUID=xxxx-xxxx))",
Attributes: []string{"ou", "owncloudUUID", "ocEducationSchoolNumber"},
Controls: []ldap.Control(nil),
}
lm.On("Search", sr1).Return(&ldap.SearchResult{Entries: []*ldap.Entry{schoolEntry}}, nil)
lm.On("Search", sr2).Return(&ldap.SearchResult{Entries: []*ldap.Entry{}}, nil)
b, err := getMockedBackend(lm, eduConfig, &logger)
assert.Nil(t, err)
school, err := b.GetSchool(context.Background(), "abcd-defg", nil)
lm.AssertNumberOfCalls(t, "Search", 1)
assert.Nil(t, err)
assert.Equal(t, "Test School", school.GetDisplayName())
assert.Equal(t, "abcd-defg", school.GetId())
assert.Equal(t, "0123", school.GetSchoolNumber())
school, err = b.GetSchool(context.Background(), "xxxx-xxxx", nil)
lm.AssertNumberOfCalls(t, "Search", 2)
assert.NotNil(t, err)
assert.Equal(t, "itemNotFound", err.Error())
}