Example #1
0
    def setup_auth(self):
        """Set self.auth and self.uri, and maybe create an admin user."""
        try:
            cmd_line = self.sync_cx.admin.command('getCmdLineOpts')
        except pymongo.errors.OperationFailure as e:
            msg = e.details.get('errmsg', '')
            if e.code == 13 or 'unauthorized' in msg or 'login' in msg:
                # Unauthorized.
                self.auth = True
            else:
                raise
        else:
            # Either we're on mongod < 2.7.1 and we can connect over localhost
            # to check if --auth is in the command line. Or we're prohibited
            # from seeing the command line so we should try blindly to create
            # an admin user.
            try:
                authorization = safe_get(cmd_line,
                                         'parsed.security.authorization')
                if authorization:
                    self.auth = (authorization == 'enabled')
                else:
                    argv = cmd_line['argv']
                    self.auth = ('--auth' in argv or '--keyFile' in argv)
            except pymongo.errors.OperationFailure as e:
                if e.code == 13:
                    # Auth failure getting command line.
                    self.auth = True
                else:
                    raise

        if self.auth:
            uri_template = 'mongodb://%s:%s@%s:%s/admin'
            self.uri = uri_template % (db_user, db_password, self.host,
                                       self.port)

            # If the hostname 'server' is resolvable, this URI lets us use it
            # to test SSL hostname validation with auth.
            self.fake_hostname_uri = uri_template % (db_user, db_password,
                                                     'server', self.port)

            try:
                self.sync_cx.admin.add_user(db_user,
                                            db_password,
                                            roles=['root'])
            except pymongo.errors.OperationFailure:
                # User was added before setup(), e.g. by Mongo Orchestration.
                self.user_provided = True

            self.sync_cx.admin.authenticate(db_user, db_password)

        else:
            self.uri = 'mongodb://%s:%s/admin' % (self.host, self.port)

            self.fake_hostname_uri = 'mongodb://%s:%s/admin' % ('server',
                                                                self.port)

        if self.rs_name:
            self.rs_uri = self.uri + '?replicaSet=' + self.rs_name
Example #2
0
    def setup_auth(self):
        """Set self.auth and self.uri, and maybe create an admin user."""
        try:
            cmd_line = self.sync_cx.admin.command('getCmdLineOpts')
        except pymongo.errors.OperationFailure as e:
            msg = e.details.get('errmsg', '')
            if e.code == 13 or 'unauthorized' in msg or 'login' in msg:
                # Unauthorized.
                self.auth = True
            else:
                raise
        else:
            # Either we're on mongod < 2.7.1 and we can connect over localhost
            # to check if --auth is in the command line. Or we're prohibited
            # from seeing the command line so we should try blindly to create
            # an admin user.
            try:
                authorization = safe_get(cmd_line,
                                         'parsed.security.authorization')
                if authorization:
                    self.auth = (authorization == 'enabled')
                else:
                    argv = cmd_line['argv']
                    self.auth = ('--auth' in argv or '--keyFile' in argv)
            except pymongo.errors.OperationFailure as e:
                if e.code == 13:
                    # Auth failure getting command line.
                    self.auth = True
                else:
                    raise

        if self.auth:
            uri_template = 'mongodb://%s:%s@%s:%s/admin'
            self.uri = uri_template % (db_user, db_password,
                                       self.host, self.port)

            # If the hostname 'server' is resolvable, this URI lets us use it
            # to test SSL hostname validation with auth.
            self.fake_hostname_uri = uri_template % (
                db_user, db_password, 'server', self.port)

            try:
                self.sync_cx.admin.add_user(db_user, db_password,
                                            roles=['root'])
            except pymongo.errors.OperationFailure:
                # User was added before setup(), e.g. by Mongo Orchestration.
                self.user_provided = True

            self.sync_cx.admin.authenticate(db_user, db_password)

        else:
            self.uri = 'mongodb://%s:%s/admin' % (
                self.host, self.port)

            self.fake_hostname_uri = 'mongodb://%s:%s/admin' % (
                'server', self.port)

        if self.rs_name:
            self.rs_uri = self.uri + '?replicaSet=' + self.rs_name
    def maybe_skip(self):
        if (yield server_is_mongos(self.cx)):
            raise SkipTest("mongos has no maxTimeAlwaysTimeOut fail point")

        cmdline = yield get_command_line(self.cx)
        if '1' != safe_get(cmdline, 'parsed.setParameter.enableTestCommands'):
            if 'enableTestCommands=1' not in cmdline['argv']:
                raise SkipTest("testing maxTimeMS requires failpoints")
Example #4
0
    async def maybe_skip(self):
        if await server_is_mongos(self.cx):
            raise SkipTest("mongos has no maxTimeAlwaysTimeOut fail point")

        cmdline = await get_command_line(self.cx)
        if "1" != safe_get(cmdline, "parsed.setParameter.enableTestCommands"):
            if "enableTestCommands=1" not in cmdline["argv"]:
                raise SkipTest("testing maxTimeMS requires failpoints")
Example #5
0
    def maybe_skip(self):
        if (yield server_is_mongos(self.cx)):
            raise SkipTest("mongos has no maxTimeAlwaysTimeOut fail point")

        cmdline = yield get_command_line(self.cx)
        if '1' != safe_get(cmdline, 'parsed.setParameter.enableTestCommands'):
            if 'enableTestCommands=1' not in cmdline['argv']:
                raise SkipTest("testing maxTimeMS requires failpoints")
Example #6
0
    def maybe_skip(self):
        if (yield server_is_mongos(self.cx)):
            raise SkipTest("mongos has no maxTimeAlwaysTimeOut fail point")

        if not (yield at_least(self.cx, (2, 5, 3, -1))):
            raise SkipTest("maxTimeMS requires MongoDB >= 2.5.3")

        cmdline = yield get_command_line(self.cx)
        if "1" != safe_get(cmdline, "parsed.setParameter.enableTestCommands"):
            if "enableTestCommands=1" not in cmdline["argv"]:
                raise SkipTest("testing maxTimeMS requires failpoints")