-
-
Notifications
You must be signed in to change notification settings - Fork 511
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
115 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,7 +73,9 @@ func TestOpenLDAPWithDifferentRoot(t *testing.T) { | |
} | ||
}) | ||
|
||
// connectionString { | ||
connectionString, err := container.ConnectionString(ctx) | ||
// } | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
@@ -90,3 +92,70 @@ func TestOpenLDAPWithDifferentRoot(t *testing.T) { | |
t.Fatal(err) | ||
} | ||
} | ||
|
||
func TestOpenLDAPWithLdif(t *testing.T) { | ||
ctx := context.Background() | ||
|
||
container, err := RunContainer(ctx, testcontainers.WithImage("bitnami/openldap:2.6.6")) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
// Clean up the container after the test is complete | ||
t.Cleanup(func() { | ||
if err := container.Terminate(ctx); err != nil { | ||
t.Fatalf("failed to terminate container: %s", err) | ||
} | ||
}) | ||
|
||
// loadLdif { | ||
ldif := ` | ||
dn: uid=test.user,ou=users,dc=example,dc=org | ||
changetype: add | ||
objectclass: iNetOrgPerson | ||
cn: Test User | ||
sn: Test | ||
mail: [email protected] | ||
userPassword: Password1 | ||
` | ||
|
||
err = container.LoadLdif(ctx, []byte(ldif)) | ||
// } | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
connectionString, err := container.ConnectionString(ctx) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
client, err := ldap.DialURL(connectionString) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer client.Close() | ||
|
||
// First bind with a read only user | ||
err = client.Bind("cn=admin,dc=example,dc=org", "adminpassword") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
result, err := client.Search(&ldap.SearchRequest{ | ||
BaseDN: "uid=test.user,ou=users,dc=example,dc=org", | ||
Scope: ldap.ScopeWholeSubtree, | ||
Filter: "(objectClass=*)", | ||
Attributes: []string{"dn"}, | ||
}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if len(result.Entries) != 1 { | ||
t.Fatal("Invalid number of entries returned", result.Entries) | ||
} | ||
if result.Entries[0].DN != "uid=test.user,ou=users,dc=example,dc=org" { | ||
t.Fatal("Invalid entry returned", result.Entries[0].DN) | ||
} | ||
} |