Skip to content

Commit

Permalink
Merge pull request liberkee#47 from hufsm/feature/XPLHUFRO-64_sample_…
Browse files Browse the repository at this point in the history
…updates

Feature/xplhufro 64 sample updates
  • Loading branch information
Radu94 authored Feb 1, 2018
2 parents d0243fc + 5e95a02 commit 52a2d66
Show file tree
Hide file tree
Showing 15 changed files with 68 additions and 62 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,3 @@ modify.ldif
./build/**
.vscode/settings.json
build/*
TSdeclaration/**/*
libBuildTLS/**/*
8 changes: 4 additions & 4 deletions populate.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ const validEntryObject = [
];


const ldapClient = new Client(configFile.ldapTestEntries.host);
const ldapClient = new Client(configFile.ldapAuthentication.host);

ldapClient.initialize()
.then(() => {
return ldapClient.bind(
configFile.ldapTestEntries.userDn,
configFile.ldapTestEntries.userPassword);
configFile.ldapAuthentication.dnAdmin,
configFile.ldapAuthentication.passwordAdmin);
})
.then(() => {
ldapClient.add(dn, validEntryObject)
Expand All @@ -51,6 +51,6 @@ ldapClient.initialize()

Promise.map(args, (arg) => {
return ldapClient.add(arg, validEntryObject);
}, {concurrency: 1});
}, {concurrency: 4});
});
});
18 changes: 18 additions & 0 deletions sample/README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Code Samples

Sample code for all function calls:

- [Add](./add_operation.js)
- [Delete](./delete_operation.js)
- [Compare](./compare_operation.js)
- [Change Password](./change_password_operation.js)
- [Extended Operations](./extended_operation.js)
- [Modify](./modify_operation.js)
- [Paged Search](./page_search_operation.js)
- [Rename](./rename_operation.js)
- [Search](./search_operation.js)


The samples use credentials and parameter values from the [config](./config.json) file, check that out for further info on how to use the library.

For more details on the control parameters, please check the [documentation](../docs/controls.MD)
8 changes: 3 additions & 5 deletions sample/add_operation.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

const LdapClientLib = require('../libs/ldap_async_wrap.js');
const ldif = require('ldif');
const LdapClientLib = require('../index').Client;
const config = require('./config.json');

const newClient = new LdapClientLib(config.ldapAuthentication.host);
Expand Down Expand Up @@ -31,14 +30,13 @@ newClient.initialize()
config.ldapControls.ldapModificationControlPostRead);
})
.then((result) => {
const resultJson = ldif.parse(result);
const outputOptions = {};

const JSONstructure = resultJson.toObject(outputOptions);
const JSONstructure = result.toObject(outputOptions);
JSONstructure.entries.forEach((element) => {
console.log(element);
});
})
.catch((err) => {
console.log(`${err.name} ${err.constructor.description}`);
console.log(err.toString());
});
4 changes: 2 additions & 2 deletions sample/change_password_operation.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const LdapClientLib = require('../libs/ldap_async_wrap.js');
const LdapClientLib = require('../index').Client;
const config = require('./config.json');

const newClient = new LdapClientLib(config.ldapAuthentication.host);
Expand All @@ -23,5 +23,5 @@ newClient.initialize()
console.log('The user\'s password was changed with success');
})
.catch((err) => {
console.log(`${err.name} ${err.constructor.description}`);
console.log(err.toString());
});
4 changes: 2 additions & 2 deletions sample/compare_operation.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const LdapClientLib = require('../libs/ldap_async_wrap.js');
const LdapClientLib = require('../index').Client;

const config = require('./config.json');

Expand Down Expand Up @@ -31,5 +31,5 @@ newClient.initialize()
console.log(`Compare result: ${result}`);
})
.catch((err) => {
console.log(`${err.name} ${err.constructor.description}`);
console.log(err.toString());
});
2 changes: 1 addition & 1 deletion sample/config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"ldapAuthentication": {
"host": "ldap://localhost:389",
"host": "ldap://10.16.0.179:389",
"dnUser": "cn=managerUser,ou=users,o=myhost,dc=demoApp,dc=com",
"passwordUser": "secret",
"pathFileToCert": "/etc/ldap/ca_certs.pem"
Expand Down
8 changes: 3 additions & 5 deletions sample/delete_operation.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

const LdapClientLib = require('../libs/ldap_async_wrap.js');
const ldif = require('ldif');
const LdapClientLib = require('../index').Client;

const config = require('./config.json');

Expand All @@ -26,14 +25,13 @@ newClient.initialize()
config.ldapControls.ldapModificationControlPreRead);
})
.then((result) => {
const resultJson = ldif.parse(result);
const outputOptions = {};

const JSONstructure = resultJson.toObject(outputOptions);
const JSONstructure = result.toObject(outputOptions);
JSONstructure.entries.forEach((element) => {
console.log(element);
});
})
.catch((err) => {
console.log(`${err.name} ${err.constructor.description}`);
console.log(err.toString());
});
4 changes: 2 additions & 2 deletions sample/extended_operation.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const LdapClientLib = require('../libs/ldap_async_wrap.js');
const LdapClientLib = require('../index').Client;

const config = require('./config.json');

Expand Down Expand Up @@ -34,6 +34,6 @@ newClient.initialize()
console.log(`The current user is: ${res}`);
})
.catch((err) => {
console.log(`${err.name} ${err.constructor.description}`);
console.log(err.toString());
});

21 changes: 13 additions & 8 deletions sample/modify_operation.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
'use strict';

const LdapClientLib = require('../libs/ldap_async_wrap.js');

const ldif = require('ldif');
const LdapClientLib = require('../index').Client;

const dn = 'ou=users,o=myhost,dc=demoApp,dc=com';

Expand All @@ -17,8 +15,16 @@ const changes = [
];

const prePostReadControls = [
config.ldapControls.ldapModificationControlPostRead,
config.ldapControls.ldapModificationControlPreRead,
{
oid: '1.3.6.1.1.13.1',
value: ['cn'],
isCritical: false,
},
{
oid: '1.3.6.1.1.13.2',
value: ['cn'],
isCritical: false,
},
];

newClient.initialize()
Expand All @@ -39,14 +45,13 @@ newClient.initialize()
return newClient.modify(config.ldapModify.secondDNEntry, changes, prePostReadControls);
})
.then((result) => {
const resultJson = ldif.parse(result);
const outputOptions = {};

const JSONstructure = resultJson.toObject(outputOptions);
const JSONstructure = result.toObject(outputOptions);
JSONstructure.entries.forEach((element) => {
console.log(element);
});
})
.catch((err) => {
console.log(`${err.name} ${err.constructor.description}`);
console.log(err.toString());
});
13 changes: 5 additions & 8 deletions sample/page_search_operation.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
'use strict';

const LdapClientLib = require('../libs/ldap_async_wrap.js');

const ldif = require('ldif');
const LdapClientLib = require('../index').Client;

const config = require('./config.json');

Expand All @@ -28,10 +26,9 @@ newClient.initialize()
console.log('-----------------------------------');
console.log(`The page number is ${pageNumber += 1}`);
console.log('-----------------------------------');
const resultJson = ldif.parse(data.toString());
const outputOptions = {};

const JSONstructure = resultJson.toObject(outputOptions);
const JSONstructure = data.toObject(outputOptions);
console.log(`LDIF structure: ${data.toString()}`);
JSONstructure.entries.forEach((element) => {
console.log(element);
Expand All @@ -41,8 +38,8 @@ newClient.initialize()
result.on('err', (err) => {
console.log('-----------------');
console.error(`Error name: ${err.name}`);
console.error(`Error code: ${err.constructor.code}`);
console.error(`Error description: ${err.constructor.description}`);
console.error(`Error code: ${err.code}`);
console.error(`Error description: ${err.description}`);
console.log('-----------------');
});

Expand All @@ -51,5 +48,5 @@ newClient.initialize()
});
})
.catch((err) => {
console.log(`${err.name} ${err.constructor.description}`);
console.log(err.toString());
});
12 changes: 5 additions & 7 deletions sample/rename_oparation.js → sample/rename_operation.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
'use strict';

const LdapClientLib = require('../libs/ldap_async_wrap.js');
const ldif = require('ldif');
const LdapClientLib = require('../index').Client;

const config = require('./config.json');

const newClient = new LdapClientLib(config.ldapAuthentication.host);

const prePostReadControls = [
config.ldapControls.ldapModificationControlPostRead,
config.ldapControls.ldapModificationControlPreRead,
'1.3.6.1.1.13.2',
'1.3.6.1.1.13.1',
];

newClient.initialize()
Expand All @@ -32,14 +31,13 @@ newClient.initialize()
config.ldapRename.newParent, prePostReadControls);
})
.then((result) => {
const resultJson = ldif.parse(result);
const outputOptions = {};

const JSONstructure = resultJson.toObject(outputOptions);
const JSONstructure = result.toObject(outputOptions);
JSONstructure.entries.forEach((element) => {
console.log(element);
});
})
.catch((err) => {
console.log(`${err.name} ${err.constructor.description}`);
console.log(err.toString());
});
9 changes: 3 additions & 6 deletions sample/search_operation.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
'use strict';

const LdapClientLib = require('../libs/ldap_async_wrap.js');

const ldif = require('ldif');
const LdapClientLib = require('../index').Client;

const config = require('./config.json');

Expand All @@ -23,15 +21,14 @@ newClient.initialize()
config.ldapSearch.filter);
})
.then((result) => {
const resultJson = ldif.parse(result);
const outputOptions = {};
const JSONstructure = resultJson.toObject(outputOptions);
const JSONstructure = result.toObject(outputOptions);
console.log(`LDIF structure: ${result}`);
console.log('\n\n');
JSONstructure.entries.forEach((element) => {
console.log(element);
});
})
.catch((err) => {
console.log(`${err.name} ${err.constructor.description}`);
console.log(err.toString());
});
13 changes: 5 additions & 8 deletions test/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"dnUserNoRight": "cn=simpleUser,ou=users,o=myhost,dc=demoApp,dc=com",
"passwordAdmin": "secret",
"passwordUser": "secret",
"pathFileToCert": "D:/HSM/ca_certs.pem"
"pathFileToCert": "ca_certs.pem"
},
"ldapExtendedOperation": {
"oid": {
Expand Down Expand Up @@ -134,18 +134,15 @@
"filterObjAll": "objectclass=*",
"filterObjSpecific": "objectclass=aliens",
"filterObjSpecific2": "objectClass=simpleSecurityObject",
"filterObjSpecific3": "objectClass=inetOrgPerson"
"filterObjSpecific3": "objectClass=inetOrgPerson",
"nrOfResults": 10000,
"pageSize": 10
},
"ldapDelete": {
"rdnUser": "cn=testUsersDelete",
"dn": ",cn=newPoint,ou=users,o=myhost,dc=demoApp,dc=com"
},
"ldapTestEntries": {
"host": "ldap://localhost:389",
"entryDn": "cn=newPoint,ou=users,o=myhost,dc=demoApp,dc=com",
"userDn": "cn=admin,dc=demoApp,dc=com",
"userPassword": "secret",
"nrOfResults": 10000,
"pageSize": 10
"entryDn": "cn=newPoint,ou=users,o=myhost,dc=demoApp,dc=com"
}
}
4 changes: 2 additions & 2 deletions test/test_paged_search.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ describe('Testing the async LDAP paged search ', () => {
let userLDAP = new LDAPWrap(host);
let pagedSearchPromise;

const nrOfResults = config.ldapTestEntries.nrOfResults;
const nrOfResults = config.ldapSearch.nrOfResults;

const pageSize = config.ldapTestEntries.pageSize;
const pageSize = config.ldapSearch.pageSize;

const searchScope = {
base: 'BASE',
Expand Down

0 comments on commit 52a2d66

Please sign in to comment.