LDAP support for GetSchool
This commit is contained in:
committed by
Ralf Haferkamp
parent
bc9f81cc23
commit
644d96e7ad
@@ -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())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user