diff options
-rw-r--r-- | gn_libs/mysqldb.py | 10 | ||||
-rw-r--r-- | tests/unit/test_mysqldb.py | 5 |
2 files changed, 14 insertions, 1 deletions
diff --git a/gn_libs/mysqldb.py b/gn_libs/mysqldb.py index d620b11..4997ac7 100644 --- a/gn_libs/mysqldb.py +++ b/gn_libs/mysqldb.py @@ -29,6 +29,15 @@ def __non_negative_int__(val: str) -> int: _val = int(val) assert (val >= 0), f"Expected a non-negative value. Got {_val}" return _val + + +def __parse_ssl_mode_options__(val: str) -> str: + mode_opts = ( + "DISABLED", "PREFERRED", "REQUIRED", "VERIFY_CA", "VERIFY_IDENTITY") + _val = val.strip().upper() + if(_val not in mode_opts): + raise InvalidOptionValue(f"Invalid ssl_mode option: {_val}") + return _val def __parse_db_opts__(opts: str) -> dict: """Parse database options into their appropriate values. @@ -48,6 +57,7 @@ def __parse_db_opts__(opts: str) -> dict: "client_flag": int, # "ssl": __parse_ssl_options__, "multi_statements": __parse_boolean__, + "ssl_mode": __parse_ssl_mode_options__, "local_infile": __parse_boolean__, "autocommit": __parse_boolean__, "binary_prefix": __parse_boolean__ diff --git a/tests/unit/test_mysqldb.py b/tests/unit/test_mysqldb.py index 153f322..793dc1d 100644 --- a/tests/unit/test_mysqldb.py +++ b/tests/unit/test_mysqldb.py @@ -88,7 +88,10 @@ def test_parse_db_url_with_invalid_options(sql_uri, invalidopt): (("mysql://auser:passwd@somehost:3307/thedb?use_unicode=fire"), ("mysql://auser:passwd@somehost:3307/thedb?use_unicode=3"), ("mysql://auser:passwd@somehost:3307/thedb?connect_timeout=-30"), - ("mysql://auser:passwd@somehost:3307/thedb?connect_timeout=santa"))) + ("mysql://auser:passwd@somehost:3307/thedb?connect_timeout=santa"), + ("mysql://auser:passwd@somehost:3307/thedb?ssl_mode=yellow"), + ("mysql://auser:passwd@somehost:3307/thedb?ssl_mode=55"), + ("mysql://auser:passwd@somehost:3307/thedb?ssl_mode=true"))) def test_parse_db_url_with_invalid_options_values(sql_uri): """Test parsing with invalid options' values.""" with pytest.raises(InvalidOptionValue) as iov: |