Adding tests to check passing invalid data types

to encrypt and aes_encrypt_mysql functions.
This commit is contained in:
Vitaliy Zakaznikov 2021-01-27 09:27:34 -05:00
parent 085e8c7825
commit 48884d2231
3 changed files with 78 additions and 0 deletions

View File

@ -18,11 +18,15 @@ xfails = {
[(Fail, "known issue")],
"encrypt/invalid key or iv length for mode/mode=\"'aes-???-gcm'\", key_len=??, iv_len=12, aad=True/iv is too long":
[(Fail, "known issue")],
"encrypt/invalid plaintext data type/data_type='IPv6', value=\"toIPv6('2001:0db8:0000:85a3:0000:0000:ac1f:8001')\"":
[(Fail, "known issue as IPv6 is implemented as FixedString(16)")],
# encrypt_mysql
"encrypt_mysql/key or iv length for mode/mode=\"'aes-???-ecb'\", key_len=??, iv_len=None":
[(Fail, issue_18251)],
"encrypt_mysql/invalid parameters/iv not valid for mode":
[(Fail, issue_18251)],
"encrypt_mysql/invalid plaintext data type/data_type='IPv6', value=\"toIPv6('2001:0db8:0000:85a3:0000:0000:ac1f:8001')\"":
[(Fail, "known issue as IPv6 is implemented as FixedString(16)")],
# decrypt_mysql
"decrypt_mysql/key or iv length for mode/mode=\"'aes-???-ecb'\", key_len=??, iv_len=None:":
[(Fail, issue_18251)],

View File

@ -108,6 +108,43 @@ def invalid_parameters(self):
encrypt(plaintext="'hello there'", key="'0123456789123456'", mode="'AES-128-ECB'", exitcode=36,
message="DB::Exception: Invalid mode: AES-128-ECB")
@TestOutline(Scenario)
@Requirements(
RQ_SRS008_AES_Functions_InvalidParameters("1.0")
)
@Examples("data_type, value", [
("UInt8", "toUInt8('1')"),
("UInt16", "toUInt16('1')"),
("UInt32", "toUInt32('1')"),
("UInt64", "toUInt64('1')"),
("Int8", "toInt8('1')"),
("Int16", "toInt16('1')"),
("Int32", "toInt32('1')"),
("Int64", "toInt64('1')"),
("Float32", "toFloat32('1.0')"),
("Float64", "toFloat64('1.0')"),
("Decimal32", "toDecimal32(2, 4)"),
("Decimal64", "toDecimal64(2, 4)"),
("Decimal128", "toDecimal128(2, 4)"),
("UUID", "toUUID('61f0c404-5cb3-11e7-907b-a6006ad3dba0')"),
("Date", "toDate('2020-01-01')"),
("DateTime", "toDateTime('2020-01-01 20:01:02')"),
("DateTime64", "toDateTime64('2020-01-01 20:01:02.123', 3)"),
("Array", "[1,2]"),
("Tuple", "(1,'a')"),
("IPv4", "toIPv4('171.225.130.45')"),
("IPv6", "toIPv6('2001:0db8:0000:85a3:0000:0000:ac1f:8001')"),
("Enum8", r"CAST('a', 'Enum8(\'a\' = 1, \'b\' = 2)')"),
("Enum16", r"CAST('a', 'Enum16(\'a\' = 1, \'b\' = 2)')")
])
def invalid_plaintext_data_type(self, data_type, value):
"""Check that encrypt function returns an error if the
plaintext parameter has invalid data type.
"""
with When("I try to encrypt plaintext with invalid data type", description=f"{data_type} with value {value}"):
encrypt(plaintext=value, key="'0123456789123456'", mode="'aes-128-cbc'", iv="'0123456789123456'",
exitcode=43, message="DB::Exception: Illegal type of argument")
@TestOutline(Scenario)
@Requirements(
RQ_SRS008_AES_Encrypt_Function_Key_Length_InvalidLengthError("1.0"),

View File

@ -107,6 +107,43 @@ def invalid_parameters(self):
aes_encrypt_mysql(plaintext="'hello there'", key="'0123456789123456'", mode="'AES-128-ECB'", exitcode=36,
message="DB::Exception: Invalid mode: AES-128-ECB")
@TestOutline(Scenario)
@Requirements(
RQ_SRS008_AES_Functions_InvalidParameters("1.0")
)
@Examples("data_type, value", [
("UInt8", "toUInt8('1')"),
("UInt16", "toUInt16('1')"),
("UInt32", "toUInt32('1')"),
("UInt64", "toUInt64('1')"),
("Int8", "toInt8('1')"),
("Int16", "toInt16('1')"),
("Int32", "toInt32('1')"),
("Int64", "toInt64('1')"),
("Float32", "toFloat32('1.0')"),
("Float64", "toFloat64('1.0')"),
("Decimal32", "toDecimal32(2, 4)"),
("Decimal64", "toDecimal64(2, 4)"),
("Decimal128", "toDecimal128(2, 4)"),
("UUID", "toUUID('61f0c404-5cb3-11e7-907b-a6006ad3dba0')"),
("Date", "toDate('2020-01-01')"),
("DateTime", "toDateTime('2020-01-01 20:01:02')"),
("DateTime64", "toDateTime64('2020-01-01 20:01:02.123', 3)"),
("Array", "[1,2]"),
("Tuple", "(1,'a')"),
("IPv4", "toIPv4('171.225.130.45')"),
("IPv6", "toIPv6('2001:0db8:0000:85a3:0000:0000:ac1f:8001')"),
("Enum8", r"CAST('a', 'Enum8(\'a\' = 1, \'b\' = 2)')"),
("Enum16", r"CAST('a', 'Enum16(\'a\' = 1, \'b\' = 2)')")
])
def invalid_plaintext_data_type(self, data_type, value):
"""Check that aes_encrypt_mysql function returns an error if the
plaintext parameter has invalid data type.
"""
with When("I try to encrypt plaintext with invalid data type", description=f"{data_type} with value {value}"):
aes_encrypt_mysql(plaintext=value, key="'0123456789123456'", mode="'aes-128-cbc'", iv="'0123456789123456'",
exitcode=43, message="DB::Exception: Illegal type of argument")
@TestOutline(Scenario)
@Requirements(
RQ_SRS008_AES_MySQL_Encrypt_Function_Key_Length_TooShortError("1.0"),