Skip to content

Commit

Permalink
adding more test
Browse files Browse the repository at this point in the history
this tests only work on my box i'll provide a test.ldif in the future
  • Loading branch information
guedes committed Jan 25, 2013
1 parent e86b71c commit 5c9db48
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
8 changes: 5 additions & 3 deletions src/ldap_fdw.c
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ ldapIterateForeignScan(ForeignScanState *node)
char *dn;
char *attribute;

char object_body[1024];
char object_body[1024] = "";
char **values;
char **temp;

Expand All @@ -375,7 +375,7 @@ ldapIterateForeignScan(ForeignScanState *node)
attribute = ldap_next_attribute(festate->ldap_connection, festate->ldap_entry, ber))
{
strcat(object_body, attribute);
strcat(object_body, ": ");
strcat(object_body, " => \"");

if ((temp = ldap_get_values(festate->ldap_connection, festate->ldap_entry, attribute)) != NULL)
{
Expand All @@ -385,9 +385,9 @@ ldapIterateForeignScan(ForeignScanState *node)
strcat(object_body, ",");

strcat(object_body, temp[i]);
strcat(object_body, "\n");
}

strcat(object_body, "\",\n");
ldap_value_free(temp);
}

Expand All @@ -406,6 +406,7 @@ ldapIterateForeignScan(ForeignScanState *node)
if (ber != NULL)
ber_free(ber, 0);

pfree(values);
}

return slot;
Expand All @@ -422,6 +423,7 @@ ldapEndForeignScan(ForeignScanState *node)
{
LdapFdwExecutionState *festate = (LdapFdwExecutionState *) node->fdw_state;

ldap_memfree(festate->ldap_entry);
ldap_unbind( festate->ldap_connection );
}

Expand Down
30 changes: 23 additions & 7 deletions test/expected/base.out
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,29 @@ CREATE FOREIGN TABLE ldap_people (
SERVER ldap_test_server
OPTIONS (base_dn 'DC=guedesoft,DC=net');
SELECT * FROM ldap_people WHERE dn = 'cn=admin,dc=guedesoft,dc=net';
dn | object_body
------------------------------+------------------------------------------------------
cn=admin,dc=guedesoft,dc=net | objectClass: simpleSecurityObject +
| ,organizationalRole +
| cn: admin +
| description: LDAP administrator +
| userPassword: {SSHA}W0P/R7GRoqr1sl2JMMnG0TXn1UP1uVn6+
dn | object_body
------------------------------+-----------------------------------------------------------
cn=admin,dc=guedesoft,dc=net | objectClass => "simpleSecurityObject,organizationalRole",+
| cn => "admin", +
| description => "LDAP administrator", +
| userPassword => "{SSHA}W0P/R7GRoqr1sl2JMMnG0TXn1UP1uVn6" +
|
(1 row)

SELECT * FROM ldap_people ;
dn | object_body
--------------------------------+-----------------------------------------------------------
cn=admin,dc=guedesoft,dc=net | objectClass => "simpleSecurityObject,organizationalRole",+
| cn => "admin", +
| description => "LDAP administrator", +
| userPassword => "{SSHA}W0P/R7GRoqr1sl2JMMnG0TXn1UP1uVn6" +
|
ou=people,dc=guedesoft,dc=net | objectClass => "organizationalUnit,top", +
| ou => "people" +
|
cn=usuario,dc=guedesoft,dc=net | gidNumber => "500", +
| cn => "usuario", +
| objectClass => "posixGroup,top" +
|
(3 rows)

1 change: 1 addition & 0 deletions test/sql/base.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ SERVER ldap_test_server
OPTIONS (base_dn 'DC=guedesoft,DC=net');

SELECT * FROM ldap_people WHERE dn = 'cn=admin,dc=guedesoft,dc=net';
SELECT * FROM ldap_people ;

0 comments on commit 5c9db48

Please sign in to comment.