File: test_auth.py

package info (click to toggle)
python-pymysql 1.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 836 kB
  • sloc: python: 6,473; makefile: 134; sh: 44; sql: 10
file content (120 lines) | stat: -rw-r--r-- 2,887 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
"""Test for auth methods supported by MySQL 8"""

import os
import pymysql

# pymysql.connections.DEBUG = True
# pymysql._auth.DEBUG = True

host = "127.0.0.1"
port = 3306

ca = os.path.expanduser("~/ca.pem")
ssl = {"ca": ca, "check_hostname": False}

pass_sha256 = "pass_sha256_01234567890123456789"
pass_caching_sha2 = "pass_caching_sha2_01234567890123456789"


def test_sha256_no_password():
    con = pymysql.connect(user="nopass_sha256", host=host, port=port, ssl=None)
    con.close()


def test_sha256_no_passowrd_ssl():
    con = pymysql.connect(user="nopass_sha256", host=host, port=port, ssl=ssl)
    con.close()


def test_sha256_password():
    con = pymysql.connect(
        user="user_sha256", password=pass_sha256, host=host, port=port, ssl=None
    )
    con.close()


def test_sha256_password_ssl():
    con = pymysql.connect(
        user="user_sha256", password=pass_sha256, host=host, port=port, ssl=ssl
    )
    con.close()


def test_caching_sha2_no_password():
    con = pymysql.connect(user="nopass_caching_sha2", host=host, port=port, ssl=None)
    con.close()


def test_caching_sha2_no_password_ssl():
    con = pymysql.connect(user="nopass_caching_sha2", host=host, port=port, ssl=ssl)
    con.close()


def test_caching_sha2_password():
    con = pymysql.connect(
        user="user_caching_sha2",
        password=pass_caching_sha2,
        host=host,
        port=port,
        ssl=None,
    )
    con.close()

    # Fast path of caching sha2
    con = pymysql.connect(
        user="user_caching_sha2",
        password=pass_caching_sha2,
        host=host,
        port=port,
        ssl=None,
    )
    con.query("FLUSH PRIVILEGES")
    con.close()

    # Fast path after auth_switch_request
    pymysql.connections._DEFAULT_AUTH_PLUGIN = "mysql_native_password"
    con = pymysql.connect(
        user="user_caching_sha2",
        password=pass_caching_sha2,
        host=host,
        port=port,
        ssl=ssl,
    )
    con.query("FLUSH PRIVILEGES")
    con.close()
    pymysql.connections._DEFAULT_AUTH_PLUGIN = None


def test_caching_sha2_password_ssl():
    con = pymysql.connect(
        user="user_caching_sha2",
        password=pass_caching_sha2,
        host=host,
        port=port,
        ssl=ssl,
    )
    con.close()

    # Fast path of caching sha2
    con = pymysql.connect(
        user="user_caching_sha2",
        password=pass_caching_sha2,
        host=host,
        port=port,
        ssl=ssl,
    )
    con.query("FLUSH PRIVILEGES")
    con.close()

    # Fast path after auth_switch_request
    pymysql.connections._DEFAULT_AUTH_PLUGIN = "mysql_native_password"
    con = pymysql.connect(
        user="user_caching_sha2",
        password=pass_caching_sha2,
        host=host,
        port=port,
        ssl=ssl,
    )
    con.query("FLUSH PRIVILEGES")
    con.close()
    pymysql.connections._DEFAULT_AUTH_PLUGIN = None