Validating LDAP through QTP – 1

For the complete and Good Test Coverage, we usually cover the UI check, DB check as part of the automation. One more area which we more over tried to have a check is the LDAP. All user related information such as UserName, FirstName, mail-id, password, contact information are stored in LDAP Securely. I will we explain how we can Automate The LDAP tests with this series of Post.

Firstly, we shall try to understand how we can communicate with LDAP through QTP/VB scripts. LDAP internally have its own Database, which we can query the information. The process is simple as in the case of Database query. we first establish a connection, query the information. process the output.

As an example, we will define a function getDNofUser(username).

This will take the user-name as an input, and return empty string if the user doesn’t exist, or a complete Distinguished name of that user.

public Function getDNofUser(UserName)
 Set con = CreateObject("adodb.connection")
 con.Open "Provider=ADsDSOObject;", "cn=root", "password"
 sql = "select cn from 'LDAP://ldapserver:389/cn=users,dc=compName,dc=com' 
where ObjectClass='inetorgperson'and uid='"& UserName & "'"

 Set rs = con.Execute(sql)
 val=""      

 Do until rs.EOF
 ReturnValue = rs.Fields(0)
 val=""
 If IsArray(ReturnValue) Then
 val = "cn=" & ReturnValue(0) & ",cn=users,dc=compName,dc=com"
 Else
 Val = "cn=" & ReturnValue & ",cn=users,dc=compName,dc=com"
 End If
 rs.MoveNext
 Loop
 getDNofUser = val
End Function

The line

con.Open "Provider=ADsDSOObject;", "cn=root", "password" 

creates a connection object, we have to provide the LDAP credentials here. It need not be cn=root alway, It can be any user with read permission to the directory structure.

The line

sql = "select cn from 'LDAP://ldapserver:389/cn=users,dc=compName,dc=com' 
where ObjectClass='inetorgperson'and uid='"& UserName & "'"

is the actually query from which we would be fetching the detail from.

Note that in from clause, we are providing the ldap details: servername, portnumber, user Container and baseDN. In the where clause we are specifying the objectclass the user belong and the uid we are interested.

Once we execute this sql we will get the recordset. Little processing it we will be able to validate the user is present or not in the LDAP. So the Create User Sanity Test Case will Pass!! 🙂

Advertisements

5 Responses to Validating LDAP through QTP – 1

  1. Sri says:

    How can we retreive a value from the LDAP (I am trying to search for a record and then get the Customer ID

    • Sridhar says:

      Yes,

      Look at the select query, “select cn from”. here we are retrieving cn.
      You can retrieve any field you want.

  2. Sri says:

    When I am trying to retreive the value for the attribute “CN” its fine if it is an different attribute I have been thrown with unspecified error.

    Below is the query:
    sql = “select apuseraccountid from ‘LDAP://*********:389/cn=users,dc=******’ where objectclass=’auspostUser'”

  3. priyank says:

    when trying to execute above query getting error The server is not operational.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: