testing
continuous-integration/drone/pr Build is failing Details

This commit is contained in:
Andrew Wang 2021-08-25 21:49:51 -04:00
parent 5893e561cd
commit dc4d60fba2
10 changed files with 57 additions and 15 deletions

View File

@ -10,7 +10,7 @@ def http_request(method: str, path: str, **kwargs) -> requests.Response:
client = component.getUtility(IHTTPClient)
cfg = component.getUtility(IConfig)
if path.startswith('/api/db'):
host = cfg.get('ceod_db_host')
host = cfg.get('ceod_database_host')
need_cred = False
else:
host = cfg.get('ceod_admin_host')

View File

@ -1,5 +1,4 @@
from zope.interface import Attribute, Interface
from .IUser import IUser
class IDatabaseService(Interface):

View File

@ -8,3 +8,4 @@ from .IUWLDAPService import IUWLDAPService
from .IMailService import IMailService
from .IMailmanService import IMailmanService
from .IHTTPClient import IHTTPClient
from .IDatabaseService import IDatabaseService

View File

@ -38,6 +38,10 @@ def create_app(flask_config={}):
from ceod.api import mailman
app.register_blueprint(mailman.bp, url_prefix='/api/mailman')
if hostname == cfg.get('ceod_database_host'):
from ceod.api import database
app.register_blueprint(database.bp, url_prefix='/api/db')
from ceod.api import groups
app.register_blueprint(groups.bp, url_prefix='/api/groups')
@ -109,9 +113,11 @@ def register_services(app):
component.provideUtility(uwldap_srv, IUWLDAPService)
# MySQLService
mysql_srv = MySQLService()
component.provideUtility(mysql_srv, IDatabaseService, 'mysql')
if hostname == cfg.get('ceod_database_host'):
mysql_srv = MySQLService()
component.provideUtility(mysql_srv, IDatabaseService, 'mysql')
# PostgreSQLService
psql_srv = PostgreSQLService()
component.provideUtility(psql_srv, IDatabaseService, 'postgresql')
if hostname == cfg.get('ceod_database_host'):
psql_srv = PostgreSQLService()
component.provideUtility(psql_srv, IDatabaseService, 'postgresql')

View File

@ -55,13 +55,6 @@ def create_mysql_db(auth_user: str, username: str):
return create_db_from_type('mysql', username)
@bp.route('/mysql/<username>', methods=['DELETE'])
@authz_restrict_to_syscom
@development_only
def delete_mysql_db(username: str):
delete_db_from_type('mysql', username)
@bp.route('/postgresql/<username>', methods=['POST'])
@requires_authentication_no_realm
def create_postgresql_db(auth_user: str, username: str):
@ -70,6 +63,13 @@ def create_postgresql_db(auth_user: str, username: str):
return create_db_from_type('postgresql', username)
@bp.route('/mysql/<username>', methods=['DELETE'])
@authz_restrict_to_syscom
@development_only
def delete_mysql_db(username: str):
delete_db_from_type('mysql', username)
@bp.route('/postgresql/<username>', methods=['DELETE'])
@authz_restrict_to_syscom
@development_only

View File

@ -1,5 +1,40 @@
import pytest
from ceod.db.MySQLService import MySQLService
from ceo_common.errors import DatabaseConnectionError, DatabasePermissionError
from mysql.connector import connect
from mysql.connector.errors import InterfaceError, ProgrammingError
def test_mysql_db_create(cfg):
mysql_srv = MySQLService()
password = mysql_srv.create_db('test_jdoe')
with connect(
host=cfg.get('ceod_database_host'),
user='test_jdoe',
password=password,
) as con:
with con.cursor() as cur:
cur.execute("SHOW DATABASES")
response = cur.fetchall()
assert len(response) == 2
mysql_srv.delete_db('test_jdoe')
# user should be deleted
with pytest.raises(InterfaceError):
con = connect(
host=cfg.get('ceod_database_host'),
user='test_jdoe',
password=password,
)
# except InterfaceError:
# raise DatabaseConnectionError()
# except ProgrammingError:
# raise DatabasePermissionError()
# ask for mysql and postgres with proper postgres configs and no public schema
# tests are stateless

View File

@ -1,2 +1 @@
import pytest

View File

@ -7,6 +7,7 @@ admin_host = phosphoric-acid
# this is the host with NFS no_root_squash
fs_root_host = phosphoric-acid
mailman_host = mail
database_host = coffee
krb5_cache_dir = /run/ceod/krb5_cache
use_https = false
port = 9987

View File

@ -7,6 +7,7 @@ uw_domain = uwaterloo.internal
admin_host = phosphoric-acid
fs_root_host = phosphoric-acid
mailman_host = phosphoric-acid
database_host = phosphoric-acid
krb5_cache_dir = /tmp/ceod_test_krb5_cache
use_https = false
port = 9987