kuzzleio / kuzzle

Open-source Back-end, self-hostable & ready to use - Real-time, storage, advanced search - Web, Apps, Mobile, IoT -
https://kuzzle.io
Apache License 2.0
1.44k stars 124 forks source link

Configuring plugin oAauth makes Kuzzle crash at startup #501

Closed xbill82 closed 8 years ago

xbill82 commented 8 years ago

Steps to reproduce:

{
  "strategies": {
    "google-oauth": {
        "credentials": {
          "consumerKey": "PUT_SOME_KEY_HERE",
          "consumerSecret": "PUT_SOME_SECRET_HERE",
          "callbackUrl": "http://host:7511/api/1.0/_login/google-plus"
        },
        "persist": [
          "login",
          "avatar_url",
          "name",
          "email"
        ],
        "scope": [
          "user:email",
          "user:avatar_url"
        ]
    }
  }
}

Receiving many errors like

kuzzle_1 | KuzzleServer-0 TypeError: Invalid argument expected string
kuzzle_1 | KuzzleServer-0     at validate (/var/app/node_modules/compare-versions/index.js:29:19)
kuzzle_1 | KuzzleServer-0     at Array.forEach (native)
kuzzle_1 | KuzzleServer-0     at compareVersions (/var/app/node_modules/compare-versions/index.js:37:18)
kuzzle_1 | KuzzleServer-0     at /var/app/lib/api/core/plugins/packages/pluginPackage.js:140:14
kuzzle_1 | KuzzleServer-0     at tryCallOne (/var/app/node_modules/elasticsearch/node_modules/promise/lib/core.js:37:12)
kuzzle_1 | KuzzleServer-0     at /var/app/node_modules/elasticsearch/node_modules/promise/lib/core.js:123:15
kuzzle_1 | KuzzleServer-0     at flush (/var/app/node_modules/elasticsearch/node_modules/promise/node_modules/asap/raw.js:50:29)
kuzzle_1 | KuzzleServer-0     at nextTickCallbackWith0Args (node.js:420:9)
kuzzle_1 | KuzzleServer-0     at process._tickDomainCallback (node.js:390:13)
xbill82 commented 8 years ago

The problems seems to happen at the compareVersions call at lib/api/core/plugins/packages/pluginPackage.js:140

xbill82 commented 8 years ago

After inspecting the arguments passed to compareVersions (via console.log LOL) I realized that, in certain cases, the config.version (i.e. the one fetched from the DB) is undefined. Not sure why this happens (I assume that my plugin had been installed before restarting Kuzzle), but adding an extra if solves the problem.

xbill82 commented 8 years ago

Wait, but... The version field for the plugin is actually never written in the persisted configuration. Going to investigate this.

xbill82 commented 8 years ago

Ok, seems that the PluginPackage is unable to detect the installed version based on the output of npm install. The regexp at https://github.com/kuzzleio/kuzzle/blob/501-startup-crash-after-plugin-install/lib/api/core/plugins/packages/pluginPackage.js#L199 does not match the standard output of npm

kuzzle-plugin-auth-passport-oauth@2.0.3 node_modules/kuzzle-plugin-auth-passport-oauth
 ├── passport-oauth2-refresh@1.0.0
 └── passport-oauth2@1.3.0 (uid2@0.0.3, oauth@0.9.14)

So the version number is never found.

xbill82 commented 8 years ago

Ok, so #503 now fixes the version detection on npm install. But now I wonder if it's a good idea to install the plugin if the version is not found in the definition fetched from the DB.