|
|
|
@ -1,11 +1,11 @@ |
|
|
|
|
import pytest |
|
|
|
|
import os |
|
|
|
|
|
|
|
|
|
from click.testing import CliRunner |
|
|
|
|
from ceo.cli import cli |
|
|
|
|
|
|
|
|
|
from mysql.connector import connect |
|
|
|
|
from mysql.connector.errors import ProgrammingError |
|
|
|
|
import pytest |
|
|
|
|
|
|
|
|
|
from ceo.cli import cli |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def mysql_attempt_connection(host, username, password): |
|
|
|
@ -26,12 +26,13 @@ def test_mysql(cli_setup, cfg, ldap_user): |
|
|
|
|
runner = CliRunner() |
|
|
|
|
|
|
|
|
|
username = ldap_user.uid |
|
|
|
|
os.makedirs(ldap_user.home_directory) |
|
|
|
|
host = cfg.get("mysql_host") |
|
|
|
|
info_file_path = os.path.join(ldap_user.home_directory, "ceo-mysql-info") |
|
|
|
|
assert not os.path.isfile(info_file_path) |
|
|
|
|
|
|
|
|
|
# create database for user |
|
|
|
|
result = runner.invoke(cli, ['mysql', 'create', username]) |
|
|
|
|
result = runner.invoke(cli, ['mysql', 'create', username], input='y\n') |
|
|
|
|
assert result.exit_code == 0 |
|
|
|
|
assert os.path.isfile(info_file_path) |
|
|
|
|
|
|
|
|
@ -40,22 +41,24 @@ def test_mysql(cli_setup, cfg, ldap_user): |
|
|
|
|
with open(info_file_path, 'r') as file: |
|
|
|
|
old_info = file.read() |
|
|
|
|
|
|
|
|
|
expected = f"""MySQL database created |
|
|
|
|
|
|
|
|
|
Connection Information: |
|
|
|
|
expected = f"""Are you sure you want to create a MySQL database for {username}? [y/N]: y |
|
|
|
|
MySQL database created. |
|
|
|
|
Connection Information: |
|
|
|
|
|
|
|
|
|
Database: {username} |
|
|
|
|
Username: {username} |
|
|
|
|
Password: {passwd} |
|
|
|
|
Host: {host} |
|
|
|
|
Database: {username} |
|
|
|
|
Username: {username} |
|
|
|
|
Password: {passwd} |
|
|
|
|
Host: {host} |
|
|
|
|
|
|
|
|
|
Settings and more info has been written to {info_file_path}""" |
|
|
|
|
These settings have been written to {info_file_path}. |
|
|
|
|
""" |
|
|
|
|
|
|
|
|
|
assert result.output == expected |
|
|
|
|
mysql_attempt_connection(host, username, passwd) |
|
|
|
|
|
|
|
|
|
# perform password reset for user |
|
|
|
|
result = runner.invoke(cli, ['mysql', 'pwreset', username], input="y\n") |
|
|
|
|
# confirm once to reset password, another to overwrite the file |
|
|
|
|
result = runner.invoke(cli, ['mysql', 'pwreset', username], input="y\ny\n") |
|
|
|
|
assert result.exit_code == 0 |
|
|
|
|
|
|
|
|
|
response_arr = result.output.split() |
|
|
|
@ -76,3 +79,4 @@ def test_mysql(cli_setup, cfg, ldap_user): |
|
|
|
|
mysql_attempt_connection(host, username, passwd) |
|
|
|
|
|
|
|
|
|
os.remove(info_file_path) |
|
|
|
|
os.rmdir(ldap_user.home_directory) |
|
|
|
|