JackAdams / meteor-accounts-ldap

Authentication against an LDAP server in Meteor
MIT License
21 stars 12 forks source link

issue with serverDNs[k].split(/,?DC=/).slice(1).join('.'); #8

Closed feeloo007 closed 8 years ago

feeloo007 commented 9 years ago

Hi,

I have an issue with LDAP._bind.

I'm using Meteor 1.2.1 and meteor-accounts-ldap 0.4.0.

My settings file is :

{
  "ldap": {
    "serverDn": "DC=my,DC=domain",
    "serverUrl": "ldap://ldap.my.domain:389"
  }
}

I got this error :

I20151102-14:29:23.168(1)? LDAP authentication for feeloo007@my.domain
I20151102-14:29:23.169(1)? Trying to bind feeloo007@my.domain...
I20151102-14:29:23.175(1)? Callback from binding LDAP:
I20151102-14:29:23.176(1)? {"dn":"","code":34,"name":"InvalidDnSyntaxError","message":"Invalid DN"}
I20151102-14:29:23.176(1)? LDAP bind failed with error
I20151102-14:29:23.176(1)? {"dn":"","code":34,"name":"InvalidDnSyntaxError","message":"Invalid DN"}
I20151102-14:29:23.176(1)? Exception while invoking method 'login' TypeError: Object function (a) {                                                     // 2   // 10
I20151102-14:29:23.176(1)?   return this.filter(function(i) {                                                       // 3   // 11
I20151102-14:29:23.176(1)?     return a.indexOf(i) < 0;                                                             // 4   // 12
I20151102-14:29:23.176(1)?   });                                                                                    // 5   // 13
I20151102-14:29:23.176(1)? } has no method 'split'
I20151102-14:29:23.176(1)?     at Object.LDAP._bind (packages/babrahams_accounts-ldap/ldap_server.js:116:1)
I20151102-14:29:23.176(1)?     at [object Object].Package (packages/babrahams_accounts-ldap/ldap_server.js:287:1)
I20151102-14:29:23.176(1)?     at accounts_server.js:462:32
I20151102-14:29:23.176(1)?     at tryLoginMethod (accounts_server.js:239:14)
I20151102-14:29:23.177(1)?     at AccountsServer.Ap._runLoginHandlers (accounts_server.js:459:18)
I20151102-14:29:23.177(1)?     at [object Object].methods.login (accounts_server.js:522:27)
I20151102-14:29:23.177(1)?     at maybeAuditArgumentChecks (livedata_server.js:1698:12)
I20151102-14:29:23.177(1)?     at livedata_server.js:708:19
I20151102-14:29:23.177(1)?     at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)
I20151102-14:29:23.177(1)?     at livedata_server.js:706:40

The failing code is :

  var serverDNs = (typeof (settings.serverDn) == 'string') ? [settings.serverDn] : settings.serverDn;
  for (var k in serverDNs) {
    var serverDn = serverDNs[k].split(/,?DC=/).slice(1).join('.');
    ...
  }

In meteor shell, LDAP._settings().serverDn.split(/,?DC=/).slice(1).join('.') could be splitted.

LDAP._settings().serverDn.split(/,?DC=/).slice(1).join('.');
'my.domain'

But, if I made it in the loop, split method error is signaled.

Best regards

Philippe

JackAdams commented 9 years ago

I can't immediately see how that line of code is failing. Weird.

JackAdams commented 9 years ago

No ... wait a minute. It looks, from that error, like you've got a function as your serverDn. That won't work. You need to use this in server code:

LDAP.generateSettings = function (request) {
  return null; // replace null with an object that represents your settings  
}

Take a look at the example code at the bottom of the README.

feeloo007 commented 9 years ago

Thank you Jack.

Unfortunately, I have got same issue using LDAP.generateSettings.

Il will test with a fresh clean meteor's app.

Thanks for your help.

feeloo007 commented 9 years ago

Hi Jack,

Issue is correlated with the meteor's release (perhaps with ECMA script 6 support).

With older meteor version (1.1.0.2, used in meteor-accounts-ldap example from fresh git clone).

> l = [ 'test1' ]
["test1"]
> for ( k in l ) { console.log( k ) }
0

With latest version (meteor update on meteor-accounts-ldap example)

> l = [ 'test1' ]
["test1"]
> for ( k in l ) { console.log( k ) }
0
diff
equals

Best regards

JackAdams commented 9 years ago

Hey ... thanks for hunting that down. That's certainly the problem and it seems pretty fixable.

Looks like a bug in the ECMAScript 2015 support -- I wouldn't have thought that was expected behaviour.

JackAdams commented 8 years ago

I tested this and couldn't reproduce it. I don't think there's a problem with the ecmascript package after all. Something else is going on.

feeloo007 commented 8 years ago

Sorry, I missed the notification.

It's really strange. I will test with a clean meteor 1.2.1 if I got same issue with for in.

Have a nice week end

feeloo007 commented 8 years ago

Hi Jack,

I found issue's origin.

I use mickaelfm:vermongo in my project.

With this package installed, if auth fails with NoSushObjectError, the split error occurs.

Without this package installed, if auth fails with NoSushObjectError, the split doesn't occurs.

I will made an issue in mickaelfm:vermongo's github repository.

Thanks for your help !

Nice day

Philippe

JackAdams commented 8 years ago

Hey Philippe, Thanks for sharing the cause of the issue. Appreciate it.
The issue was quite a baffling one! Brent

feeloo007 commented 8 years ago

Thank you for your time Jack ! And your great packages :-)

Have a nice day

Philippe