telefonicaid / iotagent-node-lib

Module to enable IoT Agent developers to build custom agents for their devices that can easily connect to NGSI Context Brokers
https://iotagent-node-lib.rtfd.io/
GNU Affero General Public License v3.0
60 stars 85 forks source link

MongoDB doesnt support authentication #1510

Closed cblancog00 closed 9 months ago

cblancog00 commented 10 months ago

IoT Agent Node Lib version the issue has been seen with

3.4.4

Bound or port used (API interaction)

Other

NGSI version

NGSI-LD

Are you running a container?

Yes, I am using a contaner (Docker, Kubernetes...)

Image type

normal

Expected behaviour you didn't see

I moved this issue from the iotagent-json repo: https://github.com/telefonicaid/iotagent-json/issues/739

The error was not related to the iotagent, instead it's related to the iotagent-node-lib who is the resposible of the Mongo connection.

When setting a mongo connection with authentication using user and password it fails throwing an Authentication Fail error. I've been looking throw the code and it seems to be related to the iotagent-node-lib/lib/model/dbConn.js And it seems to only generates connection strings without autentication

https://github.com/telefonicaid/iotagent-node-lib/blob/master/lib/model/dbConn.js

Test passes, cause an expected result it's bad defined cause in mongo connection strings user and password goes before the host

{ mongodb: { host: 'example.com', port: '98765', db: 'examples', replicaSet: 'rs0', user: 'user01', password: 'pass01', authSource: 'admin' }, expected: { url: 'mongodb://example.com:98765/examples', options: { replicaSet: 'rs0', auth: { user: 'user01', password: 'pass01' }, authSource: 'admin', useNewUrlParser: true, useUnifiedTopology: true } } },

The error should be solved easily, checking if the options.auth is present and concat into the url string. Located in th e init function

Unexpected behaviour you saw

No response

Steps to reproduce the problem

No response

Configs

No response

Log output

No response

fgalan commented 9 months ago

PR #1511