make-ldif

make-ldif

我们经常需要在测试环境下灌入随机测试数据至LDAP数据库,make-ldif是一个很好的工具,可以用来生成这些测试数据.

make-ldif可以用来生成:

  • 测试的Person
  • 测试的Organization
  • Person归属Organization

make-ldif是根据一个模板文件来定义要生成的Person/Organization里的,可以定义:

  • Person的各个attribute, 比如可以定义Person的邮箱,手机号,姓名,密码等
  • Organization的名称以及层级关系
  • 生成Person/Organization的总数

模板文件的语法也比较简单,请自行google.

make-ldif的输出是一个标准的LDAP的ldif文件,我们通过ldapmodify就可以把这些ldif文件导入LDAP数据库

举例,测试中用到的一个模板如下:

define suffix=dc=example,dc=com
define maildomain=mailinator.com
define numusers=220
 
branch: [suffix]
 
branch: ou=BeiJing,[suffix]
 
branch: ou=HR,ou=BeiJing,[suffix]
subordinateTemplate: noemailperson:[numusers]
subordinateTemplate: nomobileperson:[numusers]
subordinateTemplate: hasemailperson:[numusers]
 
branch: ou=Recruit,ou=HR,ou=BeiJing,[suffix]
subordinateTemplate: noemailperson:[numusers]
subordinateTemplate: nomobileperson:[numusers]
subordinateTemplate: hasemailperson:[numusers]
 
branch: ou=Finance,ou=BeiJing,[suffix]
subordinateTemplate: noemailperson:[numusers]
subordinateTemplate: nomobileperson:[numusers]
subordinateTemplate: hasemailperson:[numusers]
 
branch: ou=R&D,ou=BeiJing,[suffix]
subordinateTemplate: noemailperson:[numusers]
subordinateTemplate: nomobileperson:[numusers]
subordinateTemplate: hasemailperson:[numusers]
 
branch: ou=UserCenter,ou=R&D,ou=BeiJing,[suffix]
subordinateTemplate: hasemailperson:20
subordinateTemplate: nomobileperson:20
subordinateTemplate: hasemailperson:20
 
branch: ou=Dev,ou=UserCenter,ou=R&D,ou=BeiJing,[suffix]
subordinateTemplate: hasemailperson:20
subordinateTemplate: nomobileperson:20
subordinateTemplate: hasemailperson:20
 
branch: ou=QA,ou=UserCenter,ou=R&D,ou=BeiJing,[suffix]
subordinateTemplate: noemailperson:[numusers]
subordinateTemplate: nomobileperson:[numusers]
subordinateTemplate: hasemailperson:[numusers]
 
branch: ou=Empty Depth1,ou=UserCenter,ou=R&D,ou=BeiJing,[suffix]
branch: ou=Empty Depth2,ou=Empty Depth1,ou=UserCenter,ou=R&D,ou=BeiJing,[suffix]
 
branch: ou=UEM,ou=R&D,ou=BeiJing,[suffix]
subordinateTemplate: noemailperson:[numusers]
subordinateTemplate: nomobileperson:[numusers]
subordinateTemplate: hasemailperson:[numusers]
 
branch: ou=TianJin,[suffix]
subordinateTemplate: noemailperson:[numusers]
subordinateTemplate: nomobileperson:[numusers]
subordinateTemplate: hasemailperson:[numusers]
 
branch: ou=R&D,ou=TianJin,[suffix]
subordinateTemplate: noemailperson:[numusers]
subordinateTemplate: nomobileperson:[numusers]
subordinateTemplate: hasemailperson:[numusers]
 
branch: ou=SAG,ou=R&D,ou=TianJin,[suffix]
subordinateTemplate: hasemailperson:[numusers]
subordinateTemplate: noemailperson:[numusers]
subordinateTemplate: nomobileperson:[numusers]
 
template: hasemailperson
rdnAttr: uid
objectClass: top
objectClass: person
objectClass: organizationalPerson
objectClass: inetOrgPerson
givenName: <first>
sn: <last>
cn: {givenName} {sn}
initials: {givenName:1}<random:chars:ABCDEFGHIJKLMNOPQRSTUVWXYZ:1>{sn:1}
employeeNumber: <sequential:0>
uid: emailuser.{employeeNumber}
#uid: {sn}{givenName}.{employeeNumber}
mail: {uid}@[maildomain]
userPassword: 1
telephoneNumber: <random:telephone>
homePhone: <random:telephone>
pager: <random:telephone>
mobile: <random:telephone>
street: <random:numeric:5> <file:streets> Street
l: <file:cities>
st: <file:states>
postalCode: <random:numeric:5>
postalAddress: {cn}${street}${l}, {st}  {postalCode}
description: This is the description for {cn}.
 
template: noemailperson
rdnAttr: uid
objectClass: top
objectClass: person
objectClass: organizationalPerson
objectClass: inetOrgPerson
givenName: <first>
sn: <last>
cn: {givenName} {sn}
initials: {givenName:1}<random:chars:ABCDEFGHIJKLMNOPQRSTUVWXYZ:1>{sn:1}
employeeNumber: <sequential:0>
uid: noemailuser.{employeeNumber}
#uid: {sn}{givenName}.{employeeNumber}
userPassword: 1
telephoneNumber: <random:telephone>
homePhone: <random:telephone>
pager: <random:telephone>
mobile: <random:telephone>
street: <random:numeric:5> <file:streets> Street
l: <file:cities>
st: <file:states>
postalCode: <random:numeric:5>
postalAddress: {cn}${street}${l}, {st}  {postalCode}
description: This is the description for {cn}.
 
template: nomobileperson
rdnAttr: uid
objectClass: top
objectClass: person
objectClass: organizationalPerson
objectClass: inetOrgPerson
givenName: <first>
sn: <last>
cn: {givenName} {sn}
initials: {givenName:1}<random:chars:ABCDEFGHIJKLMNOPQRSTUVWXYZ:1>{sn:1}
employeeNumber: <sequential:0>
uid: nomobileuser.{employeeNumber}
#uid: {sn}{givenName}.{employeeNumber}
userPassword: 1
telephoneNumber: <random:telephone>
homePhone: <random:telephone>
pager: <random:telephone>
street: <random:numeric:5> <file:streets> Street
l: <file:cities>
st: <file:states>
postalCode: <random:numeric:5>
postalAddress: {cn}${street}${l}, {st}  {postalCode}
description: This is the description for {cn}.

该模板文件用于在dc=example,dc=com这个basedn下,生成若干Organization以及Person,并且有的Person没有email,有的人没有mobile等

Tags:ldap   Tags:ldif
Written on February 14, 2019