Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-12643

wrong exit code from the shell when incorrectly connecting to an authenticated database

    • Type: Icon: Bug Bug
    • Resolution: Won't Fix
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 2.4.9
    • Component/s: Security, Shell
    • Labels:
    • Environment:
      MacOSX, but got the same under Linux
    • Server Tooling & Methods
    • ALL

      If you run an 'eval' query through 'mongo' on an authenticated database, you get the following:

      1) providing wrong credentials

      MacBook-Pro:mongotools me$ mongo --quiet --host 172.16.65.202 --port 27017 --username user --password pass --eval "printjson(db.adminCommand('listDatabases').databases)" test

      Thu Jan 30 13:23:39.744 Error: 18

      { code: 18, ok: 0.0, errmsg: "auth fails" }

      at src/mongo/shell/db.js:228
      exception: login failed

      MacBook-Pro:mongotools me$ echo $?
      1

      2) not trying to authenticate (missing user/password)

      MacBook-Pro:mongotools me$ mongo --quiet --host 172.16.65.202 --port 27017 --eval "printjson(db.adminCommand('listDatabases').databases)" test
      undefined

      MacBook-Pro:mongotools me$ echo $?
      0 <=== Incoherent

      In authenticating with wrong credentials (1), you get the expected error code (non-zero) from the shell.
      In not passing credentials (2), you get 'undefined' as the output, which is not really descriptive.
      But the main issue is getting 0 as the exit code.

      From a calling script, the result in providing no credentials or bad credentials should be the same.
      Also, I think it should be 1, as the expected result is not sent.

      Apart from being coherent with Unix commands, one scenario for which it is important to report a failure is the following:

      • write script, test it, deploy it.
      • authentication is added to the DB.
      • the initial script, not using auth, should start failing by seeing a different return code.

            Assignee:
            backlog-server-stm Backlog - Server Tooling and Methods (STM) (Inactive)
            Reporter:
            daniel.coupal@mongodb.com Daniel Coupal
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: