mirror of
https://github.com/ansible-collections/community.mysql.git
synced 2025-04-22 18:31:27 -07:00
Add unit tests for the new function
This commit is contained in:
parent
aed63e879c
commit
29bdfb5739
1 changed files with 70 additions and 0 deletions
|
@ -4,12 +4,17 @@ from __future__ import (absolute_import, division, print_function)
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
try:
|
||||||
|
from unittest.mock import MagicMock
|
||||||
|
except ImportError:
|
||||||
|
from mock import MagicMock
|
||||||
|
|
||||||
from ansible_collections.community.mysql.plugins.modules.mysql_user import (
|
from ansible_collections.community.mysql.plugins.modules.mysql_user import (
|
||||||
handle_grant_on_col,
|
handle_grant_on_col,
|
||||||
has_grant_on_col,
|
has_grant_on_col,
|
||||||
normalize_col_grants,
|
normalize_col_grants,
|
||||||
sort_column_order,
|
sort_column_order,
|
||||||
|
handle_requiressl_in_priv_string
|
||||||
)
|
)
|
||||||
from ..utils import dummy_cursor_class
|
from ..utils import dummy_cursor_class
|
||||||
|
|
||||||
|
@ -74,6 +79,71 @@ def test_handle_grant_on_col(privileges, start, end, output):
|
||||||
assert handle_grant_on_col(privileges, start, end) == output
|
assert handle_grant_on_col(privileges, start, end) == output
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
'input_tuple,output_tuple',
|
||||||
|
[
|
||||||
|
(('*.*:REQUIRESSL', None), (None, 'SSL')),
|
||||||
|
(('*.*:ALL,REQUIRESSL', None), ('*.*:ALL', 'SSL')),
|
||||||
|
(('*.*:REQUIRESSL,ALL', None), ('*.*:ALL', 'SSL')),
|
||||||
|
(('*.*:ALL,REQUIRESSL,GRANT', None), ('*.*:ALL,GRANT', 'SSL')),
|
||||||
|
(('*.*:ALL,REQUIRESSL,GRANT/a.b:USAGE', None), ('*.*:ALL,GRANT/a.b:USAGE', 'SSL')),
|
||||||
|
(('*.*:REQUIRESSL', 'X509'), (None, 'X509')),
|
||||||
|
(('*.*:ALL,REQUIRESSL', 'X509'), ('*.*:ALL', 'X509')),
|
||||||
|
(('*.*:REQUIRESSL,ALL', 'X509'), ('*.*:ALL', 'X509')),
|
||||||
|
(('*.*:ALL,REQUIRESSL,GRANT', 'X509'), ('*.*:ALL,GRANT', 'X509')),
|
||||||
|
(('*.*:ALL,REQUIRESSL,GRANT/a.b:USAGE', 'X509'), ('*.*:ALL,GRANT/a.b:USAGE', 'X509')),
|
||||||
|
(('*.*:REQUIRESSL', {
|
||||||
|
'subject': '/CN=alice/O=MyDom, Inc./C=US/ST=Oregon/L=Portland',
|
||||||
|
'cipher': 'ECDHE-ECDSA-AES256-SHA384',
|
||||||
|
'issuer': '/CN=org/O=MyDom, Inc./C=US/ST=Oregon/L=Portland'
|
||||||
|
}), (None, {
|
||||||
|
'subject': '/CN=alice/O=MyDom, Inc./C=US/ST=Oregon/L=Portland',
|
||||||
|
'cipher': 'ECDHE-ECDSA-AES256-SHA384',
|
||||||
|
'issuer': '/CN=org/O=MyDom, Inc./C=US/ST=Oregon/L=Portland'
|
||||||
|
})),
|
||||||
|
(('*.*:ALL,REQUIRESSL', {
|
||||||
|
'subject': '/CN=alice/O=MyDom, Inc./C=US/ST=Oregon/L=Portland',
|
||||||
|
'cipher': 'ECDHE-ECDSA-AES256-SHA384',
|
||||||
|
'issuer': '/CN=org/O=MyDom, Inc./C=US/ST=Oregon/L=Portland'
|
||||||
|
}), ('*.*:ALL', {
|
||||||
|
'subject': '/CN=alice/O=MyDom, Inc./C=US/ST=Oregon/L=Portland',
|
||||||
|
'cipher': 'ECDHE-ECDSA-AES256-SHA384',
|
||||||
|
'issuer': '/CN=org/O=MyDom, Inc./C=US/ST=Oregon/L=Portland'
|
||||||
|
})),
|
||||||
|
(('*.*:REQUIRESSL,ALL', {
|
||||||
|
'subject': '/CN=alice/O=MyDom, Inc./C=US/ST=Oregon/L=Portland',
|
||||||
|
'cipher': 'ECDHE-ECDSA-AES256-SHA384',
|
||||||
|
'issuer': '/CN=org/O=MyDom, Inc./C=US/ST=Oregon/L=Portland'
|
||||||
|
}), ('*.*:ALL', {
|
||||||
|
'subject': '/CN=alice/O=MyDom, Inc./C=US/ST=Oregon/L=Portland',
|
||||||
|
'cipher': 'ECDHE-ECDSA-AES256-SHA384',
|
||||||
|
'issuer': '/CN=org/O=MyDom, Inc./C=US/ST=Oregon/L=Portland'
|
||||||
|
})),
|
||||||
|
(('*.*:ALL,REQUIRESSL,GRANT', {
|
||||||
|
'subject': '/CN=alice/O=MyDom, Inc./C=US/ST=Oregon/L=Portland',
|
||||||
|
'cipher': 'ECDHE-ECDSA-AES256-SHA384',
|
||||||
|
'issuer': '/CN=org/O=MyDom, Inc./C=US/ST=Oregon/L=Portland'
|
||||||
|
}), ('*.*:ALL,GRANT', {
|
||||||
|
'subject': '/CN=alice/O=MyDom, Inc./C=US/ST=Oregon/L=Portland',
|
||||||
|
'cipher': 'ECDHE-ECDSA-AES256-SHA384',
|
||||||
|
'issuer': '/CN=org/O=MyDom, Inc./C=US/ST=Oregon/L=Portland'
|
||||||
|
})),
|
||||||
|
(('*.*:ALL,REQUIRESSL,GRANT/a.b:USAGE', {
|
||||||
|
'subject': '/CN=alice/O=MyDom, Inc./C=US/ST=Oregon/L=Portland',
|
||||||
|
'cipher': 'ECDHE-ECDSA-AES256-SHA384',
|
||||||
|
'issuer': '/CN=org/O=MyDom, Inc./C=US/ST=Oregon/L=Portland'
|
||||||
|
}), ('*.*:ALL,GRANT/a.b:USAGE', {
|
||||||
|
'subject': '/CN=alice/O=MyDom, Inc./C=US/ST=Oregon/L=Portland',
|
||||||
|
'cipher': 'ECDHE-ECDSA-AES256-SHA384',
|
||||||
|
'issuer': '/CN=org/O=MyDom, Inc./C=US/ST=Oregon/L=Portland'
|
||||||
|
}))
|
||||||
|
]
|
||||||
|
)
|
||||||
|
def test_handle_requiressl_in_priv_string(input_tuple, output_tuple):
|
||||||
|
"""Tests the handle_requiressl_in_priv_string funciton."""
|
||||||
|
assert handle_requiressl_in_priv_string(MagicMock(), *input_tuple) == output_tuple
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
'input_,expected',
|
'input_,expected',
|
||||||
[
|
[
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue