Skip to content

Commit

Permalink
testdirectory: handle IPv6 addresses (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
johanbrandhorst authored Aug 29, 2024
1 parent 213472b commit 2a5a684
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions testdirectory/directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ func Start(t TestingT, opt ...Option) *Directory {
if opts.withPort == 0 {
opts.withPort = FreePort(t)
}
// Handle IPv6 addresses
if strings.Contains(opts.withHost, ":") && !strings.ContainsAny(opts.withHost, "[]") {
opts.withHost = "[" + opts.withHost + "]"
}

d := &Directory{
t: t,
Expand Down
23 changes: 23 additions & 0 deletions testdirectory/directory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,25 @@ func Test_Start(t *testing.T) {
// not sure there's anything that's assertable here...
_ = testdirectory.Start(t, testdirectory.WithDisablePanicRecovery(t, true))
})
t.Run("start-with-ipv6-localhost", func(t *testing.T) {
assert, require := assert.New(t), require.New(t)
port := testdirectory.FreePort(t)
td := testdirectory.Start(
t,
testdirectory.WithPort(t, port),
testdirectory.WithHost(t, "::"),
testdirectory.WithDefaults(t, &testdirectory.Defaults{Users: testEntries}),
testdirectory.WithLogger(t, testLogger),
testdirectory.WithNoTLS(t),
)
assert.Equal(port, td.Port())

c := td.Conn()
defer c.Close()

err := c.Bind(userDN, testPwd)
require.NoError(err)
})
}

type safeBuf struct {
Expand Down Expand Up @@ -724,3 +743,7 @@ func TestDirectory_DeleteResponse(t *testing.T) {
})
}
}

func Test_Directory_Start(t *testing.T) {
t.Parallel()
}

0 comments on commit 2a5a684

Please sign in to comment.