コード例 #1
0
    def test_make_changeuser(self):
        """Make a change user MySQL packet"""
        exp = {
            "allset": bytearray(
                b"\x11\x68\x61\x6d\x00\x14\x3a\x07"
                b"\x66\xba\xba\x01\xce\xbe\x55\xe6\x29\x88\xaa\xae"
                b"\xdb\x00\xb3\x4d\x91\x5b\x74\x65\x73\x74\x00\x08"
                b"\x00"
            ),
            "nopass": bytearray(b"\x11\x68\x61\x6d\x00\x00\x74\x65" b"\x73\x74\x00\x08\x00"),
        }
        kwargs = {
            "handshake": None,
            "username": "******",
            "password": "******",
            "database": "test",
            "charset": 8,
            "client_flags": ClientFlag.get_default(),
        }
        self.assertRaises(errors.ProgrammingError, self._protocol.make_change_user, **kwargs)

        kwargs["handshake"] = {"auth_data": SEED}
        self.assertRaises(errors.ProgrammingError, self._protocol.make_change_user, **kwargs)

        kwargs["handshake"] = {"auth_data": SEED, "auth_plugin": "mysql_native_password"}
        res = self._protocol.make_change_user(**kwargs)
        self.assertEqual(exp["allset"], res)

        kwargs["password"] = None
        res = self._protocol.make_change_user(**kwargs)
        self.assertEqual(exp["nopass"], res)
コード例 #2
0
    def test_make_auth(self):
        """Make a MySQL authentication packet"""
        exp = {
            'allset':\
            '\x0d\xa2\x03\x00\x00\x00\x00\x40'\
            '\x21\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'\
            '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'\
            '\x68\x61\x6d\x00\x14\x3a\x07\x66\xba\xba\x01\xce'\
            '\xbe\x55\xe6\x29\x88\xaa\xae\xdb\x00\xb3\x4d\x91'\
            '\x5b\x74\x65\x73\x74\x00',
            'nopass':\
            '\x0d\xa2\x03\x00\x00\x00\x00\x40'\
            '\x21\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'\
            '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'\
            '\x68\x61\x6d\x00\x00\x74\x65\x73\x74\x00',
            'nouser':\
            '\x0d\xa2\x03\x00\x00\x00\x00\x40'\
            '\x21\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'\
            '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'\
            '\x00\x14\x3a\x07\x66\xba\xba\x01\xce'\
            '\xbe\x55\xe6\x29\x88\xaa\xae\xdb\x00\xb3\x4d\x91'\
            '\x5b\x74\x65\x73\x74\x00',
            'nodb':\
            '\x0d\xa2\x03\x00\x00\x00\x00\x40'\
            '\x21\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'\
            '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'\
            '\x68\x61\x6d\x00\x14\x3a\x07\x66\xba\xba\x01\xce'\
            '\xbe\x55\xe6\x29\x88\xaa\xae\xdb\x00\xb3\x4d\x91'\
            '\x5b\x00',
            }
        flags = ClientFlag.get_default()
        kwargs = {
            'seed': None,
            'username': '******',
            'password': '******',
            'database': 'test',
            'charset': 33,
            'client_flags': flags
        }

        self.assertRaises(errors.ProgrammingError, self._protocol.make_auth,
                          **kwargs)

        kwargs['seed'] = SEED
        res = self._protocol.make_auth(**kwargs)
        self.assertEqual(exp['allset'], res)

        kwargs['password'] = None
        res = self._protocol.make_auth(**kwargs)
        self.assertEqual(exp['nopass'], res)

        kwargs['password'] = '******'
        kwargs['database'] = None
        res = self._protocol.make_auth(**kwargs)
        self.assertEqual(exp['nodb'], res)

        kwargs['username'] = None
        kwargs['database'] = 'test'
        res = self._protocol.make_auth(**kwargs)
        self.assertEqual(exp['nouser'], res)
コード例 #3
0
    def test_make_changeuser(self):
        """Make a change user MySQL packet"""
        exp = {
            'allset':
            b'\x11\x68\x61\x6d\x00\x14\x3a\x07'
            b'\x66\xba\xba\x01\xce\xbe\x55\xe6\x29\x88\xaa\xae'
            b'\xdb\x00\xb3\x4d\x91\x5b\x74\x65\x73\x74\x00\x08'
            b'\x00',
            'nopass':
            b'\x11\x68\x61\x6d\x00\x00\x74\x65'
            b'\x73\x74\x00\x08\x00',
        }
        kwargs = {
            'seed': None,
            'username': '******',
            'password': '******',
            'database': 'test',
            'charset': 8,
            'client_flags': ClientFlag.get_default()
        }
        self.assertRaises(errors.ProgrammingError,
                          self._protocol.make_change_user, **kwargs)

        kwargs['seed'] = SEED
        res = self._protocol.make_change_user(**kwargs)
        self.assertEqual(exp['allset'], res)

        kwargs['password'] = None
        res = self._protocol.make_change_user(**kwargs)
        self.assertEqual(exp['nopass'], res)
コード例 #4
0
    def test_make_changeuser(self):
        """Make a change user MySQL packet"""
        exp = {
            'allset':
            b'\x11\x68\x61\x6d\x00\x14\x3a\x07'
            b'\x66\xba\xba\x01\xce\xbe\x55\xe6\x29\x88\xaa\xae'
            b'\xdb\x00\xb3\x4d\x91\x5b\x74\x65\x73\x74\x00\x08'
            b'\x00',
            'nopass':
            b'\x11\x68\x61\x6d\x00\x00\x74\x65'
            b'\x73\x74\x00\x08\x00',
        }
        kwargs = {
            'seed': None,
            'username': '******',
            'password': '******',
            'database': 'test',
            'charset': 8,
            'client_flags': ClientFlag.get_default()
        }
        self.assertRaises(errors.ProgrammingError,
                          self._protocol.make_change_user, **kwargs)

        kwargs['seed'] = SEED
        res = self._protocol.make_change_user(**kwargs)
        self.assertEqual(exp['allset'], res)

        kwargs['password'] = None
        res = self._protocol.make_change_user(**kwargs)
        self.assertEqual(exp['nopass'], res)
コード例 #5
0
    def test_make_auth(self):
        """Make a MySQL authentication packet"""
        exp = {
            'allset':
            b'\x0d\xa2\x03\x00\x00\x00\x00\x40'
            b'\x21\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
            b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
            b'\x68\x61\x6d\x00\x14\x3a\x07\x66\xba\xba\x01\xce'
            b'\xbe\x55\xe6\x29\x88\xaa\xae\xdb\x00\xb3\x4d\x91'
            b'\x5b\x74\x65\x73\x74\x00',
            'nopass':
            b'\x0d\xa2\x03\x00\x00\x00\x00\x40'
            b'\x21\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
            b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
            b'\x68\x61\x6d\x00\x00\x74\x65\x73\x74\x00',
            'nouser':
            b'\x0d\xa2\x03\x00\x00\x00\x00\x40'
            b'\x21\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
            b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
            b'\x00\x14\x3a\x07\x66\xba\xba\x01\xce'
            b'\xbe\x55\xe6\x29\x88\xaa\xae\xdb\x00\xb3\x4d\x91'
            b'\x5b\x74\x65\x73\x74\x00',
            'nodb':
            b'\x0d\xa2\x03\x00\x00\x00\x00\x40'
            b'\x21\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
            b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
            b'\x68\x61\x6d\x00\x14\x3a\x07\x66\xba\xba\x01\xce'
            b'\xbe\x55\xe6\x29\x88\xaa\xae\xdb\x00\xb3\x4d\x91'
            b'\x5b\x00',
        }
        flags = ClientFlag.get_default()
        kwargs = {
            'seed': None,
            'username': '******',
            'password': '******',
            'database': 'test',
            'charset': 33,
            'client_flags': flags}

        self.assertRaises(errors.ProgrammingError,
                          self._protocol.make_auth, **kwargs)

        kwargs['seed'] = SEED
        res = self._protocol.make_auth(**kwargs)
        self.assertEqual(exp['allset'], res)

        kwargs['password'] = None
        res = self._protocol.make_auth(**kwargs)
        self.assertEqual(exp['nopass'], res)

        kwargs['password'] = '******'
        kwargs['database'] = None
        res = self._protocol.make_auth(**kwargs)
        self.assertEqual(exp['nodb'], res)

        kwargs['username'] = None
        kwargs['database'] = 'test'
        res = self._protocol.make_auth(**kwargs)
        self.assertEqual(exp['nouser'], res)
コード例 #6
0
    def setUp(self):
        self.config = tests.get_mysql_config()

        connect_args = [
            "host", "user", "password", "database", "port", "unix_socket",
            "client_flags"
        ]
        self.connect_kwargs = {}
        for key, value in self.config.items():
            if key in connect_args:
                self.connect_kwargs[key] = value

        if 'client_flags' not in self.connect_kwargs:
            self.connect_kwargs['client_flags'] = ClientFlag.get_default()
コード例 #7
0
    def setUp(self):
        self.config = tests.get_mysql_config()

        connect_args = [
            "host", "user", "password", "database",
            "port", "unix_socket", "client_flags"
        ]
        self.connect_kwargs = {}
        for key, value in self.config.items():
            if key in connect_args:
                self.connect_kwargs[key] = value

        if 'client_flags' not in self.connect_kwargs:
            self.connect_kwargs['client_flags'] = ClientFlag.get_default()
    def create_connect_args(self, url):
        opts = url.translate_connect_args(username='******')
        opts.update(url.query)

        util.coerce_kw_type(opts, 'buffered', bool)
        util.coerce_kw_type(opts, 'raise_on_warnings', bool)
        opts['buffered'] = True
        opts['raise_on_warnings'] = True

        # FOUND_ROWS must be set in ClientFlag to enable
        # supports_sane_rowcount.
        if self.dbapi is not None:
            try:
                from mysql.connector.constants import ClientFlag
                client_flags = opts.get('client_flags', ClientFlag.get_default())
                client_flags |= ClientFlag.FOUND_ROWS
                opts['client_flags'] = client_flags
            except:
                pass
        return [[], opts]
コード例 #9
0
ファイル: mysqlconnector.py プロジェクト: BY-jk/sqlalchemy
    def create_connect_args(self, url):
        opts = url.translate_connect_args(username="******")

        opts.update(url.query)

        util.coerce_kw_type(opts, "allow_local_infile", bool)
        util.coerce_kw_type(opts, "autocommit", bool)
        util.coerce_kw_type(opts, "buffered", bool)
        util.coerce_kw_type(opts, "compress", bool)
        util.coerce_kw_type(opts, "connection_timeout", int)
        util.coerce_kw_type(opts, "connect_timeout", int)
        util.coerce_kw_type(opts, "consume_results", bool)
        util.coerce_kw_type(opts, "force_ipv6", bool)
        util.coerce_kw_type(opts, "get_warnings", bool)
        util.coerce_kw_type(opts, "pool_reset_session", bool)
        util.coerce_kw_type(opts, "pool_size", int)
        util.coerce_kw_type(opts, "raise_on_warnings", bool)
        util.coerce_kw_type(opts, "raw", bool)
        util.coerce_kw_type(opts, "ssl_verify_cert", bool)
        util.coerce_kw_type(opts, "use_pure", bool)
        util.coerce_kw_type(opts, "use_unicode", bool)

        # unfortunately, MySQL/connector python refuses to release a
        # cursor without reading fully, so non-buffered isn't an option
        opts.setdefault("buffered", True)

        # FOUND_ROWS must be set in ClientFlag to enable
        # supports_sane_rowcount.
        if self.dbapi is not None:
            try:
                from mysql.connector.constants import ClientFlag

                client_flags = opts.get(
                    "client_flags", ClientFlag.get_default()
                )
                client_flags |= ClientFlag.FOUND_ROWS
                opts["client_flags"] = client_flags
            except Exception:
                pass
        return [[], opts]
コード例 #10
0
    def create_connect_args(self, url):
        opts = url.translate_connect_args(username="******")

        opts.update(url.query)

        util.coerce_kw_type(opts, "allow_local_infile", bool)
        util.coerce_kw_type(opts, "autocommit", bool)
        util.coerce_kw_type(opts, "buffered", bool)
        util.coerce_kw_type(opts, "compress", bool)
        util.coerce_kw_type(opts, "connection_timeout", int)
        util.coerce_kw_type(opts, "connect_timeout", int)
        util.coerce_kw_type(opts, "consume_results", bool)
        util.coerce_kw_type(opts, "force_ipv6", bool)
        util.coerce_kw_type(opts, "get_warnings", bool)
        util.coerce_kw_type(opts, "pool_reset_session", bool)
        util.coerce_kw_type(opts, "pool_size", int)
        util.coerce_kw_type(opts, "raise_on_warnings", bool)
        util.coerce_kw_type(opts, "raw", bool)
        util.coerce_kw_type(opts, "ssl_verify_cert", bool)
        util.coerce_kw_type(opts, "use_pure", bool)
        util.coerce_kw_type(opts, "use_unicode", bool)

        # unfortunately, MySQL/connector python refuses to release a
        # cursor without reading fully, so non-buffered isn't an option
        opts.setdefault("buffered", True)

        # FOUND_ROWS must be set in ClientFlag to enable
        # supports_sane_rowcount.
        if self.dbapi is not None:
            try:
                from mysql.connector.constants import ClientFlag

                client_flags = opts.get(
                    "client_flags", ClientFlag.get_default()
                )
                client_flags |= ClientFlag.FOUND_ROWS
                opts["client_flags"] = client_flags
            except Exception:
                pass
        return [[], opts]
コード例 #11
0
    def __init__(self, *args, **kwargs):
        self._protocol = None
        self._socket = None
        self._handshake = None
        self._server_version = None
        self.converter = None
        self._converter_class = MySQLConverter

        self._client_flags = ClientFlag.get_default()
        self._charset_id = 33
        self._sql_mode = None
        self._time_zone = None
        self._autocommit = False

        self._user = ""
        self._password = ""
        self._database = ""
        self._host = "127.0.0.1"
        self._port = 3306
        self._unix_socket = None
        self._client_host = ""
        self._client_port = 0
        self._ssl = {}
        self._force_ipv6 = False

        self._use_unicode = True
        self._get_warnings = False
        self._raise_on_warnings = False
        self._connection_timeout = None
        self._buffered = False
        self._unread_result = False
        self._have_next_result = False
        self._raw = False
        self._in_transaction = False

        self._prepared_statements = None

        if len(kwargs) > 0:
            self.connect(**kwargs)
コード例 #12
0
ファイル: mysqlconnector.py プロジェクト: estuans/sqlalchemy
    def create_connect_args(self, url):
        opts = url.translate_connect_args(username='******')

        opts.update(url.query)

        util.coerce_kw_type(opts, 'buffered', bool)
        util.coerce_kw_type(opts, 'raise_on_warnings', bool)

        # unfortunately, MySQL/connector python refuses to release a
        # cursor without reading fully, so non-buffered isn't an option
        opts.setdefault('buffered', True)

        # FOUND_ROWS must be set in ClientFlag to enable
        # supports_sane_rowcount.
        if self.dbapi is not None:
            try:
                from mysql.connector.constants import ClientFlag
                client_flags = opts.get('client_flags', ClientFlag.get_default())
                client_flags |= ClientFlag.FOUND_ROWS
                opts['client_flags'] = client_flags
            except:
                pass
        return [[], opts]
コード例 #13
0
    def test_make_changeuser(self):
        """Make a change user MySQL packet"""
        exp = {
            'allset':
            bytearray(b'\x11ham\x00\x143\xaa_'
                      b'\x92\\d\x94Z\xb2\xf8;U\x8a\x0c\xfb'
                      b'\x8a\xfc\xa7\xd0\xe3test\x00\x08'
                      b'\x00'),
            'nopass':
            bytearray(b'\x11\x68\x61\x6d\x00\x00\x74\x65'
                      b'\x73\x74\x00\x08\x00'),
        }
        kwargs = {
            'handshake': None,
            'username': '******',
            'password': '******',
            'database': 'test',
            'charset': 8,
            'client_flags': ClientFlag.get_default()
        }
        self.assertRaises(errors.ProgrammingError,
                          self._protocol.make_change_user, **kwargs)

        kwargs['handshake'] = {'auth_data': SEED}
        self.assertRaises(errors.ProgrammingError,
                          self._protocol.make_change_user, **kwargs)

        kwargs['handshake'] = {
            'auth_data': SEED,
            'auth_plugin': 'mysql_native_password'
        }
        res = self._protocol.make_change_user(**kwargs)
        self.assertEqual(exp['allset'], res)

        kwargs['password'] = None
        res = self._protocol.make_change_user(**kwargs)
        self.assertEqual(exp['nopass'], res)
コード例 #14
0
    def test_make_changeuser(self):
        """Make a change user MySQL packet"""
        exp = {
            'allset': bytearray(
                b'\x11ham\x00\x143\xaa_'
                b'\x92\\d\x94Z\xb2\xf8;U\x8a\x0c\xfb'
                b'\x8a\xfc\xa7\xd0\xe3test\x00\x08'
                b'\x00'),
            'nopass': bytearray(
                b'\x11\x68\x61\x6d\x00\x00\x74\x65'
                b'\x73\x74\x00\x08\x00'),
        }
        kwargs = {
            'handshake': None,
            'username': '******',
            'password': '******',
            'database': 'test',
            'charset': 8,
            'client_flags': ClientFlag.get_default()
        }
        self.assertRaises(errors.ProgrammingError,
                          self._protocol.make_change_user, **kwargs)

        kwargs['handshake'] = {'auth_data': SEED}
        self.assertRaises(errors.ProgrammingError,
                          self._protocol.make_change_user, **kwargs)

        kwargs['handshake'] = {
            'auth_data': SEED,
            'auth_plugin': 'mysql_native_password'
        }
        res = self._protocol.make_change_user(**kwargs)
        self.assertEqual(exp['allset'], res)

        kwargs['password'] = None
        res = self._protocol.make_change_user(**kwargs)
        self.assertEqual(exp['nopass'], res)
コード例 #15
0
    def create_connect_args(self, url):
        opts = url.translate_connect_args(username='******')

        opts.update(url.query)

        util.coerce_kw_type(opts, 'buffered', bool)
        util.coerce_kw_type(opts, 'raise_on_warnings', bool)

        # unfortunately, MySQL/connector python refuses to release a
        # cursor without reading fully, so non-buffered isn't an option
        opts.setdefault('buffered', True)

        # FOUND_ROWS must be set in ClientFlag to enable
        # supports_sane_rowcount.
        if self.dbapi is not None:
            try:
                from mysql.connector.constants import ClientFlag
                client_flags = opts.get('client_flags',
                                        ClientFlag.get_default())
                client_flags |= ClientFlag.FOUND_ROWS
                opts['client_flags'] = client_flags
            except Exception:
                pass
        return [[], opts]
コード例 #16
0
    def config(self, *args, **kwargs):
        """Configure the MySQL Connection

        This method allows you to configure the MySQLConnection instance.

        Raises on errors.
        """
        config = kwargs.copy()
        if "dsn" in config:
            raise errors.NotSupportedError("Data source name is not supported")

        # Configure how we handle MySQL warnings
        try:
            self.get_warnings = config["get_warnings"]
            del config["get_warnings"]
        except KeyError:
            pass  # Leave what was set or default
        try:
            self.raise_on_warnings = config["raise_on_warnings"]
            del config["raise_on_warnings"]
        except KeyError:
            pass  # Leave what was set or default

        # Configure client flags
        try:
            default = ClientFlag.get_default()
            self.set_client_flags(config["client_flags"] or default)
            del config["client_flags"]
        except KeyError:
            pass  # Missing client_flags-argument is OK

        try:
            if config["compress"]:
                self.set_client_flags([ClientFlag.COMPRESS])
        except KeyError:
            pass  # Missing compress argument is OK

        # Configure character set and collation
        if "charset" in config or "collation" in config:
            try:
                charset = config["charset"]
                del config["charset"]
            except KeyError:
                charset = None
            try:
                collation = config["collation"]
                del config["collation"]
            except KeyError:
                collation = None
            self._charset_id = CharacterSet.get_charset_info(charset, collation)[0]

        # Set converter class
        try:
            self.set_converter_class(config["converter_class"])
        except KeyError:
            pass  # Using default converter class
        except TypeError:
            raise AttributeError("Converter class should be a subclass " "of conversion.MySQLConverterBase.")

        # Compatible configuration with other drivers
        compat_map = [
            # (<other driver argument>,<translates to>)
            ("db", "database"),
            ("passwd", "password"),
            ("connect_timeout", "connection_timeout"),
        ]
        for compat, translate in compat_map:
            try:
                if translate not in config:
                    config[translate] = config[compat]
                del config[compat]
            except KeyError:
                pass  # Missing compat argument is OK

        # Configure login information
        if "user" in config or "password" in config:
            try:
                user = config["user"]
                del config["user"]
            except KeyError:
                user = self._user
            try:
                password = config["password"]
                del config["password"]
            except KeyError:
                password = self._password
            self.set_login(user, password)

        # Check network locations
        try:
            self._port = int(config["port"])
            del config["port"]
        except KeyError:
            pass  # Missing port argument is OK
        except ValueError:
            raise errors.InterfaceError("TCP/IP port number should be an integer")

        # Other configuration
        set_ssl_flag = False
        for key, value in config.items():
            try:
                DEFAULT_CONFIGURATION[key]
            except KeyError:
                raise AttributeError("Unsupported argument '{}'".format(key))
            # SSL Configuration
            if key == "ssl_verify_cert":
                set_ssl_flag = True
                self._ssl.update({"verify_cert": value})
            elif key.startswith("ssl_") and value:
                set_ssl_flag = True
                self._ssl.update({key.replace("ssl_", ""): value})
            else:
                attribute = "_" + key
                try:
                    setattr(self, attribute, value.strip())
                except AttributeError:
                    setattr(self, attribute, value)

        if set_ssl_flag:
            if "verify_cert" not in self._ssl:
                self._ssl["verify_cert"] = DEFAULT_CONFIGURATION["ssl_verify_cert"]
            required_keys = set(["ca", "cert", "key"])
            diff = list(required_keys - set(self._ssl.keys()))
            if diff:
                missing_attrs = ["ssl_" + val for val in diff]
                raise AttributeError("Missing SSL argument(s): {0}".format(", ".join(missing_attrs)))
            self.set_client_flags([ClientFlag.SSL])
コード例 #17
0
    def test_make_auth(self):
        """Make a MySQL authentication packet"""
        exp = {
            'allset':
            bytearray(b'\x0d\xa2\x13\x00\x00\x00\x00@!'
                      b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
                      b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00ham'
                      b'\x00\x143\xaa_\x92\\d\x94Z\xb2\xf8;U\x8a\x0c'
                      b'\xfb\x8a\xfc\xa7\xd0\xe3test\x00'),
            'nopass':
            bytearray(b'\x0d\xa2\x13\x00\x00\x00\x00@!'
                      b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
                      b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00ham'
                      b'\x00\x00test\x00'),
            'nouser':
            bytearray(b'\x0d\xa2\x13\x00\x00\x00\x00@!'
                      b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
                      b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
                      b'\x143\xaa_\x92\\d\x94Z\xb2\xf8;U\x8a\x0c'
                      b'\xfb\x8a\xfc\xa7\xd0\xe3test\x00'),
            'nodb':
            bytearray(b'\x0d\xa2\x13\x00\x00\x00\x00@!'
                      b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
                      b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00ham'
                      b'\x00\x143\xaa_\x92\\d\x94Z\xb2\xf8;U\x8a\x0c'
                      b'\xfb\x8a\xfc\xa7\xd0\xe3\x00'),
        }
        flags = ClientFlag.get_default()
        kwargs = {
            'handshake': None,
            'username': '******',
            'password': '******',
            'database': 'test',
            'charset': 33,
            'client_flags': flags
        }

        self.assertRaises(errors.ProgrammingError, self._protocol.make_auth,
                          **kwargs)

        kwargs['handshake'] = {'auth_data': SEED}
        self.assertRaises(errors.ProgrammingError, self._protocol.make_auth,
                          **kwargs)

        kwargs['handshake'] = {
            'auth_data': SEED,
            'auth_plugin': 'mysql_native_password'
        }
        res = self._protocol.make_auth(**kwargs)
        self.assertEqual(exp['allset'], res)

        kwargs['password'] = None
        res = self._protocol.make_auth(**kwargs)
        self.assertEqual(exp['nopass'], res)

        kwargs['password'] = '******'
        kwargs['database'] = None
        res = self._protocol.make_auth(**kwargs)
        self.assertEqual(exp['nodb'], res)

        kwargs['username'] = None
        kwargs['database'] = 'test'
        res = self._protocol.make_auth(**kwargs)
        self.assertEqual(exp['nouser'], res)
コード例 #18
0
    def test_make_auth(self):
        """Make a MySQL authentication packet"""
        exp = {
            'allset': bytearray(
                b'\x0d\xa2\x03\x00\x00\x00\x00@!'
                b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
                b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00ham'
                b'\x00\x143\xaa_\x92\\d\x94Z\xb2\xf8;U\x8a\x0c'
                b'\xfb\x8a\xfc\xa7\xd0\xe3test\x00'),
            'nopass': bytearray(
                b'\x0d\xa2\x03\x00\x00\x00\x00@!'
                b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
                b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00ham'
                b'\x00\x00test\x00'),
            'nouser': bytearray(
                b'\x0d\xa2\x03\x00\x00\x00\x00@!'
                b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
                b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
                b'\x143\xaa_\x92\\d\x94Z\xb2\xf8;U\x8a\x0c'
                b'\xfb\x8a\xfc\xa7\xd0\xe3test\x00'),
            'nodb': bytearray(
                b'\x0d\xa2\x03\x00\x00\x00\x00@!'
                b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
                b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00ham'
                b'\x00\x143\xaa_\x92\\d\x94Z\xb2\xf8;U\x8a\x0c'
                b'\xfb\x8a\xfc\xa7\xd0\xe3\x00'),
        }
        flags = ClientFlag.get_default()
        kwargs = {
            'handshake': None,
            'username': '******',
            'password': '******',
            'database': 'test',
            'charset': 33,
            'client_flags': flags
        }

        self.assertRaises(errors.ProgrammingError,
                          self._protocol.make_auth, **kwargs)

        kwargs['handshake'] = {'auth_data': SEED}
        self.assertRaises(errors.ProgrammingError,
                          self._protocol.make_auth, **kwargs)

        kwargs['handshake'] = {
            'auth_data': SEED,
            'auth_plugin': 'mysql_native_password'
        }
        res = self._protocol.make_auth(**kwargs)
        self.assertEqual(exp['allset'], res)

        kwargs['password'] = None
        res = self._protocol.make_auth(**kwargs)
        self.assertEqual(exp['nopass'], res)

        kwargs['password'] = '******'
        kwargs['database'] = None
        res = self._protocol.make_auth(**kwargs)
        self.assertEqual(exp['nodb'], res)

        kwargs['username'] = None
        kwargs['database'] = 'test'
        res = self._protocol.make_auth(**kwargs)
        self.assertEqual(exp['nouser'], res)
コード例 #19
0
    def test_make_auth(self):
        """Make a MySQL authentication packet"""
        exp = {
            "allset": bytearray(
                b"\x8d\xa2\x03\x00\x00\x00\x00\x40"
                b"\x21\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
                b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
                b"\x68\x61\x6d\x00\x14\x3a\x07\x66\xba\xba\x01\xce"
                b"\xbe\x55\xe6\x29\x88\xaa\xae\xdb\x00\xb3\x4d\x91"
                b"\x5b\x74\x65\x73\x74\x00"
            ),
            "nopass": bytearray(
                b"\x8d\xa2\x03\x00\x00\x00\x00\x40"
                b"\x21\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
                b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
                b"\x68\x61\x6d\x00\x00\x74\x65\x73\x74\x00"
            ),
            "nouser": bytearray(
                b"\x8d\xa2\x03\x00\x00\x00\x00\x40"
                b"\x21\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
                b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
                b"\x00\x14\x3a\x07\x66\xba\xba\x01\xce"
                b"\xbe\x55\xe6\x29\x88\xaa\xae\xdb\x00\xb3\x4d\x91"
                b"\x5b\x74\x65\x73\x74\x00"
            ),
            "nodb": bytearray(
                b"\x8d\xa2\x03\x00\x00\x00\x00\x40"
                b"\x21\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
                b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
                b"\x68\x61\x6d\x00\x14\x3a\x07\x66\xba\xba\x01\xce"
                b"\xbe\x55\xe6\x29\x88\xaa\xae\xdb\x00\xb3\x4d\x91"
                b"\x5b\x00"
            ),
        }
        flags = ClientFlag.get_default()
        kwargs = {
            "handshake": None,
            "username": "******",
            "password": "******",
            "database": "test",
            "charset": 33,
            "client_flags": flags,
        }

        self.assertRaises(errors.ProgrammingError, self._protocol.make_auth, **kwargs)

        kwargs["handshake"] = {"auth_data": SEED}
        self.assertRaises(errors.ProgrammingError, self._protocol.make_auth, **kwargs)

        kwargs["handshake"] = {"auth_data": SEED, "auth_plugin": "mysql_native_password"}
        res = self._protocol.make_auth(**kwargs)
        self.assertEqual(exp["allset"], res)

        kwargs["password"] = None
        res = self._protocol.make_auth(**kwargs)
        self.assertEqual(exp["nopass"], res)

        kwargs["password"] = "******"
        kwargs["database"] = None
        res = self._protocol.make_auth(**kwargs)
        self.assertEqual(exp["nodb"], res)

        kwargs["username"] = None
        kwargs["database"] = "test"
        res = self._protocol.make_auth(**kwargs)
        self.assertEqual(exp["nouser"], res)