def setUp(self):
        """Function:  setUp

        Description:  Initialization for unit testing.

        Arguments:

        """

        self.base_dir = "test/integration"
        self.config_dir = os.path.join(self.base_dir, "config")
        self.config_name = "mongo"
        self.cfg = gen_libs.load_module(self.config_name, self.config_dir)
        self.mongo = mongo_class.Server(
            self.cfg.name,
            self.cfg.user,
            self.cfg.japd,
            host=self.cfg.host,
            port=self.cfg.port,
            use_uri=self.cfg.use_uri,
            auth=self.cfg.auth,
            use_arg=self.cfg.use_arg,
            auth_db=self.cfg.auth_db,
            conf_file=self.cfg.conf_file,
            ssl_client_ca=self.cfg.ssl_client_ca,
            ssl_client_key=self.cfg.ssl_client_key,
            ssl_client_cert=self.cfg.ssl_client_cert,
            ssl_client_phrase=self.cfg.ssl_client_phrase)
        self.mongo.connect()
Exemple #2
0
    def test_login_fail(self):
        """Function:  test_login_fail

        Description:  Test with login failure.

        Arguments:

        """

        msg = "Authentication failed."
        errmsg = "Error:  Auth flag or login params is incorrect: %s" % msg
        mongo = mongo_class.Server(
            self.cfg.name,
            self.cfg.user,
            "mytestpd",
            host=self.cfg.host,
            port=self.cfg.port,
            use_uri=self.cfg.use_uri,
            auth=self.cfg.auth,
            use_arg=self.cfg.use_arg,
            auth_db=self.cfg.auth_db,
            conf_file=self.cfg.conf_file,
            ssl_client_ca=self.cfg.ssl_client_ca,
            ssl_client_key=self.cfg.ssl_client_key,
            ssl_client_cert=self.cfg.ssl_client_cert,
            ssl_client_phrase=self.cfg.ssl_client_phrase)
        mongo.conn = pymongo.MongoClient(mongo.conn_list,
                                         username=mongo.user,
                                         authSource=mongo.auth_db,
                                         **mongo.config)

        self.assertEqual(mongo.get_srv_attr(), (False, errmsg))
Exemple #3
0
    def test_connect(self):
        """Function:  test_connect

        Description:  Test with successful connection.

        Arguments:

        """

        mongo = mongo_class.Server(
            self.cfg.name,
            self.cfg.user,
            self.cfg.japd,
            host=self.cfg.host,
            port=self.cfg.port,
            use_uri=self.cfg.use_uri,
            auth=self.cfg.auth,
            use_arg=self.cfg.use_arg,
            auth_db=self.cfg.auth_db,
            conf_file=self.cfg.conf_file,
            ssl_client_ca=self.cfg.ssl_client_ca,
            ssl_client_key=self.cfg.ssl_client_key,
            ssl_client_cert=self.cfg.ssl_client_cert,
            ssl_client_phrase=self.cfg.ssl_client_phrase)
        mongo.conn = pymongo.MongoClient(mongo.conn_list,
                                         username=mongo.user,
                                         authSource=mongo.auth_db,
                                         **mongo.config)

        self.assertEqual(mongo.get_srv_attr(), (True, None))
Exemple #4
0
    def test_no_auth(self):
        """Function:  test_no_auth

        Description:  Test with no auth present.

        Arguments:

        """

        mongo = mongo_class.Server(
            self.cfg.name,
            self.cfg.user,
            self.cfg.japd,
            host=self.cfg.host,
            port=self.cfg.port,
            use_uri=self.cfg.use_uri,
            auth=False,
            use_arg=self.cfg.use_arg,
            auth_db=self.cfg.auth_db,
            conf_file=self.cfg.conf_file,
            ssl_client_ca=self.cfg.ssl_client_ca,
            ssl_client_key=self.cfg.ssl_client_key,
            ssl_client_cert=self.cfg.ssl_client_cert,
            ssl_client_phrase=self.cfg.ssl_client_phrase)

        self.assertEqual(mongo.connect(), (False, self.errmsg))
Exemple #5
0
    def setUp(self):

        """Function:  setUp

        Description:  Initialization for unit testing.

        Arguments:

        """

        self.base_dir = "test/integration"
        self.config_dir = os.path.join(self.base_dir, "config")
        self.config_name = "mongo"
        self.cfg = gen_libs.load_module(self.config_name, self.config_dir)
        self.mongo = mongo_class.Server(
            self.cfg.name, self.cfg.user, self.cfg.japd,
            host=self.cfg.host, port=self.cfg.port, auth=self.cfg.auth,
            conf_file=self.cfg.conf_file, auth_db=self.cfg.auth_db,
            use_arg=self.cfg.use_arg, use_uri=self.cfg.use_uri,
            ssl_client_ca=self.cfg.ssl_client_ca,
            ssl_client_key=self.cfg.ssl_client_key,
            ssl_client_cert=self.cfg.ssl_client_cert,
            ssl_client_phrase=self.cfg.ssl_client_phrase)

        self.cmd_line = ["program_name"]
        self.ssl = "--ssl"
        self.ssl_ca = "--sslCAFile="
        self.ssl_key = "--sslPEMKeyFile="
        self.ssl_phrase = "--sslPEMKeyPass"
        self.ca_file = "CAFile"
        self.key_file = "KeyFile"
        self.key_phrase = "KeyPhraseFile"
Exemple #6
0
    def test_conn_true2(self):
        """Function:  test_conn_true2

        Description:  Test with conn set to True.

        Arguments:

        """

        mongo = mongo_class.Server(
            self.cfg.name,
            self.cfg.user,
            self.cfg.japd,
            host=self.cfg.host,
            port=self.cfg.port,
            use_uri=self.cfg.use_uri,
            auth=self.cfg.auth,
            use_arg=self.cfg.use_arg,
            auth_db=self.cfg.auth_db,
            conf_file=self.cfg.conf_file,
            ssl_client_ca=self.cfg.ssl_client_ca,
            ssl_client_key=self.cfg.ssl_client_key,
            ssl_client_cert=self.cfg.ssl_client_cert,
            ssl_client_phrase=self.cfg.ssl_client_phrase)
        mongo.connect()

        self.assertEqual(mongo.connect(), (True, None))
Exemple #7
0
    def test_fail_get_srv_attr2(self):
        """Function:  test_fail_get_srv_attr2

        Description:  Test with failed get_srv_attr call.

        Arguments:

        """

        mongo = mongo_class.Server(
            self.cfg.name,
            self.cfg.user,
            "mytestpd",
            host=self.cfg.host,
            port=self.cfg.port,
            use_uri=self.cfg.use_uri,
            auth=self.cfg.auth,
            use_arg=self.cfg.use_arg,
            auth_db=self.cfg.auth_db,
            conf_file=self.cfg.conf_file,
            ssl_client_ca=self.cfg.ssl_client_ca,
            ssl_client_key=self.cfg.ssl_client_key,
            ssl_client_cert=self.cfg.ssl_client_cert,
            ssl_client_phrase=self.cfg.ssl_client_phrase)
        mongo.connect()

        self.assertEqual((mongo.name, mongo.user, mongo.japd, mongo.host,
                          mongo.port, mongo.use_arg),
                         (self.cfg.name, self.cfg.user, "mytestpd",
                          self.cfg.host, self.cfg.port, self.cfg.use_arg))
Exemple #8
0
    def test_change_pass(self):
        """Function:  test_change_pass

        Description:  Test change passwd and update config.

        Arguments:

        """

        global KEY1
        global KEY2

        new_config = {KEY1 + KEY2: self.new_japd}
        new_config["authMechanism"] = "SCRAM-SHA-1"
        mongo = mongo_class.Server(self.name,
                                   self.user,
                                   self.japd,
                                   self.host,
                                   self.port,
                                   conf_file=self.conf_file)
        mongo.japd = self.new_japd
        mongo.set_pass_config()

        self.assertEqual((mongo.config, mongo.japd),
                         (new_config, self.new_japd))
Exemple #9
0
    def test_auth_uri2(self):
        """Function:  test_auth_uri2

        Description:  Test with auth and uri present.

        Arguments:

        """

        mongo = mongo_class.Server(
            self.cfg.name,
            self.cfg.user,
            self.cfg.japd,
            host=self.cfg.host,
            port=self.cfg.port,
            use_uri=self.cfg.use_uri,
            auth=self.cfg.auth,
            use_arg=False,
            auth_db=True,
            conf_file=self.cfg.conf_file,
            ssl_client_ca=self.cfg.ssl_client_ca,
            ssl_client_key=self.cfg.ssl_client_key,
            ssl_client_cert=self.cfg.ssl_client_cert,
            ssl_client_phrase=self.cfg.ssl_client_phrase)
        mongo.connect()

        self.assertEqual((mongo.name, mongo.user, mongo.japd, mongo.host,
                          mongo.port, mongo.use_uri),
                         (self.cfg.name, self.cfg.user, self.cfg.japd,
                          self.cfg.host, self.cfg.port, self.cfg.use_uri))
Exemple #10
0
    def test_fail_get_srv_attr(self):
        """Function:  test_fail_get_srv_attr

        Description:  Test with failed get_srv_attr call.

        Arguments:

        """

        msg = "Authentication failed."
        errmsg = "Error:  Auth flag or login params is incorrect: %s" % msg

        mongo = mongo_class.Server(
            self.cfg.name,
            self.cfg.user,
            "mytestpd",
            host=self.cfg.host,
            port=self.cfg.port,
            use_uri=self.cfg.use_uri,
            auth=self.cfg.auth,
            use_arg=self.cfg.use_arg,
            auth_db=self.cfg.auth_db,
            conf_file=self.cfg.conf_file,
            ssl_client_ca=self.cfg.ssl_client_ca,
            ssl_client_key=self.cfg.ssl_client_key,
            ssl_client_cert=self.cfg.ssl_client_cert,
            ssl_client_phrase=self.cfg.ssl_client_phrase)

        self.assertEqual(mongo.connect(), (False, errmsg))
Exemple #11
0
    def test_conn_attr(self):

        """Function:  test_conn_attr

        Description:  Test conn attribute.

        Arguments:

        """

        mongo = mongo_class.Server(
            self.name, self.user, self.japd, host=self.host, port=self.port)

        self.assertFalse(mongo.conn)
Exemple #12
0
    def test_no_auth_uri(self):

        """Function:  test_no_auth_uri

        Description:  Test with auth and no uri present.

        Arguments:

        """

        mongo = mongo_class.Server(
            self.name, self.user, self.japd, host=self.host, port=self.port)

        self.assertFalse(mongo.use_uri)
Exemple #13
0
    def test_fetch_svr_info(self):
        """Function:  test_fetch_svr_info

        Description:  Test fetch_svr_info method.

        Arguments:

        """

        mongo = mongo_class.Server(self.name, self.user, self.japd, self.host,
                                   self.port)
        mongo.conn = ServerInfo()

        self.assertTrue(mongo.fetch_svr_info())
Exemple #14
0
    def test_using_no_auth_db(self):

        """Function:  test_using_no_auth_db

        Description:  Test using no auth_db attribute.

        Arguments:

        """

        mongo = mongo_class.Server(
            self.name, self.user, self.japd, host=self.host, port=self.port)

        self.assertEqual(mongo.auth_db, "admin")
Exemple #15
0
    def test_config_attr(self):

        """Function:  test_config_attr

        Description:  Test setting the config attribute.

        Arguments:

        """

        mongo = mongo_class.Server(
            self.name, self.user, self.japd, host=self.host, port=self.port)

        self.assertEqual(mongo.config, self.config2)
Exemple #16
0
    def test_no_conf_file_attr(self):

        """Function:  test_no_conf_file_attr

        Description:  Test no conf_file attribute passed.

        Arguments:

        """

        mongo = mongo_class.Server(
            self.name, self.user, self.japd, host=self.host, port=self.port)

        self.assertFalse(mongo.conf_file)
    def test_lock_db(self):
        """Function:  test_lock_db

        Description:  Test lock_db method.

        Arguments:

        """

        mongo = mongo_class.Server(self.name, self.user, self.japd, self.host,
                                   self.port)
        mongo.conn = LockDb()

        self.assertTrue(mongo.lock_db(lock=True))
Exemple #18
0
    def test_default_auth_mech(self):

        """Function:  test_default_auth_mech

        Description:  Test auth_mech default setting.

        Arguments:

        """

        mongo = mongo_class.Server(
            self.name, self.user, self.japd, host=self.host, port=self.port)

        self.assertEqual(mongo.auth_mech, self.auth_mech2)
Exemple #19
0
    def test_ssl_client_ca(self):

        """Function:  test_ssl_client_ca

        Description:  Test with ssl_client_ca attribute.

        Arguments:

        """

        mongo = mongo_class.Server(
            self.name, self.user, self.japd, host=self.host, port=self.port)

        self.assertEqual(mongo.ssl_client_ca, None)
Exemple #20
0
    def test_name_attr(self):

        """Function:  test_name_attr

        Description:  Test name attribute.

        Arguments:

        """

        mongo = mongo_class.Server(
            self.name, self.user, self.japd, host=self.host, port=self.port)

        self.assertEqual(mongo.name, self.name)
Exemple #21
0
    def test_db_path_attr(self):

        """Function:  test_db_path_attr

        Description:  Test db_path attribute.

        Arguments:

        """

        mongo = mongo_class.Server(
            self.cfg.name, self.cfg.user, self.cfg.japd, host=self.cfg.host,
            port=self.cfg.port)

        self.assertFalse(mongo.db_path)
Exemple #22
0
    def test_default_auth(self):

        """Function:  test_default_auth

        Description:  Test using the default auth setting.

        Arguments:

        """

        mongo = mongo_class.Server(
            self.cfg.name, self.cfg.user, self.cfg.japd, host=self.cfg.host,
            port=self.cfg.port)

        self.assertTrue(mongo.auth)
Exemple #23
0
    def test_conf_file_attr(self):

        """Function:  test_conf_file_attr

        Description:  Test conf_file attribute passed.

        Arguments:

        """

        mongo = mongo_class.Server(
            self.cfg.name, self.cfg.user, self.cfg.japd, host=self.cfg.host,
            port=self.cfg.port, conf_file="myfile")

        self.assertEqual(mongo.conf_file, "myfile")
Exemple #24
0
    def test_adm_cmd(self):

        """Function:  test_adm_cmd

        Description:  Test adm_cmd method.

        Arguments:

        """

        mongo = mongo_class.Server(self.name, self.user, self.japd,
                                   self.host, self.port)
        mongo.conn = Admin1()

        self.assertTrue(mongo.adm_cmd(self.cmd))
Exemple #25
0
    def test_arg(self):

        """Function:  test_arg

        Description:  Test with argument passed.

        Arguments:

        """

        mongo = mongo_class.Server(self.name, self.user, self.japd,
                                   self.host, self.port)
        mongo.conn = Admin1()

        self.assertTrue(mongo.adm_cmd(self.cmd, arg1=self.arg1))
Exemple #26
0
    def test_using_auth(self):

        """Function:  test_using_auth

        Description:  Test using the auth connection.

        Arguments:

        """

        mongo = mongo_class.Server(
            self.cfg.name, self.cfg.user, self.cfg.japd, host=self.cfg.host,
            port=self.cfg.port, auth=False)

        self.assertFalse(mongo.auth)
Exemple #27
0
    def test_using_uri(self):

        """Function:  test_using_uri

        Description:  Test using the uri connection.

        Arguments:

        """

        mongo = mongo_class.Server(
            self.cfg.name, self.cfg.user, self.cfg.japd, host=self.cfg.host,
            port=self.cfg.port, use_uri=True)

        self.assertTrue(mongo.use_uri)
Exemple #28
0
    def test_fetch_dbs(self):

        """Function:  test_fetch_dbs

        Description:  Test fetch_dbs method.

        Arguments:

        """

        mongo = mongo_class.Server(self.name, self.user, self.japd,
                                   self.host, self.port)
        mongo.conn = FetchAdr()

        self.assertTrue(mongo.fetch_dbs())
Exemple #29
0
    def test_using_auth_db(self):

        """Function:  test_using_auth_db

        Description:  Test using the auth_db attribute.

        Arguments:

        """

        mongo = mongo_class.Server(
            self.cfg.name, self.cfg.user, self.cfg.japd, host=self.cfg.host,
            port=self.cfg.port, auth_db=self.cfg.auth_db)

        self.assertEqual(mongo.auth_db, self.cfg.auth_db)
Exemple #30
0
    def test_no_using_arg(self):

        """Function:  test_no_using_arg

        Description:  Test with auth and no arg present.

        Arguments:

        """

        mongo = mongo_class.Server(
            self.cfg.name, self.cfg.user, self.cfg.japd, host=self.cfg.host,
            port=self.cfg.port)

        self.assertFalse(mongo.use_arg)