@@ -26,6 +26,7 @@ describe('Auth', function () {
26
26
27
27
describe ( '#SCRAMSHA256' , function ( ) {
28
28
29
+ var method0 = 'LDAP'
29
30
var method1 = 'SCRAMPBKDF2SHA256' ;
30
31
var method2 = 'SCRAMSHA256' ;
31
32
var password = 'secret' ;
@@ -56,12 +57,69 @@ describe('Auth', function () {
56
57
'01002093cae8d0d3fd9ea7e67da4a09678d504429e67a1cb6197ed3a6a70afbd757a96' ,
57
58
'hex' ) ;
58
59
60
+ var ldapClientChallenge = new Buffer (
61
+ '0200' +
62
+ // client nonce = clientChallenge
63
+ '40' +
64
+ 'edbd7cc8b2f26489d65a7cd51e27f2e73fca227d1ab6aafcac0f428ca4d8e10c' +
65
+ '19e3e38f3aac51075e67bbe52fdb6103a7c34c8a70908ed5be0b3542705f738c' +
66
+ // supported capabilities
67
+ '08' +
68
+ '0100000000000000' ,
69
+ 'hex' ) ;
70
+ var ldapServerChallenge = new Buffer (
71
+ '0400' +
72
+ // client nonce = clientChallenge
73
+ '40' +
74
+ 'edbd7cc8b2f26489d65a7cd51e27f2e73fca227d1ab6aafcac0f428ca4d8e10c' +
75
+ '19e3e38f3aac51075e67bbe52fdb6103a7c34c8a70908ed5be0b3542705f738c' +
76
+ // server nonce
77
+ '40' +
78
+ 'a16fc718d5fd20aa3febeeeebe34270565ad3818894c6e3b3b674ee71b440c07' +
79
+ 'd6b9329d1860d4e693d9312aaece14bf3eb86d604670c571f2d7445a97949310' +
80
+ // public key pem
81
+ 'ff01c4' +
82
+ '2d2d2d2d2d424547494e205055424c4943204b45592d2d2d2d2d0a' +
83
+ '4d494942496a414e42676b71686b6947397730424151454641414f43415138414d49494243674b43415145416f4e736d494777763554583558473051697076620a' +
84
+ '435342576645773678546d3230596c555559516262316d5863764831575153475877424c5078313449556b584e67545350435177314a4f7361513075364843680a' +
85
+ '6e35773063786f4e78367a386e694b3838676c774a476167714c32356536506d47354d586264784d74496c5863736336465a55364a4370384538496d313362650a' +
86
+ '7776584c4b6c6d7536304238762b462b5877582b5a6b6f693735662f6758626e2f366a723679737a554c4b512f586151524a69535766567468575a71533967540a' +
87
+ '53645676686e736d4e306261744c7a70705376706c79356447423735596961754b4f66672b753531684e2b4b4d4a5a532f392f415172716d71637678675835740a' +
88
+ '79624a6b6138796e437164694e4b6d32764d6174766d6f656a4f446d7a61474b5553514754627042357a35654a544636625172796877666850645263692b7a760a' +
89
+ '7a514944415141420a' +
90
+ '2d2d2d2d2d454e44205055424c4943204b45592d2d2d2d2d0a00' +
91
+ // capability to use
92
+ '01' +
93
+ '01' ,
94
+ 'hex' ) ;
95
+ /*
96
+ -----BEGIN PUBLIC KEY-----
97
+ MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAoNsmIGwv5TX5XG0Qipvb
98
+ CSBWfEw6xTm20YlUUYQbb1mXcvH1WQSGXwBLPx14IUkXNgTSPCQw1JOsaQ0u6HCh
99
+ n5w0cxoNx6z8niK88glwJGagqL25e6PmG5MXbdxMtIlXcsc6FZU6JCp8E8Im13be
100
+ wvXLKlmu60B8v+F+XwX+Zkoi75f/gXbn/6jr6yszULKQ/XaQRJiSWfVthWZqS9gT
101
+ SdVvhnsmN0batLzppSvply5dGB75YiauKOfg+u51hN+KMJZS/9/AQrqmqcvxgX5t
102
+ ybJka8ynCqdiNKm2vMatvmoejODmzaGKUSQGTbpB5z5eJTF6bQryhwfhPdRci+zv
103
+ zQIDAQAB
104
+ -----END PUBLIC KEY-----
105
+ */
106
+ var ldapSessionKey = new Buffer (
107
+ '568bdf7b9d8930ea937279326c92f72fc0769205e91d864b7a44868984e2cbb2' ,
108
+ 'hex' ) ;
109
+ // can't check client proof as RSA encypt has a random factor
110
+ // so only check the encrypted password
111
+ var ldapEncryptedPassword = new Buffer ( '7d78f690a5cff122e72f62f6c07dfea1259098a2ccfa938f42031f2644dba8954aa10d1c0665d7b8ac763353acfd0792cea2a6dea423c85c62efb8448f398bc9425aee548b1cdb22cbb4d6d3a95eaf70' , 'hex' ) ;
112
+
59
113
it ( 'should get the corresponding authentication method instances' , function ( ) {
60
114
var manager = auth . createManager ( {
61
115
user : user ,
62
116
password : new Buffer ( password , 'utf8' ) ,
63
117
clientChallenge : clientChallenge
64
118
} ) ;
119
+ var authMethod0 = manager . getMethod ( method0 ) ;
120
+ Buffer . isBuffer ( authMethod0 . password ) . should . be . true ;
121
+ authMethod0 . password . toString ( 'utf8' ) . should . equal ( password ) ;
122
+
65
123
var authMethod1 = manager . getMethod ( method1 ) ;
66
124
Buffer . isBuffer ( authMethod1 . password ) . should . be . true ;
67
125
authMethod1 . password . toString ( 'utf8' ) . should . equal ( password ) ;
@@ -78,8 +136,8 @@ describe('Auth', function () {
78
136
clientChallenge : clientChallenge
79
137
} ) ;
80
138
manager . user . should . equal ( user ) ;
81
- manager . _authMethods . should . have . length ( 2 ) ;
82
- var authMethod = manager . _authMethods [ 1 ] ;
139
+ manager . _authMethods . should . have . length ( 3 ) ;
140
+ var authMethod = manager . _authMethods [ 2 ] ;
83
141
authMethod . name . should . equal ( method2 ) ;
84
142
authMethod . password . should . be . instanceof ( Buffer ) ;
85
143
authMethod . password . toString ( 'utf8' ) . should . eql ( password ) ;
@@ -88,7 +146,7 @@ describe('Auth', function () {
88
146
var initialData = authMethod . initialData ( ) ;
89
147
initialData . should . equal ( clientChallenge ) ;
90
148
initialData = manager . initialData ( ) ;
91
- initialData . should . eql ( [ user , method1 , clientChallenge , method2 , clientChallenge ] ) ;
149
+ initialData . should . eql ( [ user , method0 , ldapClientChallenge , method1 , clientChallenge , method2 , clientChallenge ] ) ;
92
150
// initialize manager
93
151
manager . initialize ( [ method2 , serverChallengeDataNoPBKDF2 ] , function ( err ) {
94
152
manager . _authMethod . should . equal ( authMethod ) ;
@@ -112,8 +170,8 @@ describe('Auth', function () {
112
170
clientChallenge : clientChallenge
113
171
} ) ;
114
172
manager . user . should . equal ( user ) ;
115
- manager . _authMethods . should . have . length ( 2 ) ;
116
- var authMethod = manager . _authMethods [ 0 ] ;
173
+ manager . _authMethods . should . have . length ( 3 ) ;
174
+ var authMethod = manager . _authMethods [ 1 ] ;
117
175
authMethod . name . should . equal ( method1 ) ;
118
176
authMethod . password . should . be . instanceof ( Buffer ) ;
119
177
authMethod . password . toString ( 'utf8' ) . should . eql ( password ) ;
@@ -122,7 +180,7 @@ describe('Auth', function () {
122
180
var initialData = authMethod . initialData ( ) ;
123
181
initialData . should . equal ( clientChallenge ) ;
124
182
initialData = manager . initialData ( ) ;
125
- initialData . should . eql ( [ user , method1 , clientChallenge , method2 , clientChallenge ] ) ;
183
+ initialData . should . eql ( [ user , method0 , ldapClientChallenge , method1 , clientChallenge , method2 , clientChallenge ] ) ;
126
184
// initialize manager
127
185
manager . initialize ( [ method1 , serverChallengeDataWithPBKDF2 ] , function ( err ) {
128
186
manager . _authMethod . should . equal ( authMethod ) ;
@@ -146,6 +204,45 @@ describe('Auth', function () {
146
204
} ) ;
147
205
} ) ;
148
206
207
+ it ( 'should authenticate and connect successfully with LDAP' , function ( done ) {
208
+ var manager = auth . createManager ( {
209
+ user : user ,
210
+ password : password ,
211
+ clientChallenge : clientChallenge ,
212
+ sessionKey : ldapSessionKey
213
+ } ) ;
214
+ manager . user . should . equal ( user ) ;
215
+ manager . _authMethods . should . have . length ( 3 ) ;
216
+ var authMethod = manager . _authMethods [ 0 ] ;
217
+ authMethod . name . should . equal ( method0 ) ;
218
+ authMethod . password . should . be . instanceof ( Buffer ) ;
219
+ authMethod . password . toString ( 'utf8' ) . should . eql ( password ) ;
220
+ authMethod . clientNonce . should . equal ( clientChallenge ) ;
221
+ authMethod . sessionKey . should . equal ( ldapSessionKey ) ;
222
+ // initial data
223
+ var initialData = authMethod . initialData ( ) ;
224
+ initialData . should . eql ( ldapClientChallenge ) ;
225
+ initialData = manager . initialData ( ) ;
226
+ initialData . should . eql ( [ user , method0 , ldapClientChallenge , method1 , clientChallenge , method2 , clientChallenge ] ) ;
227
+ // initialize manager
228
+ manager . initialize ( [ method0 , ldapServerChallenge ] , function ( err ) {
229
+ manager . _authMethod . should . equal ( authMethod ) ;
230
+ // clientProof
231
+ var ldapClientProof = authMethod . clientProof ;
232
+ var clientProofFields = Fields . read ( { buffer : ldapClientProof } ) ;
233
+ clientProofFields . length . should . eql ( 2 ) ;
234
+ clientProofFields [ 1 ] . should . eql ( ldapEncryptedPassword ) ;
235
+ // final data
236
+ var finalData = authMethod . finalData ( ) ;
237
+ finalData . should . eql ( ldapClientProof ) ;
238
+ finalData = manager . finalData ( ) ;
239
+ finalData . should . eql ( [ user , method0 , ldapClientProof ] ) ;
240
+ // finalize manager
241
+ manager . finalize ( [ method0 , null ] ) ;
242
+ done ( ) ;
243
+ } ) ;
244
+ } ) ;
245
+
149
246
it ( 'should write initial data fields part' , function ( ) {
150
247
var part = Fields . write ( { } , auth . createManager ( {
151
248
user : user ,
@@ -156,7 +253,7 @@ describe('Auth', function () {
156
253
var buffer = part . buffer ;
157
254
var offset = 0 ;
158
255
var field , length ;
159
- buffer . readUInt16LE ( offset ) . should . equal ( 5 ) ;
256
+ buffer . readUInt16LE ( offset ) . should . equal ( 7 ) ;
160
257
offset += 2 ;
161
258
// validate user
162
259
length = buffer [ offset ] ;
@@ -165,6 +262,20 @@ describe('Auth', function () {
165
262
offset += length ;
166
263
length . should . equal ( Buffer . byteLength ( user ) ) ;
167
264
field . should . equal ( user ) ;
265
+ // validate method0 name
266
+ length = buffer [ offset ] ;
267
+ offset += 1 ;
268
+ field = buffer . toString ( 'utf8' , offset , offset + length ) ;
269
+ offset += length ;
270
+ length . should . equal ( Buffer . byteLength ( method0 ) ) ;
271
+ field . should . equal ( method0 ) ;
272
+ // validate clientChallenge #0
273
+ length = buffer [ offset ] ;
274
+ offset += 1 ;
275
+ field = buffer . slice ( offset , offset + length ) ;
276
+ offset += length ;
277
+ length . should . equal ( ldapClientChallenge . length ) ;
278
+ field . should . eql ( ldapClientChallenge ) ;
168
279
// validate method1 name
169
280
length = buffer [ offset ] ;
170
281
offset += 1 ;
0 commit comments