-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_rename.js
212 lines (191 loc) · 7.5 KB
/
test_rename.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
'use strict';
const LdapAsyncWrap = require('../libs/ldap_async_wrap.js');
const config = require('./config.json');
const should = require('should');
const errorHandler = require('../libs/errors/error_dispenser').errorFunction;
const ValidationError = require('../libs/errors/validation_error');
const StateError = require('../libs/errors/state_error');
const errorCodes = require('../libs/error_codes');
const errorMessages = require('../libs/messages.json');
describe('Testing the rename functionalities', () => {
let ldapAsyncWrap = new LdapAsyncWrap(config.ldapAuthentication.host);
const controlOperation = [
{
oid: config.ldapControls.ldapModificationControlPostRead.oid,
value: config.ldapControls.ldapModificationControlPostRead.value,
isCritical: config.ldapControls.ldapModificationControlPostRead.isCritical,
},
{
oid: config.ldapControls.ldapModificationControlPreRead.oid,
value: config.ldapControls.ldapModificationControlPreRead.value,
isCritical: config.ldapControls.ldapModificationControlPreRead.isCritical,
},
];
const pathToCert = config.ldapAuthentication.pathFileToCert;
beforeEach(() => {
ldapAsyncWrap = new LdapAsyncWrap(config.ldapAuthentication.host);
return ldapAsyncWrap.initialize()
.then(() => {
return ldapAsyncWrap.bind(config.ldapAuthentication.dnAdmin, config.ldapAuthentication.passwordAdmin);
});
});
afterEach(() => {
return ldapAsyncWrap.unbind();
});
it('should reject if dn is not a string', () => {
return ldapAsyncWrap.rename(1, config.ldapRename.newrdn, config.ldapRename.newparent)
.then(() => {
should.fail('should not have passed');
})
.catch(TypeError, (error) => {
should.deepEqual(error.message, errorMessages.typeErrorMessage);
})
.catch((err) => {
should.fail('did not expect generic error');
});
});
it('should reject if newRdn is not a string', () => {
return ldapAsyncWrap.rename(config.ldapRename.dnChange, 1, config.ldapRename.newparent)
.then(() => {
should.fail('should not have passed');
})
.catch(TypeError, (error) => {
should.deepEqual(error.message, errorMessages.typeErrorMessage);
})
.catch((err) => {
should.fail('did not expect generic error');
});
});
it('should reject if newParent is not a string', () => {
return ldapAsyncWrap.rename(config.ldapRename.dnChange, config.ldapRename.newrdn, 1)
.then(() => {
should.fail('should not have passed');
})
.catch(TypeError, (error) => {
should.deepEqual(error.message, errorMessages.typeErrorMessage);
})
.catch((err) => {
should.fail('did not expect generic Error');
});
});
it('should reject if control is not a valid control object', () => {
return ldapAsyncWrap.rename(config.ldapRename.dnChange, config.ldapRename.newrdn, config.ldapRename.newparent, { test: 'test' })
.then(() => {
should.fail('should not have passed');
})
.catch(ValidationError, (error) => {
should.deepEqual(error.message, errorMessages.controlPropError);
})
.catch((err) => {
should.fail('did not expect generic Error');
});
});
it('should reject if control is not properly defined', () => {
return ldapAsyncWrap.rename(config.ldapRename.dnChange, config.ldapRename.newrdn, config.ldapRename.newparent, [{ test: 'test' }])
.then(() => {
should.fail('should not have passed');
})
.catch(ValidationError, (error) => {
should.deepEqual(error.message, errorMessages.controlPropError);
})
.catch((err) => {
should.fail('did not expect generic error');
});
});
it('should reject if dn incorrectly defined', () => {
const badDn = 'bad dn';
return ldapAsyncWrap.rename(badDn, config.ldapRename.newrdn, config.ldapRename.newparent)
.then(() => {
should.fail('should not have passed');
})
.catch(errorHandler(errorCodes.invalidDnSyntax), (error) => {
const CustomError = errorHandler(errorCodes.invalidDnSyntax);
should.deepEqual(error, new CustomError(errorMessages.ldapRenameErrorMessage));
})
.catch((err) => {
should.fail('did not expect generic error');
});
});
it('should reject if newparent incorrectly defined', () => {
const badNewParent = 'bad dn';
const CustomError = errorHandler(errorCodes.invalidDnSyntax);
return ldapAsyncWrap.rename(config.ldapRename.dnChange, config.ldapRename.newrdn, badNewParent)
.then(() => {
should.fail('should not have passed');
})
.catch(CustomError, (error) => {
should.deepEqual(error, new CustomError(errorMessages.ldapRenameErrorMessage));
})
.catch((err) => {
should.fail('did not expect generic error');
});
});
it('should reject if dn incorrectly defined', () => {
const incorrectDefinedDn = 'cn=admin';
const CustomError = errorHandler(errorCodes.unwillingToPerform);
return ldapAsyncWrap.rename(incorrectDefinedDn, config.ldapRename.newrdn, config.ldapRename.newparent)
.then(() => {
should.fail('should not have passed');
})
.catch(CustomError, (error) => {
should.deepEqual(error, new CustomError(errorMessages.ldapRenameErrorMessage));
})
.catch((err) => {
should.fail('did not expect generic error');
});
});
it('should reject if newparent incorrectly defined', () => {
const incorrectDefinedNewParent = 'ou=users';
const CustomError = errorHandler(errorCodes.affectMultipleDsas);
return ldapAsyncWrap.rename(config.ldapRename.dnChange, config.ldapRename.newrdn, incorrectDefinedNewParent)
.then(() => {
should.fail('should not have passed');
})
.catch(CustomError, (error) => {
should.deepEqual(error, new CustomError(errorMessages.ldapRenameErrorMessage));
})
.catch((err) => {
should.fail('did not expect generic error');
});
});
it('should reject if the state is not BOUND', () => {
return ldapAsyncWrap.unbind()
.then(() => {
return ldapAsyncWrap.rename(config.ldapRename.dnChange, config.ldapRename.newrdn, config.ldapRename.newparent);
})
.then(() => {
should.fail('should not have passed');
})
.catch(StateError, (error) => {
should.deepEqual(error.message, errorMessages.bindErrorMessage);
})
.catch((err) => {
should.fail('did not expect generic Error');
});
});
it('should reject if dn doesn\'t exist ', () => {
const existDn = 'cn=1,ou=users,o=myhost,dc=demoApp,dc=com';
const CustomError = errorHandler(errorCodes.ldapNoSuchObject);
return ldapAsyncWrap.rename(existDn, config.ldapRename.newrdn, config.ldapRename.newparent, controlOperation)
.then(() => {
should.fail('should not have passed');
})
.catch(CustomError, (error) => {
should.deepEqual(error, new CustomError(errorMessages.ldapRenameErrorMessage));
})
.catch((err) => {
should.fail('did not expect generic error');
});
});
it('should rename the dn', () => {
const validEntry = [
config.ldapAdd.firstAttr,
config.ldapAdd.secondAttr,
config.ldapAdd.lastAttr,
];
ldapAsyncWrap.rename(config.ldapRename.dnChange, config.ldapRename.newrdn, config.ldapRename.newparent, controlOperation)
.then((result) => {
should.deepEqual(result.entries[0].dn, config.ldapRename.dnChange);
});
});
});