MXS-1302: added tests for "obfuscate"
Tests updated
This commit is contained in:
@ -346,6 +346,17 @@ bool create_rules_from_array(json_t* pRules, vector<shared_ptr<MaskingRules::Rul
|
||||
json_t* pObfuscate = json_object_get(pRule, KEY_OBFUSCATE);
|
||||
json_t* pReplace = json_object_get(pRule, KEY_REPLACE);
|
||||
|
||||
// Check whether we have KEY_OBFUSCATE or KEY_REPLACE
|
||||
if (!pReplace && !pObfuscate)
|
||||
{
|
||||
MXS_ERROR("A masking rule does not contain a '%s' or '%s' key.",
|
||||
KEY_OBFUSCATE,
|
||||
KEY_REPLACE);
|
||||
parsed = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Obfuscate takes the precedence
|
||||
if (pObfuscate)
|
||||
{
|
||||
sRule = MaskingRules::ObfuscateRule::create_from(pRule);
|
||||
@ -554,7 +565,7 @@ auto_ptr<MaskingRules::Rule> MaskingRules::ReplaceRule::create_from(json_t* pRul
|
||||
// Set the account rules
|
||||
if (pApplies_to && pExempted &&
|
||||
(!get_accounts(KEY_APPLIES_TO, pApplies_to, applies_to) ||
|
||||
(!get_accounts(KEY_EXEMPTED, pExempted, exempted))))
|
||||
!get_accounts(KEY_EXEMPTED, pExempted, exempted)))
|
||||
{
|
||||
return sRule;
|
||||
}
|
||||
@ -661,7 +672,7 @@ auto_ptr<MaskingRules::Rule> MaskingRules::ObfuscateRule::create_from(json_t* pR
|
||||
// Set the account rules
|
||||
if (pApplies_to && pExempted &&
|
||||
(!get_accounts(KEY_APPLIES_TO, pApplies_to, applies_to) ||
|
||||
(!get_accounts(KEY_EXEMPTED, pExempted, exempted))))
|
||||
!get_accounts(KEY_EXEMPTED, pExempted, exempted)))
|
||||
{
|
||||
return sRule;
|
||||
}
|
||||
|
||||
@ -29,6 +29,11 @@ const char valid_minimal[] =
|
||||
" \"with\": {"
|
||||
" \"value\": \"blah\" "
|
||||
" }"
|
||||
" },"
|
||||
" {"
|
||||
" \"obfuscate\": { "
|
||||
" \"column\": \"b\" "
|
||||
" }"
|
||||
" }"
|
||||
" ]"
|
||||
"}";
|
||||
@ -54,11 +59,18 @@ const char valid_maximal[] =
|
||||
" \"exempted\": ["
|
||||
" \"'admin'\""
|
||||
" ]"
|
||||
" },"
|
||||
" {"
|
||||
" \"obfuscate\": { "
|
||||
" \"column\": \"c\", "
|
||||
" \"table\": \"d\", "
|
||||
" \"database\": \"e\" "
|
||||
" }"
|
||||
" }"
|
||||
" ]"
|
||||
"}";
|
||||
|
||||
// Neither "replace", nor "with".
|
||||
// Neither "obfuscate", nor "replace".
|
||||
const char invalid1[] =
|
||||
"{"
|
||||
" \"rules\": ["
|
||||
@ -82,13 +94,24 @@ const char invalid2[] =
|
||||
" \"replace\": { "
|
||||
" },"
|
||||
" \"with\": { "
|
||||
" \"value\": \"blah\", "
|
||||
" \"value\": \"blah\" "
|
||||
" }"
|
||||
" }"
|
||||
" ]"
|
||||
"}";
|
||||
|
||||
// No "value" or "fill" in "with"
|
||||
/**
|
||||
* NOTE:
|
||||
* This test fails for ", " after column
|
||||
* and after "}," (Json parsing).
|
||||
*
|
||||
* If Json is ok the test doesn't fail at all.
|
||||
* The default 'fill' is used even if value is not set:
|
||||
*
|
||||
* void MaskingRules::ReplaceRule::rewrite(LEncString& s)
|
||||
*
|
||||
*/
|
||||
const char invalid3[] =
|
||||
"{"
|
||||
" \"rules\": ["
|
||||
@ -102,6 +125,36 @@ const char invalid3[] =
|
||||
" ]"
|
||||
"}";
|
||||
|
||||
// No "column" in "obfuscate"
|
||||
const char invalid4[] =
|
||||
"{"
|
||||
" \"rules\": ["
|
||||
" {"
|
||||
" \"obfuscate\": { "
|
||||
" }"
|
||||
" }"
|
||||
" ]"
|
||||
"}";
|
||||
|
||||
// No "with" in "replace"
|
||||
const char invalid5[] =
|
||||
"{"
|
||||
" \"rules\": ["
|
||||
" {"
|
||||
" \"replace\": { "
|
||||
" \"column\": \"a\" "
|
||||
" },"
|
||||
" \"applies_to\": ["
|
||||
" \"'alice'@'host'\","
|
||||
" \"'bob'@'%'\""
|
||||
" ],"
|
||||
" \"exempted\": ["
|
||||
" \"'admin'\""
|
||||
" ]"
|
||||
" }"
|
||||
" ]"
|
||||
"}";
|
||||
|
||||
struct rule_test
|
||||
{
|
||||
const char* zJson;
|
||||
@ -113,6 +166,8 @@ struct rule_test
|
||||
{ invalid1, false },
|
||||
{ invalid2, false },
|
||||
{ invalid3, false },
|
||||
{ invalid4, false },
|
||||
{ invalid5, false },
|
||||
};
|
||||
|
||||
const size_t nRule_tests = (sizeof(rule_tests) / sizeof(rule_tests[0]));
|
||||
@ -244,10 +299,13 @@ int main()
|
||||
{
|
||||
int rc = EXIT_SUCCESS;
|
||||
|
||||
if (mxs_log_init(NULL, ".", MXS_LOG_TARGET_DEFAULT))
|
||||
if (mxs_log_init(NULL, ".", MXS_LOG_TARGET_STDOUT))
|
||||
{
|
||||
rc = (MaskingRulesTester::test_parsing() == EXIT_FAILURE) ? EXIT_FAILURE : EXIT_SUCCESS;
|
||||
rc = (MaskingRulesTester::test_account_handling() == EXIT_FAILURE) ? EXIT_FAILURE : EXIT_SUCCESS;
|
||||
if (!rc)
|
||||
{
|
||||
rc = (MaskingRulesTester::test_account_handling() == EXIT_FAILURE) ? EXIT_FAILURE : EXIT_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
return rc;
|
||||
|
||||
Reference in New Issue
Block a user