~mysql/mysql-utilities/1.6

« back to all changes in this revision

Viewing changes to mysql-test/t/ssl_connection_simple_test_errors.py

  • Committer: chuck.bell at oracle
  • Date: 2014-12-05 15:00:19 UTC
  • mfrom: (488.1.1 mu-1.6.1-b19031182)
  • Revision ID: chuck.bell@oracle.com-20141205150019-enxhq2j2gdylzhx9
Tagged for release to SysQA

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
check ssl connection support test.
20
20
"""
21
21
 
 
22
from mysql.utilities.exception import MUTLibError
 
23
 
 
24
from mutlib.ssl_certs import ssl_c_ca_b
 
25
 
22
26
import ssl_connection_simple_test
23
27
 
24
28
 
26
30
    """checks ssl connection support for utilities that uses add server option
27
31
    from option module.
28
32
 
29
 
    Shares the the same pre_requisites, setup and drop_all methods as the
 
33
    Shares the the same pre_requisites and drop_all methods as the
30
34
    parent class.
31
35
    """
32
 
    # pylint: disable=W0221
33
 
    def run_test(self, test, test_case, conn_str, exp_result):
34
 
        """Runs each individual test.
35
 
        """
36
 
        test_cmd = "{0} {1}".format(test['cmd_str'].format(conn_str),
37
 
                                    test['cmd_opts'])
38
 
        test_comment = test['comment'].format(test_case)
39
 
        res = self.run_test_case(exp_result, test_cmd, test_comment)
40
 
        return res
 
36
 
 
37
    server2 = None
 
38
 
 
39
    def setup(self):
 
40
        super(test, self).setup()
 
41
        try:
 
42
            self.servers.spawn_server('no_ssl_server', mysqld="--ssl=1")
 
43
        except MUTLibError as err:
 
44
            raise MUTLibError("Cannot spawn needed servers: {0}"
 
45
                              "".format(err.errmsg))
 
46
 
 
47
        index = self.servers.find_server_by_name('no_ssl_server')
 
48
        self.server2 = self.servers.get_server(index)
 
49
 
 
50
        return True
41
51
 
42
52
    def run_round_of_tests(self, tests, test_num, conn_opts, comment):
43
53
        """Runs a round of tests.
60
70
        ssl_ca = "--ssl-ca={0}".format(conn_val[6])
61
71
        ssl_cert = "--ssl-cert={0}".format(conn_val[7])
62
72
        ssl_key = "--ssl-key={0}".format(conn_val[8])
 
73
        ssl = "--ssl={0}"
 
74
        conn_no_ssl = self.build_connection_string(self.server2)
63
75
        tests = []
64
76
 
65
77
        # ======== mysqlindexcheck ========= #
124
136
            "utility": "mysqldiskusage",
125
137
            "cmd_str": "mysqldiskusage.py --server={0}",
126
138
            "comment": "Test case {0} - basic diskusage with ssl",
127
 
            "cmd_opts": " -q"
 
139
            "cmd_opts": ""
128
140
        })
129
141
 
130
142
        # ========  mysqlfrm  ========= #
174
186
        test_num = self.run_round_of_tests(tests, test_num, conn_opts,
175
187
                                           "No ssl options")
176
188
 
177
 
        # Servers prior to 5.7 will allow connection if ssl_ca is present
178
 
        # for that reason this case is not run on this test.
179
 
        # MySQl 5.7 may require a variant of this test.
180
 
 
181
189
        # conn_str with --ssl-ca and --ssl-key options only
182
190
        conn_opts = "{0} {1} {2}".format(conn_str, ssl_ca, ssl_key)
183
191
        test_num = self.run_round_of_tests(tests, test_num, conn_opts,
230
238
                                           "unexisting certificate"
231
239
                                           "file in --ssl-key option")
232
240
 
 
241
        # conn_str with --ssl=0 with user that requires SSL
 
242
        ssl_required = ssl.format("0")
 
243
        conn_opts = "{0} {1}".format(conn_str, ssl_required)
 
244
        test_num = self.run_round_of_tests(tests, test_num, conn_opts,
 
245
                                           "only --ssl=0 option for ssl "
 
246
                                           "required user")
 
247
 
 
248
        # conn_str with --ssl=1 with server without ssl certs and user that no
 
249
        # requires SSL
 
250
        ssl_required = ssl.format("1")
 
251
        conn_opts = "{0} {1}".format(conn_no_ssl, ssl_required)
 
252
        test_num = self.run_round_of_tests(tests, test_num, conn_opts,
 
253
                                           "only --ssl=1 option and server "
 
254
                                           "without ssl certs")
 
255
 
 
256
        # conn_str with --ssl=1 with different ca-cert
 
257
        ssl_required = ssl.format("1")
 
258
        conn_opts = "{0} --ssl-ca={1} {2}".format(conn_str, ssl_c_ca_b,
 
259
                                                  ssl_required)
 
260
        test_num = self.run_round_of_tests(tests, test_num, conn_opts,
 
261
                                           "--ssl=1 option and different ssl "
 
262
                                           "ca-cert")
 
263
 
233
264
        self.do_replacements()
234
265
 
235
266
        return True
249
280
                            "| root[...]\n")
250
281
        self.remove_result_and_lines_after("              config_file:", 16)
251
282
        self.remove_result_and_lines_after("| db_name             |", 12)
 
283
        self.remove_result("# Database totals:")
 
284
        self.remove_result_and_lines_after("Total database disk u", 2)
 
285
        self.replace_substring("mysqldiskusage: error: Lost connection",
 
286
                               "ERROR: Lost connection")
 
287
        self.replace_substring("ERROR: 2055: Lost connection",
 
288
                               "ERROR: Lost connection")
 
289
        self.replace_substring("mysqlfrm: error: Lost connection",
 
290
                               "ERROR: Lost connection")
 
291
        self.replace_substring_portion("ERROR: Lost connection",
 
292
                                       "certificate verify failed",
 
293
                                       "certificate verify failed")
 
294
        self.replace_result("ERROR: Lost connection to MySQL server at",
 
295
                            "ERROR: Lost connection to MySQL server at"
 
296
                            " 'XXXX-XXXX:XXXX'\n")
252
297
 
253
298
    def get_result(self):
254
299
        return self.compare(__name__, self.results)
257
302
        return self.save_result_file(__name__, self.results)
258
303
 
259
304
    def cleanup(self):
 
305
        self.kill_server_list(['no_ssl_server'])
260
306
        return ssl_connection_simple_test.test.cleanup(self)