Skip to content

Commit

Permalink
test: add integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
wadahiro committed Mar 8, 2023
1 parent de60980 commit aee535c
Show file tree
Hide file tree
Showing 2 changed files with 182 additions and 18 deletions.
155 changes: 154 additions & 1 deletion integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package main
import (
"os"
"testing"
"time"

"github.com/go-ldap/ldap/v3"
)
Expand Down Expand Up @@ -86,6 +87,94 @@ func TestParallel(t *testing.T) {
runTestCases(t, tcs)
}

func TestParallelByNonRootUsers(t *testing.T) {
type A []string
type M map[string][]string

tcs := []Command{
Conn{},
Bind{"cn=Manager", "secret", &AssertResponse{}},
AddDC("com").SetAssert(&AssertResponse{53}),
AddDC("example", "dc=com"),
AddOU("Users"),
Add{
"uid=op1", "ou=Users",
M{
"objectClass": A{"inetOrgPerson"},
"cn": A{"op1"},
"sn": A{"op1"},
"userPassword": A{SSHA("password1")},
},
&AssertEntry{},
},
Add{
"uid=op2", "ou=Users",
M{
"objectClass": A{"inetOrgPerson"},
"cn": A{"op2"},
"sn": A{"op2"},
"userPassword": A{SSHA256("password2")},
},
&AssertEntry{},
},
Parallel{
100,
[][]Command{
{
Conn{},
Bind{"uid=op1,ou=Users", "password1", &AssertResponse{}},
Add{
"uid=user1", "ou=Users",
M{
"objectClass": A{"inetOrgPerson"},
"cn": A{"user1"},
"sn": A{"user1"},
},
&AssertEntry{},
},
ModifyAdd{
"uid=user1", "ou=Users",
M{
"givenName": A{"user1"},
},
&AssertEntry{},
},
Delete{
"uid=user1", "ou=Users",
&AssertNoEntry{},
},
},
{
Conn{},
Bind{"uid=op2,ou=Users", "password2", &AssertResponse{}},
Add{
"uid=user2", "ou=Users",
M{
"objectClass": A{"inetOrgPerson"},
"cn": A{"user2"},
"sn": A{"user2"},
},
&AssertEntry{},
},
ModifyAdd{
"uid=user2", "ou=Users",
M{
"givenName": A{"user2"},
},
&AssertEntry{},
},
Delete{
"uid=user2", "ou=Users",
&AssertNoEntry{},
},
},
},
},
}

runTestCases(t, tcs)
}

func TestDeadlock(t *testing.T) {
type A []string
type M map[string][]string
Expand Down Expand Up @@ -323,6 +412,70 @@ func TestBind(t *testing.T) {
runTestCases(t, tcs)
}

func TestBindWithAccountLock(t *testing.T) {
type A []string
type M map[string][]string

testServer.config.MigrationEnabled = true
testServer.LoadSchema()

tcs := []Command{
Conn{},
Bind{"cn=Manager", "secret", &AssertResponse{}},
AddDC("example", "dc=com"),
AddOU("Users"),
AddOU("Policies"),
Add{
"uid=op1", "ou=Users",
M{
"objectClass": A{"inetOrgPerson"},
"cn": A{"op1"},
"sn": A{"op1"},
"userPassword": A{SSHA("password1")},
},
&AssertEntry{},
},
Add{
"cn=standard-policy", "ou=Policies",
M{
"objectClass": A{"top", "device", "pwdPolicy"},
"pwdAttribute": A{"userPassword"},
"pwdLockout": A{"TRUE"},
"pwdMaxFailure": A{"2"},
"pwdlockoutDuration": A{"10"},
},
nil,
},
Bind{"uid=op1,ou=users", "password1", &AssertResponse{}},
Bind{
"uid=op1,ou=Users",
"invalid",
&AssertResponse{49},
},
Bind{"uid=op1,ou=users", "password1", &AssertResponse{}},
Bind{
"uid=op1,ou=Users",
"invalid",
&AssertResponse{49},
},
Bind{
"uid=op1,ou=Users",
"invalid",
&AssertResponse{49},
},
// Account Locked
Bind{"uid=op1,ou=users", "password1", &AssertResponse{49}},
// still locked
Wait{time.Second * 5},
Bind{"uid=op1,ou=users", "password1", &AssertResponse{49}},
// Unlocked
Wait{time.Second * 5},
Bind{"uid=op1,ou=users", "password1", &AssertResponse{}},
}

runTestCases(t, tcs)
}

func TestSearchSpecialCharacters(t *testing.T) {
type A []string
type M map[string][]string
Expand Down Expand Up @@ -1455,7 +1608,7 @@ func TestOperationalAttributesMigration(t *testing.T) {
runTestCases(t, tcs)
}

func TesPwdFailureTimeNano(t *testing.T) {
func TestPwdFailureTimeNano(t *testing.T) {
type A []string
type M map[string][]string

Expand Down
45 changes: 28 additions & 17 deletions test_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ type Command interface {
Run(t *testing.T, conn *ldap.Conn) (*ldap.Conn, error)
}

type Wait struct {
duration time.Duration
}

func (w Wait) Run(t *testing.T, unused *ldap.Conn) (*ldap.Conn, error) {
time.Sleep(w.duration)
return unused, nil
}

type Parallel struct {
count int
ops [][]Command
Expand Down Expand Up @@ -704,23 +713,25 @@ func setupLDAPServer() *Server {
// "objectClasses: ( 2.5.6.9 NAME 'groupOfNames' DESC 'RFC2256: a group of names (DNs)' SUP top STRUCTURAL MUST cn MAY ( businessCategory $ seeAlso $ owner $ ou $ o $ description $ member $ uniqueMember $ displayName ) )",
// }
testServer = NewServer(&ServerConfig{
DBHostName: "localhost",
DBPort: testPGPort,
DBName: "ldap",
DBSchema: "public",
DBUser: "dev",
DBPassword: "dev",
DBMaxOpenConns: 2,
DBMaxIdleConns: 1,
Suffix: "dc=example,dc=com",
RootDN: "cn=Manager,dc=example,dc=com",
RootPW: "secret",
BindAddress: "127.0.0.1:8389",
LogLevel: "warn",
PProfServer: "127.0.0.1:10000",
GoMaxProcs: 0,
QueryTranslator: "default",
DefaultPageSize: 500,
DBHostName: "localhost",
DBPort: testPGPort,
DBName: "ldap",
DBSchema: "public",
DBUser: "dev",
DBPassword: "dev",
DBMaxOpenConns: 2,
DBMaxIdleConns: 1,
Suffix: "dc=example,dc=com",
RootDN: "cn=Manager,dc=example,dc=com",
RootPW: "secret",
BindAddress: "127.0.0.1:8389",
LogLevel: "warn",
PProfServer: "127.0.0.1:10000",
GoMaxProcs: 0,
QueryTranslator: "default",
DefaultPPolicyDN: "cn=standard-policy,ou=Policies,dc=examle,dc=com",
DefaultPageSize: 500,
SimpleACL: []string{"uid=op1,ou=users,dc=example,dc=com:RW:", "uid=op2,ou=users,dc=example,dc=com:RW:"},
})
go testServer.Start()

Expand Down

0 comments on commit aee535c

Please sign in to comment.