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
121
122
123
// Copyright (C) 2015-2022 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#ifndef TEST_MYSQL_SCHEMA_H
#define TEST_MYSQL_SCHEMA_H

#include <config.h>
#include <database/testutils/schema.h>
#include <string><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.

namespace isc {
namespace db {
namespace test {

extern const char* MYSQL_VALID_TYPE;

/// Return valid connection string
///
/// @return valid MySQL connection string.
std::string validMySQLConnectionString();

/// @brief Clear the unit test database
///
/// In order to reduce test execution time, this function
/// defaults to first attempting to delete transient data
/// from the database by calling @c wipeMySQLData.  If that
/// function fails it will then attempt to destroy the database
/// schema by running the SQL script:
///
///  <DATABASE_SCRIPT_DIR>/mysql/dhcpdb_drop.mysql
///
/// The default behavior of wiping the data only may be overridden
/// in one of two ways:
///
/// -# Setting the force parameter to true
/// -# Defining the environment variable:
///    KEA_TEST_DB_WIPE_DATA_ONLY="false"
///
/// @param show_err flag which governs whether or not stderr is suppressed.
/// @param force if true, the function will skip deleting the data and
/// destroy the schema.
void destroyMySQLSchema(bool show_err = false, bool force = false);

/// @brief Create the unit test MySQL Schema
///
/// Ensures the unit test database is a empty and version-correct.
/// Unless, the force parameter is true, it will first attempt
/// to wipe the data from the database by calling @c wipeMySQLData.
/// If this call succeeds the function returns, otherwise it will
/// will call @c destroyMySQLSchema to forcibly remove the
/// existing schema and then submits the SQL script:
///
///  <DATABASE_SCRIPTS_DIR>/mysql/dhcpdb_create.mysql
///
/// to the unit test MySQL database.
///
/// The default behavior of wiping the data only may be overridden
/// in one of two ways:
///
/// -# Setting the force parameter to true
/// -# Defining the environment variable:
///    KEA_TEST_DB_WIPE_DATA_ONLY="false"
///
/// @param show_err flag which governs whether or not stderr is suppressed.
/// @param force flag when true, the function will recreate the database
/// schema.
void createMySQLSchema(bool show_err = false, bool force = false);

/// @brief Attempts to wipe data from the MySQL unit test database
///
/// Runs the shell script
///
///  <DATABASE_WIPE_DIR>/mysql/wipe_data.sh
///
/// This will fail if there is no schema, if the existing schema
/// version is incorrect (i.e. does not match MYSQL_SCHEMA_VERSION_MAJOR
/// and MYSQL_SCHEMA_VERSION_MINOR), or a SQL error occurs.  Otherwise,
/// the script is should delete all transient data, leaving intact
/// reference tables.
///
/// @param show_err flag which governs whether or not stderr is suppressed.
bool wipeMySQLData(bool show_err = false);

/// @brief Run a MySQL SQL script against the MySQL unit test database
///
/// Submits the given SQL script to MySQL via mysql CLI. The output of
/// stderr is suppressed unless the parameter, show_err is true.  The is done
/// to suppress warnings that might otherwise make test output needlessly
/// noisy.  An exception is thrown if the script fails to execute.
///
/// @param path - path (if not blank) of the script to execute
/// @param script_name - file name of the path to execute
/// @param show_err flag which governs whether or not stderr is suppressed.
/// @throw Unexpected when the script returns an error.
void runMySQLScript(const std::string& path, const std::string& script_name,
                    bool show_err);

/// @brief Get the SSL/TLS support status from the environment
///
/// The environment variable is KEA_MYSQL_HAVE_SSL
std::string getMySQLTlsEnv();

/// @brief Get the SSL/TLS support status from the server
/// @note the returned value is set in the environment
std::string getMySQLTlsServer();

/// @brief Return true if the server has been configured with proper SSL/TLS
/// credentials, false otherwise
bool isMySQLTlsConfigured();

/// @brief Get the server global variable value
///
/// @param variable The server global variable name
std::string getMySQLTlsServerVariable(std::string variable);

}
}
}

#endif