"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/utils/test/js_normalizer_test.cc" between
snort3-3.1.31.0.tar.gz and snort3-3.1.32.0.tar.gz

About: Snort 3 is a network intrusion prevention and detection system (IDS/IPS) combining the benefits of signature, protocol and anomaly-based inspection.

js_normalizer_test.cc  (snort3-3.1.31.0):js_normalizer_test.cc  (snort3-3.1.32.0)
skipping to change at line 687 skipping to change at line 687
"[^:/\\\\%]+\\/|[^:/\\\\%]*[?#]|about:blank#)/i;" "[^:/\\\\%]+\\/|[^:/\\\\%]*[?#]|about:blank#)/i;"
"/[/ a b c / 1]/ a b c / 1;"; "/[/ a b c / 1]/ a b c / 1;";
static const char all_patterns_expected9[] = static const char all_patterns_expected9[] =
"var r=/^(?:(?:https?|mailto|ftp):|[^:/?#]*(?:[/?#]|$))/i;" "var r=/^(?:(?:https?|mailto|ftp):|[^:/?#]*(?:[/?#]|$))/i;"
"new Lb(function(a){return /^[^:]*([/?#]|$)/.test(a)});" "new Lb(function(a){return /^[^:]*([/?#]|$)/.test(a)});"
"pa=/^((https:)?\\/\\/[0-9a-z.:[\\]-]+\\/|\\/[^/\\\\]" "pa=/^((https:)?\\/\\/[0-9a-z.:[\\]-]+\\/|\\/[^/\\\\]"
"|[^:/\\\\%]+\\/|[^:/\\\\%]*[?#]|about:blank#)/i;" "|[^:/\\\\%]+\\/|[^:/\\\\%]*[?#]|about:blank#)/i;"
"/[/ a b c / 1]/ a b c/1;"; "/[/ a b c / 1]/ a b c/1;";
static const char all_patterns_buf10[] =
"function(a){if(!/^\\s*{/.test(a))return!1;a=_.xf(a);return null!==a&&\"obje
ct\"===typeof a&&!!a.g};"
"/^\\s*$/.test(Q)?0:/^[\\],:{}]*$/.replace(/(?=:|,|]|}|$)/g,z)";
static const char all_patterns_expected10[] =
"function(a){if(!/^\\s*{/.test(a))return!1;a=_.xf(a);return null!==a&&\"obje
ct\"===typeof a&&!!a.g};"
"/^\\s*$/.test(Q)?0:/^[\\],:{}]*$/.replace(/(?=:|,|]|}|$)/g,z)";
TEST_CASE("all patterns", "[JSNormalizer]") TEST_CASE("all patterns", "[JSNormalizer]")
{ {
SECTION("whitespaces and special characters") SECTION("whitespaces and special characters")
{ {
NORMALIZE(all_patterns_buf0); NORMALIZE(all_patterns_buf0);
VALIDATE(all_patterns_buf0, all_patterns_expected0); VALIDATE(all_patterns_buf0, all_patterns_expected0);
} }
SECTION("comments") SECTION("comments")
{ {
NORMALIZE(all_patterns_buf1); NORMALIZE(all_patterns_buf1);
skipping to change at line 792 skipping to change at line 800
SECTION("multiple escaped slashes") SECTION("multiple escaped slashes")
{ {
NORMALIZE(all_patterns_buf8); NORMALIZE(all_patterns_buf8);
VALIDATE(all_patterns_buf8, all_patterns_expected8); VALIDATE(all_patterns_buf8, all_patterns_expected8);
} }
SECTION("slashes and braces") SECTION("slashes and braces")
{ {
NORMALIZE(all_patterns_buf9); NORMALIZE(all_patterns_buf9);
VALIDATE(all_patterns_buf9, all_patterns_expected9); VALIDATE(all_patterns_buf9, all_patterns_expected9);
} }
SECTION("regex literal with curly brace")
{
NORMALIZE(all_patterns_buf10);
VALIDATE(all_patterns_buf10, all_patterns_expected10);
}
} }
// Test vectors for different syntax cases // Test vectors for different syntax cases
static const char syntax_cases_buf0[] = static const char syntax_cases_buf0[] =
"var a;\n" "var a;\n"
"var b = \"init this stuff\";\n" "var b = \"init this stuff\";\n"
"var c = \"Hi\" + \" \" + \"Joe\";\n" "var c = \"Hi\" + \" \" + \"Joe\";\n"
"var d = 1 + 2 + \"3\";\n" "var d = 1 + 2 + \"3\";\n"
"var e = [ 2, 3, 5, 8 ];\n" "var e = [ 2, 3, 5, 8 ];\n"
"var f = false;\n" "var f = false;\n"
skipping to change at line 1112 skipping to change at line 1125
static const char syntax_cases_expected22[] = static const char syntax_cases_expected22[] =
"tag `template\n \\\\\\${ } \\\\${a+` template ${1+c}`}`"; "tag `template\n \\\\\\${ } \\\\${a+` template ${1+c}`}`";
static const char syntax_cases_buf23[] = static const char syntax_cases_buf23[] =
"`${`${`${`${`${}`}`}`}`}`}"; "`${`${`${`${`${}`}`}`}`}`}";
static const char syntax_cases_expected23[] = static const char syntax_cases_expected23[] =
"`${`${`${`${`"; "`${`${`${`${`";
static const char syntax_cases_buf24[] = static const char syntax_cases_buf24[] =
"var a=/{{{{/}}}}/;" "var a=/((((/))))/;"
"var b=/{{{{{/}}}}}/;"; "var b=/(((((/)))))/;";
static const char syntax_cases_expected24[] = static const char syntax_cases_expected24[] =
"var a=/{{{{/}}}}/;" "var a=/((((/))))/;"
"var b=/{{{{"; "var b=/((((";
static const char syntax_cases_buf25[] = static const char syntax_cases_buf25[] =
"return /regex0/.foo + /regex1/.bar ;" "return /regex0/.foo + /regex1/.bar ;"
"return /regex2/.baz * /regex3/.qux ;"; "return /regex2/.baz * /regex3/.qux ;";
static const char syntax_cases_expected25[] = static const char syntax_cases_expected25[] =
"return /regex0/.var_0000+/regex1/.var_0001;" "return /regex0/.var_0000+/regex1/.var_0001;"
"return /regex2/.var_0002*/regex3/.var_0003;"; "return /regex2/.var_0002*/regex3/.var_0003;";
TEST_CASE("syntax cases", "[JSNormalizer]") TEST_CASE("syntax cases", "[JSNormalizer]")
skipping to change at line 3563 skipping to change at line 3576
const char dat2[] = "b=/({})[]/"; const char dat2[] = "b=/({})[]/";
const char dat3[] = "c=/(){[]}/"; const char dat3[] = "c=/(){[]}/";
const char exp1[] = "a=/(){}[]/"; const char exp1[] = "a=/(){}[]/";
const char exp2[] = "b=/({})[]/"; const char exp2[] = "b=/({})[]/";
const char exp3[] = "c=/(){[]}/"; const char exp3[] = "c=/(){[]}/";
NORMALIZE_1(dat1, exp1); NORMALIZE_1(dat1, exp1);
NORMALIZE_1(dat2, exp2); NORMALIZE_1(dat2, exp2);
NORMALIZE_1(dat3, exp3); NORMALIZE_1(dat3, exp3);
} }
SECTION("parentheses - wrong closing symbol")
{
const char dat1[] = "/({ (} })/";
const char dat2[] = "/({ (] })/";
const char exp1[] = "/({ (";
const char exp2[] = "/({ (";
NORM_BAD_1(dat1, exp1, JSTokenizer::BAD_TOKEN);
NORM_BAD_1(dat2, exp2, JSTokenizer::BAD_TOKEN);
}
SECTION("curly braces - wrong closing symbol")
{
const char dat1[] = "/({ {) })/";
const char dat2[] = "/({ {] })/";
const char exp1[] = "/({ {";
const char exp2[] = "/({ {";
NORM_BAD_1(dat1, exp1, JSTokenizer::BAD_TOKEN);
NORM_BAD_1(dat2, exp2, JSTokenizer::BAD_TOKEN);
}
SECTION("square brackets - raw bracket") SECTION("square brackets - raw bracket")
{ {
const char dat1[] = "/]/"; const char dat1[] = "/]/";
const char dat2[] = "/[]]/"; const char dat2[] = "/[]]/";
const char dat3[] = "/][]]/g"; const char dat3[] = "/][]]/g";
const char exp1[] = "/]/"; const char exp1[] = "/]/";
const char exp2[] = "/[]]/"; const char exp2[] = "/[]]/";
const char exp3[] = "/][]]/g"; const char exp3[] = "/][]]/g";
NORMALIZE_1(dat1, exp1); NORMALIZE_1(dat1, exp1);
NORMALIZE_1(dat2, exp2); NORMALIZE_1(dat2, exp2);
NORMALIZE_1(dat3, exp3); NORMALIZE_1(dat3, exp3);
} }
SECTION("parentheses - mismatch") SECTION("parentheses - mismatch")
{ {
const char dat1[] = "/)/"; const char dat1[] = "/)/";
const char dat2[] = "/())/"; const char dat2[] = "/())/";
const char dat3[] = "/({{ ()) }})/"; const char dat3[] = "/( ()) )/";
const char exp1[] = "/"; const char exp1[] = "/";
const char exp2[] = "/()"; const char exp2[] = "/()";
const char exp3[] = "/({{ ()"; const char exp3[] = "/( ()) ";
NORM_BAD_1(dat1, exp1, JSTokenizer::BAD_TOKEN);
NORM_BAD_1(dat2, exp2, JSTokenizer::BAD_TOKEN);
NORM_BAD_1(dat3, exp3, JSTokenizer::BAD_TOKEN);
}
SECTION("curly braces - mismatch")
{
const char dat1[] = "/}/";
const char dat2[] = "/{}}/";
const char dat3[] = "/({( {}} )})/";
const char exp1[] = "/";
const char exp2[] = "/{}";
const char exp3[] = "/({( {}";
NORM_BAD_1(dat1, exp1, JSTokenizer::BAD_TOKEN); NORM_BAD_1(dat1, exp1, JSTokenizer::BAD_TOKEN);
NORM_BAD_1(dat2, exp2, JSTokenizer::BAD_TOKEN); NORM_BAD_1(dat2, exp2, JSTokenizer::BAD_TOKEN);
NORM_BAD_1(dat3, exp3, JSTokenizer::BAD_TOKEN); NORM_BAD_1(dat3, exp3, JSTokenizer::BAD_TOKEN);
} }
SECTION("parentheses - continuation") SECTION("parentheses - continuation")
{ {
const char dat1[] = "/(("; const char dat1[] = "/((";
const char dat2[] = "))/"; const char dat2[] = "))/";
const char exp1[] = "/(("; const char exp1[] = "/((";
const char exp2[] = "))/"; const char exp2[] = "))/";
const char exp[] = "/(())/"; const char exp[] = "/(())/";
NORMALIZE_2(dat1, dat2, exp1, exp2); NORMALIZE_2(dat1, dat2, exp1, exp2);
NORM_COMBINED_2(dat1, dat2, exp); NORM_COMBINED_2(dat1, dat2, exp);
} }
SECTION("curly braces - continuation")
{
const char dat1[] = "/{{";
const char dat2[] = "}}/";
const char exp1[] = "/{{";
const char exp2[] = "}}/";
const char exp[] = "/{{}}/";
NORMALIZE_2(dat1, dat2, exp1, exp2);
NORM_COMBINED_2(dat1, dat2, exp);
}
SECTION("square brackets - continuation") SECTION("square brackets - continuation")
{ {
const char dat1[] = "/[["; const char dat1[] = "/[[";
const char dat2[] = "[]/"; const char dat2[] = "[]/";
const char exp1[] = "/[["; const char exp1[] = "/[[";
const char exp2[] = "[]/"; const char exp2[] = "[]/";
const char exp[] = "/[[[]/"; const char exp[] = "/[[[]/";
NORMALIZE_2(dat1, dat2, exp1, exp2); NORMALIZE_2(dat1, dat2, exp1, exp2);
NORM_COMBINED_2(dat1, dat2, exp); NORM_COMBINED_2(dat1, dat2, exp);
skipping to change at line 3666 skipping to change at line 3635
{ {
const char dat1[] = "/("; const char dat1[] = "/(";
const char dat2[] = "))/"; const char dat2[] = "))/";
const char exp1[] = "/("; const char exp1[] = "/(";
const char exp2[] = ")"; const char exp2[] = ")";
const char exp[] = "/()"; const char exp[] = "/()";
NORM_BAD_2(dat1, dat2, exp1, exp2, JSTokenizer::BAD_TOKEN); NORM_BAD_2(dat1, dat2, exp1, exp2, JSTokenizer::BAD_TOKEN);
NORM_COMBINED_BAD_2(dat1, dat2, exp, JSTokenizer::BAD_TOKEN); NORM_COMBINED_BAD_2(dat1, dat2, exp, JSTokenizer::BAD_TOKEN);
} }
SECTION("curly braces - mismatch in continuation")
{
const char dat1[] = "/{";
const char dat2[] = "}}/";
const char exp1[] = "/{";
const char exp2[] = "}";
const char exp[] = "/{}";
NORM_BAD_2(dat1, dat2, exp1, exp2, JSTokenizer::BAD_TOKEN);
NORM_COMBINED_BAD_2(dat1, dat2, exp, JSTokenizer::BAD_TOKEN);
}
} }
TEST_CASE("ignored identifiers", "[JSNormalizer]") TEST_CASE("ignored identifiers", "[JSNormalizer]")
{ {
// 'console' 'eval' 'document' are in the ignore list // 'console' 'eval' 'document' are in the ignore list
SECTION("a standalone identifier") SECTION("a standalone identifier")
{ {
const char dat1[] = "alpha bravo console delta eval"; const char dat1[] = "alpha bravo console delta eval";
const char dat2[] = "var a = 0; console = 1;"; const char dat2[] = "var a = 0; console = 1;";
skipping to change at line 4248 skipping to change at line 4206
const char dat14[] = "foo . unwatch () \n . bar ;"; const char dat14[] = "foo . unwatch () \n . bar ;";
const char dat15[] = "foo ['unwatch'] () \n . bar ;"; const char dat15[] = "foo ['unwatch'] () \n . bar ;";
const char dat16[] = "foo /*multiline*/ . unwatch ( ) . // oneline \n ba r ;"; const char dat16[] = "foo /*multiline*/ . unwatch ( ) . // oneline \n ba r ;";
const char dat17[] = "foo . + watch . bar ;"; const char dat17[] = "foo . + watch . bar ;";
const char dat18[] = "foo . + ['watch'] . bar ;"; const char dat18[] = "foo . + ['watch'] . bar ;";
const char dat19[] = "foo . + unwatch() . bar ;"; const char dat19[] = "foo . + unwatch() . bar ;";
const char dat20[] = "foo . + ['unwatch']() . bar ;"; const char dat20[] = "foo . + ['unwatch']() . bar ;";
// FIXIT-L: add support for proper tracking of bracket accessors.
// Current behavior: foo['watch'].bar -> var_0000['watch'].var_0001
// Expected behavior: foo['watch'].bar -> var_0000['watch'].bar
const char exp1[] = "var_0000.watch.bar;"; const char exp1[] = "var_0000.watch.bar;";
const char exp2[] = "var_0000['watch'].var_0001;"; const char exp2[] = "var_0000['watch'].var_0001;";
const char exp3[] = "var_0000.var_0001.watch.bar;"; const char exp3[] = "var_0000.var_0001.watch.bar;";
const char exp4[] = "var_0000['bar'].watch['bar'];"; const char exp4[] = "var_0000['bar'].watch['bar'];";
const char exp5[] = "var_0000['bar'].watch['bar'].baz;"; const char exp5[] = "var_0000['bar'].watch['bar'].baz;";
const char exp6[] = "var_0000.unwatch().bar;"; const char exp6[] = "var_0000.unwatch().bar;";
const char exp7[] = "var_0000['unwatch']().var_0001;"; const char exp7[] = "var_0000['unwatch']().var_0001;";
const char exp8[] = "var_0000.var_0001.unwatch().bar;"; const char exp8[] = "var_0000.var_0001.unwatch().bar;";
const char exp9[] = "var_0000['bar'].unwatch()['bar'];"; const char exp9[] = "var_0000['bar'].unwatch()['bar'];";
 End of changes. 10 change blocks. 
64 lines changed or deleted 21 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)