{
  "tests": [
    {
      "description": "should use the default source and mechanism",
      "uri": "mongodb://user:password@localhost",
      "valid": true,
      "credential": {
        "username": "user",
        "password": "password",
        "source": "admin",
        "mechanism": null,
        "mechanism_properties": null
      }
    },
    {
      "description": "should use the database when no authSource is specified",
      "uri": "mongodb://user:password@localhost/foo",
      "valid": true,
      "credential": {
        "username": "user",
        "password": "password",
        "source": "foo",
        "mechanism": null,
        "mechanism_properties": null
      }
    },
    {
      "description": "should use the authSource when specified",
      "uri": "mongodb://user:password@localhost/foo?authSource=bar",
      "valid": true,
      "credential": {
        "username": "user",
        "password": "password",
        "source": "bar",
        "mechanism": null,
        "mechanism_properties": null
      }
    },
    {
      "description": "should recognise the mechanism (GSSAPI)",
      "uri": "mongodb://user%40DOMAIN.COM@localhost/?authMechanism=GSSAPI",
      "valid": true,
      "credential": {
        "username": "user@DOMAIN.COM",
        "password": null,
        "source": "$external",
        "mechanism": "GSSAPI",
        "mechanism_properties": {
          "SERVICE_NAME": "mongodb"
        }
      }
    },
    {
      "description": "should ignore the database (GSSAPI)",
      "uri": "mongodb://user%40DOMAIN.COM@localhost/foo?authMechanism=GSSAPI",
      "valid": true,
      "credential": {
        "username": "user@DOMAIN.COM",
        "password": null,
        "source": "$external",
        "mechanism": "GSSAPI",
        "mechanism_properties": {
          "SERVICE_NAME": "mongodb"
        }
      }
    },
    {
      "description": "should accept valid authSource (GSSAPI)",
      "uri": "mongodb://user%40DOMAIN.COM@localhost/?authMechanism=GSSAPI&authSource=$external",
      "valid": true,
      "credential": {
        "username": "user@DOMAIN.COM",
        "password": null,
        "source": "$external",
        "mechanism": "GSSAPI",
        "mechanism_properties": {
          "SERVICE_NAME": "mongodb"
        }
      }
    },
    {
      "description": "should accept generic mechanism property (GSSAPI)",
      "uri": "mongodb://user%40DOMAIN.COM@localhost/?authMechanism=GSSAPI&authMechanismProperties=SERVICE_NAME:other,CANONICALIZE_HOST_NAME:true",
      "valid": true,
      "credential": {
        "username": "user@DOMAIN.COM",
        "password": null,
        "source": "$external",
        "mechanism": "GSSAPI",
        "mechanism_properties": {
          "SERVICE_NAME": "other",
          "CANONICALIZE_HOST_NAME": true
        }
      }
    },
    {
      "description": "should accept the password (GSSAPI)",
      "uri": "mongodb://user%40DOMAIN.COM:password@localhost/?authMechanism=GSSAPI&authSource=$external",
      "valid": true,
      "credential": {
        "username": "user@DOMAIN.COM",
        "password": "password",
        "source": "$external",
        "mechanism": "GSSAPI",
        "mechanism_properties": {
          "SERVICE_NAME": "mongodb"
        }
      }
    },
    {
      "description": "should throw an exception if authSource is invalid (GSSAPI)",
      "uri": "mongodb://user%40DOMAIN.COM@localhost/?authMechanism=GSSAPI&authSource=foo",
      "valid": false
    },
    {
      "description": "should throw an exception if no username (GSSAPI)",
      "uri": "mongodb://localhost/?authMechanism=GSSAPI",
      "valid": false
    },
    {
      "description": "should recognize the mechanism (MONGODB-CR)",
      "uri": "mongodb://user:password@localhost/?authMechanism=MONGODB-CR",
      "valid": true,
      "credential": {
        "username": "user",
        "password": "password",
        "source": "admin",
        "mechanism": "MONGODB-CR",
        "mechanism_properties": null
      }
    },
    {
      "description": "should use the database when no authSource is specified (MONGODB-CR)",
      "uri": "mongodb://user:password@localhost/foo?authMechanism=MONGODB-CR",
      "valid": true,
      "credential": {
        "username": "user",
        "password": "password",
        "source": "foo",
        "mechanism": "MONGODB-CR",
        "mechanism_properties": null
      }
    },
    {
      "description": "should use the authSource when specified (MONGODB-CR)",
      "uri": "mongodb://user:password@localhost/foo?authMechanism=MONGODB-CR&authSource=bar",
      "valid": true,
      "credential": {
        "username": "user",
        "password": "password",
        "source": "bar",
        "mechanism": "MONGODB-CR",
        "mechanism_properties": null
      }
    },
    {
      "description": "should throw an exception if no username is supplied (MONGODB-CR)",
      "uri": "mongodb://localhost/?authMechanism=MONGODB-CR",
      "valid": false
    },
    {
      "description": "should recognize the mechanism (MONGODB-X509)",
      "uri": "mongodb://CN%3DmyName%2COU%3DmyOrgUnit%2CO%3DmyOrg%2CL%3DmyLocality%2CST%3DmyState%2CC%3DmyCountry@localhost/?authMechanism=MONGODB-X509",
      "valid": true,
      "credential": {
        "username": "CN=myName,OU=myOrgUnit,O=myOrg,L=myLocality,ST=myState,C=myCountry",
        "password": null,
        "source": "$external",
        "mechanism": "MONGODB-X509",
        "mechanism_properties": null
      }
    },
    {
      "description": "should ignore the database (MONGODB-X509)",
      "uri": "mongodb://CN%3DmyName%2COU%3DmyOrgUnit%2CO%3DmyOrg%2CL%3DmyLocality%2CST%3DmyState%2CC%3DmyCountry@localhost/foo?authMechanism=MONGODB-X509",
      "valid": true,
      "credential": {
        "username": "CN=myName,OU=myOrgUnit,O=myOrg,L=myLocality,ST=myState,C=myCountry",
        "password": null,
        "source": "$external",
        "mechanism": "MONGODB-X509",
        "mechanism_properties": null
      }
    },
    {
      "description": "should accept valid authSource (MONGODB-X509)",
      "uri": "mongodb://CN%3DmyName%2COU%3DmyOrgUnit%2CO%3DmyOrg%2CL%3DmyLocality%2CST%3DmyState%2CC%3DmyCountry@localhost/?authMechanism=MONGODB-X509&authSource=$external",
      "valid": true,
      "credential": {
        "username": "CN=myName,OU=myOrgUnit,O=myOrg,L=myLocality,ST=myState,C=myCountry",
        "password": null,
        "source": "$external",
        "mechanism": "MONGODB-X509",
        "mechanism_properties": null
      }
    },
    {
      "description": "should recognize the mechanism with no username (MONGODB-X509)",
      "uri": "mongodb://localhost/?authMechanism=MONGODB-X509",
      "valid": true,
      "credential": {
        "username": null,
        "password": null,
        "source": "$external",
        "mechanism": "MONGODB-X509",
        "mechanism_properties": null
      }
    },
    {
      "description": "should throw an exception if supplied a password (MONGODB-X509)",
      "uri": "mongodb://user:password@localhost/?authMechanism=MONGODB-X509",
      "valid": false
    },
    {
      "description": "should throw an exception if authSource is invalid (MONGODB-X509)",
      "uri": "mongodb://CN%3DmyName%2COU%3DmyOrgUnit%2CO%3DmyOrg%2CL%3DmyLocality%2CST%3DmyState%2CC%3DmyCountry@localhost/foo?authMechanism=MONGODB-X509&authSource=bar",
      "valid": false
    },
    {
      "description": "should recognize the mechanism (PLAIN)",
      "uri": "mongodb://user:password@localhost/?authMechanism=PLAIN",
      "valid": true,
      "credential": {
        "username": "user",
        "password": "password",
        "source": "$external",
        "mechanism": "PLAIN",
        "mechanism_properties": null
      }
    },
    {
      "description": "should use the database when no authSource is specified (PLAIN)",
      "uri": "mongodb://user:password@localhost/foo?authMechanism=PLAIN",
      "valid": true,
      "credential": {
        "username": "user",
        "password": "password",
        "source": "foo",
        "mechanism": "PLAIN",
        "mechanism_properties": null
      }
    },
    {
      "description": "should use the authSource when specified (PLAIN)",
      "uri": "mongodb://user:password@localhost/foo?authMechanism=PLAIN&authSource=bar",
      "valid": true,
      "credential": {
        "username": "user",
        "password": "password",
        "source": "bar",
        "mechanism": "PLAIN",
        "mechanism_properties": null
      }
    },
    {
      "description": "should throw an exception if no username (PLAIN)",
      "uri": "mongodb://localhost/?authMechanism=PLAIN",
      "valid": false
    },
    {
      "description": "should recognize the mechanism (SCRAM-SHA-1)",
      "uri": "mongodb://user:password@localhost/?authMechanism=SCRAM-SHA-1",
      "valid": true,
      "credential": {
        "username": "user",
        "password": "password",
        "source": "admin",
        "mechanism": "SCRAM-SHA-1",
        "mechanism_properties": null
      }
    },
    {
      "description": "should use the database when no authSource is specified (SCRAM-SHA-1)",
      "uri": "mongodb://user:password@localhost/foo?authMechanism=SCRAM-SHA-1",
      "valid": true,
      "credential": {
        "username": "user",
        "password": "password",
        "source": "foo",
        "mechanism": "SCRAM-SHA-1",
        "mechanism_properties": null
      }
    },
    {
      "description": "should accept valid authSource (SCRAM-SHA-1)",
      "uri": "mongodb://user:password@localhost/foo?authMechanism=SCRAM-SHA-1&authSource=bar",
      "valid": true,
      "credential": {
        "username": "user",
        "password": "password",
        "source": "bar",
        "mechanism": "SCRAM-SHA-1",
        "mechanism_properties": null
      }
    },
    {
      "description": "should throw an exception if no username (SCRAM-SHA-1)",
      "uri": "mongodb://localhost/?authMechanism=SCRAM-SHA-1",
      "valid": false
    },
    {
      "description": "should recognize the mechanism (SCRAM-SHA-256)",
      "uri": "mongodb://user:password@localhost/?authMechanism=SCRAM-SHA-256",
      "valid": true,
      "credential": {
        "username": "user",
        "password": "password",
        "source": "admin",
        "mechanism": "SCRAM-SHA-256",
        "mechanism_properties": null
      }
    },
    {
      "description": "should use the database when no authSource is specified (SCRAM-SHA-256)",
      "uri": "mongodb://user:password@localhost/foo?authMechanism=SCRAM-SHA-256",
      "valid": true,
      "credential": {
        "username": "user",
        "password": "password",
        "source": "foo",
        "mechanism": "SCRAM-SHA-256",
        "mechanism_properties": null
      }
    },
    {
      "description": "should accept valid authSource (SCRAM-SHA-256)",
      "uri": "mongodb://user:password@localhost/foo?authMechanism=SCRAM-SHA-256&authSource=bar",
      "valid": true,
      "credential": {
        "username": "user",
        "password": "password",
        "source": "bar",
        "mechanism": "SCRAM-SHA-256",
        "mechanism_properties": null
      }
    },
    {
      "description": "should throw an exception if no username (SCRAM-SHA-256)",
      "uri": "mongodb://localhost/?authMechanism=SCRAM-SHA-256",
      "valid": false
    },
    {
      "description": "URI with no auth-related info doesn't create credential",
      "uri": "mongodb://localhost/",
      "valid": true,
      "credential": null
    },
    {
      "description": "database in URI path doesn't create credentials",
      "uri": "mongodb://localhost/foo",
      "valid": true,
      "credential": null
    },
    {
      "description": "authSource without username doesn't create credential (default mechanism)",
      "uri": "mongodb://localhost/?authSource=foo",
      "valid": true,
      "credential": null
    },
    {
      "description": "should throw an exception if no username provided (userinfo implies default mechanism)",
      "uri": "mongodb://@localhost.com/",
      "valid": false
    },
    {
      "description": "should throw an exception if no username/password provided (userinfo implies default mechanism)",
      "uri": "mongodb://:@localhost.com/",
      "valid": false
    }
  ]
}

