tests:
    -
        description: "should use the default source and mechanism"
        uri: "mongodb://user:password@localhost"
        valid: true
        credential:
            username: "user"
            password: "password"
            source: "admin"
            mechanism: ~
            mechanism_properties: ~
    -
        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: ~
            mechanism_properties: ~
    -
        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: ~
            mechanism_properties: ~
    -
        description: "should recognise the mechanism (GSSAPI)"
        uri: "mongodb://user%40DOMAIN.COM@localhost/?authMechanism=GSSAPI"
        valid: true
        credential:
            username: "user@DOMAIN.COM"
            password: ~
            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: ~
            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: ~
            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: ~
            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: ~
    -
        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: ~
    -
        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: ~
    -
        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: ~
            source: "$external"
            mechanism: "MONGODB-X509"
            mechanism_properties: ~
    -
        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: ~
            source: "$external"
            mechanism: "MONGODB-X509"
            mechanism_properties: ~
    -
        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: ~
            source: "$external"
            mechanism: "MONGODB-X509"
            mechanism_properties: ~
    -
        description: "should recognize the mechanism with no username (MONGODB-X509)"
        uri: "mongodb://localhost/?authMechanism=MONGODB-X509"
        valid: true
        credential:
            username: ~
            password: ~
            source: "$external"
            mechanism: "MONGODB-X509"
            mechanism_properties: ~
    -
        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: ~
    -
        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: ~
    -
        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: ~
    -
        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: ~
    -
        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: ~
    -
        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: ~
    -
        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: ~
    -
        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: ~
    -
        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: ~
    -
        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: ~
    -
        description: "database in URI path doesn't create credentials"
        uri: "mongodb://localhost/foo"
        valid: true
        credential: ~
    -
        description: "authSource without username is invalid (default mechanism)"
        uri: "mongodb://localhost/?authSource=foo"
        valid: false
