Beispiel #1
0
 async def testMySQLOldPasswordAuth(self, set_me_up):
     await set_me_up(self)
     if self.mysql_server_is(self.connections[0], (5, 7, 0)):
         raise base.SkipTest('Old passwords aren\'t supported in 5.7')
     # trio_mysql.err.OperationalError: (1045, "Access denied for user 'old_pass_user'@'localhost' (using password: YES)")
     # from login in MySQL-5.6
     if self.mysql_server_is(self.connections[0], (5, 6, 0)):
         raise base.SkipTest('Old passwords don\'t authenticate in 5.6')
     db = self.db.copy()
     db['password'] = "******"
     async with self.connections[0] as c:
         # deprecated in 5.6
         if sys.version_info[0:2] >= (3, 2) and self.mysql_server_is(
                 self.connections[0], (5, 6, 0)):
             with self.assertWarns(trio_mysql.err.Warning) as cm:
                 await c.execute("SELECT OLD_PASSWORD('%s')" %
                                 db['password'])
         else:
             await c.execute("SELECT OLD_PASSWORD('%s')" % db['password'])
         v = (await c.fetchone())[0]
         self.assertEqual(v, '2a01785203b08770')
         # only works in MariaDB and MySQL-5.6 - can't separate out by version
         #if self.mysql_server_is(self.connections[0], (5, 5, 0)):
         #    with TempUser(c, 'old_pass_user@localhost',
         #                  self.databases[0]['db'], 'mysql_old_password', '2a01785203b08770') as u:
         #        c = trio_mysql.connect(user='******', **db)
         #        await c.connect()
         #        cur = c.cursor()
         #        await cur.execute("SELECT VERSION()")
         await c.execute("SELECT @@secure_auth")
         secure_auth_setting = (await c.fetchone())[0]
         await c.execute('set old_passwords=1')
         # trio_mysql.err.Warning: 'pre-4.1 password hash' is deprecated and will be removed in a future release. Please use post-4.1 password hash instead
         if sys.version_info[0:2] >= (3, 2) and self.mysql_server_is(
                 self.connections[0], (5, 6, 0)):
             with self.assertWarns(trio_mysql.err.Warning) as cm:
                 await c.execute('set global secure_auth=0')
         else:
             await c.execute('set global secure_auth=0')
         async with TempUser(c,
                             'old_pass_user@localhost',
                             self.databases[0]['db'],
                             password=db['password']) as u:
             cc = trio_mysql.connect(user='******', **db)
             await cc.connect()
             cur = cc.cursor()
             await cur.execute("SELECT VERSION()")
             await cc.aclose()
         await c.execute('set global secure_auth=%r' % secure_auth_setting)
Beispiel #2
0
    async def test_json(self, set_me_up):
        await set_me_up(self)
        args = self.databases[0].copy()
        args["charset"] = "utf8mb4"
        conn = trio_mysql.connect(**args)
        await conn.connect()
        if not self.mysql_server_is(conn, (5, 7, 0)):
            raise base.SkipTest("JSON type is not supported on MySQL <= 5.6")

        await self.safe_create_table(
            conn, "test_json", """\
create table test_json (
    id int not null,
    json JSON not null,
    primary key (id)
);""")
        cur = conn.cursor()

        json_str = u'{"hello": "こんにちは"}'
        await cur.execute("INSERT INTO test_json (id, `json`) values (42, %s)",
                          (json_str, ))
        await cur.execute("SELECT `json` from `test_json` WHERE `id`=42")
        res = (await cur.fetchone())[0]
        self.assertEqual(json.loads(res), json.loads(json_str))

        await cur.execute("SELECT CAST(%s AS JSON) AS x", (json_str, ))
        res = (await cur.fetchone())[0]
        self.assertEqual(json.loads(res), json.loads(json_str))
        await conn.aclose()
Beispiel #3
0
 async def testPamAuthInstallPlugin(self, set_me_up):
     await set_me_up(self)
     # needs plugin. lets install it.
     cur = self.connections[0].cursor()
     try:
         await cur.execute("install plugin pam soname 'auth_pam.so'")
         TestAuthentication.pam_found = True
         await self.realTestPamAuth()
     except trio_mysql.err.InternalError:
         raise base.SkipTest('we couldn\'t install the auth_pam plugin')
     finally:
         if TestAuthentication.pam_found:
             await cur.execute("uninstall plugin pam")
Beispiel #4
0
 async def testDialogAuthThreeAttemptsQuestionsInstallPlugin(self, set_me_up):
     await set_me_up(self)
     # needs plugin. lets install it.
     cur = self.connections[0].cursor()
     try:
         await cur.execute("install plugin three_attempts soname 'dialog_examples.so'")
         TestAuthentication.three_attempts_found = True
         await self.realTestDialogAuthThreeAttempts()
     except trio_mysql.err.InternalError:
         raise base.SkipTest('we couldn\'t install the three_attempts plugin')
     finally:
         if TestAuthentication.three_attempts_found:
             await cur.execute("uninstall plugin three_attempts")
Beispiel #5
0
    async def test_datetime_microseconds(self, set_me_up):
        await set_me_up(self)
        """ test datetime conversion w microseconds"""

        conn = await self.connect()
        if not self.mysql_server_is(conn, (5, 6, 4)):
            raise base.SkipTest("target backend does not support microseconds")
        c = conn.cursor()
        dt = datetime.datetime(2013, 11, 12, 9, 9, 9, 123450)
        await c.execute("create table test_datetime (id int, ts datetime(6))")
        try:
            await c.execute("insert into test_datetime values (%s, %s)",
                            (1, dt))
            await c.execute("select ts from test_datetime")
            self.assertEqual((dt, ), await c.fetchone())
        finally:
            await c.execute("drop table test_datetime")
Beispiel #6
0
 async def testSocketAuthInstallPlugin(self, set_me_up):
     await set_me_up(self)
     # needs plugin. lets install it.
     cur = self.connections[0].cursor()
     try:
         await cur.execute("install plugin auth_socket soname 'auth_socket.so'")
         TestAuthentication.socket_found = True
         self.socket_plugin_name = 'auth_socket'
         await self.realtestSocketAuth()
     except trio_mysql.err.InternalError:
         try:
             await cur.execute("install soname 'auth_socket'")
             TestAuthentication.socket_found = True
             self.socket_plugin_name = 'unix_socket'
             await self.realtestSocketAuth()
         except trio_mysql.err.InternalError:
             TestAuthentication.socket_found = False
             raise base.SkipTest('we couldn\'t install the socket plugin')
     finally:
         if TestAuthentication.socket_found:
             await cur.execute("uninstall plugin %s" % self.socket_plugin_name)