From 1dc6fa096ca7e7b30651f82170ac7fffc3711e6c Mon Sep 17 00:00:00 2001 From: Julian Koberg Date: Wed, 25 Feb 2026 16:12:57 +0100 Subject: [PATCH] test: let (ai) add a test for it Signed-off-by: Julian Koberg --- .../graph/pkg/identity/ldap_group_test.go | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/services/graph/pkg/identity/ldap_group_test.go b/services/graph/pkg/identity/ldap_group_test.go index a7efaf95581..634de7af5a3 100644 --- a/services/graph/pkg/identity/ldap_group_test.go +++ b/services/graph/pkg/identity/ldap_group_test.go @@ -8,6 +8,7 @@ import ( "github.com/CiscoM31/godata" "github.com/go-ldap/ldap/v3" + libregraph "github.com/owncloud/libre-graph-api-go" "github.com/owncloud/ocis/v2/services/graph/pkg/identity/mocks" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" @@ -451,3 +452,63 @@ func TestUpdateGroupName(t *testing.T) { }) } } + +func TestGroupToLDAPAttrValuesUsesConfiguredObjectClass(t *testing.T) { + tests := []struct { + name string + groupObjectClass string + }{ + { + name: "default groupOfNames", + groupObjectClass: "groupOfNames", + }, + { + name: "custom groupOfUniqueNames", + groupObjectClass: "groupOfUniqueNames", + }, + { + name: "custom posixGroup", + groupObjectClass: "posixGroup", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + // Setup config with custom groupObjectClass + testConfig := lconfig + testConfig.GroupObjectClass = tt.groupObjectClass + + lm := &mocks.Client{} + b, err := getMockedBackend(lm, testConfig, &logger) + if err != nil { + t.Fatalf("Failed to create backend: %s", err.Error()) + } + + // Create test group + group := libregraph.Group{} + displayName := "Test Group" + group.SetDisplayName(displayName) + + // Get LDAP attributes + attrs, err := b.groupToLDAPAttrValues(group) + if err != nil { + t.Fatalf("Expected groupToLDAPAttrValues to succeed, got error: %s", err.Error()) + } + + objectClasses, ok := attrs["objectClass"] + if !ok { + t.Fatal("Expected objectClass attribute to be present") + } + + // Check objectClass has exactly 3 elements + if len(objectClasses) != 3 { + t.Errorf("Expected objectClass to have exactly 3 elements, got %d: %v", len(objectClasses), objectClasses) + } + + // Check first element is the configured groupObjectClass (exact match) + if objectClasses[0] != tt.groupObjectClass { + t.Errorf("Expected first objectClass to be '%s', got '%s'", tt.groupObjectClass, objectClasses[0]) + } + }) + } +}