|
| 1 | +%%% % DO NOT EDIT: this file was generated by 'just codegen' |
| 2 | +%%% % @generated SignedSource<<60159ac2f544d43788d7acc38b52a010>> |
| 3 | +%%% % @format |
| 4 | +%%%----------------------------------------------------------------------------- |
| 5 | +%%% Copyright (c) Meta Platforms, Inc. and affiliates. |
| 6 | +%%% Copyright (c) WhatsApp LLC |
| 7 | +%%% |
| 8 | +%%% This source code is licensed under the MIT license found in the |
| 9 | +%%% LICENSE.md file in the root directory of this source tree. |
| 10 | +%%%----------------------------------------------------------------------------- |
| 11 | +-module(markdown_gfm_tagfilter_SUITE). |
| 12 | +-moduledoc """ |
| 13 | + |
| 14 | +""". |
| 15 | +- moduledoc #{ author => [ "Andrew Bennett <[email protected]>"]}. |
| 16 | +-moduledoc #{created => "", modified => ""}. |
| 17 | +-moduledoc #{copyright => "Meta Platforms, Inc. and affiliates."}. |
| 18 | +-compile(warn_missing_spec_all). |
| 19 | +-oncall("whatsapp_clr"). |
| 20 | + |
| 21 | +-include_lib("markdown/include/markdown_mdast.hrl"). |
| 22 | +-include_lib("markdown/include/markdown_util.hrl"). |
| 23 | +-include_lib("stdlib/include/assert.hrl"). |
| 24 | + |
| 25 | +-behaviour(ct_suite). |
| 26 | + |
| 27 | +%% ct_suite callbacks |
| 28 | +-export([ |
| 29 | + all/0, |
| 30 | + groups/0, |
| 31 | + init_per_suite/1, |
| 32 | + end_per_suite/1, |
| 33 | + init_per_group/2, |
| 34 | + end_per_group/2 |
| 35 | +]). |
| 36 | + |
| 37 | +%% Test Cases |
| 38 | +-export([ |
| 39 | + test_gfm_tagfilter_case_1/1, |
| 40 | + test_gfm_tagfilter_case_2/1, |
| 41 | + test_gfm_tagfilter_case_3/1, |
| 42 | + test_gfm_tagfilter_case_4/1, |
| 43 | + test_gfm_tagfilter_case_5/1, |
| 44 | + test_gfm_tagfilter_case_6/1 |
| 45 | +]). |
| 46 | + |
| 47 | +%%%============================================================================= |
| 48 | +%%% ct_suite callbacks |
| 49 | +%%%============================================================================= |
| 50 | + |
| 51 | +-spec all() -> markdown_test:all(). |
| 52 | +all() -> |
| 53 | + [ |
| 54 | + {group, static} |
| 55 | + ]. |
| 56 | + |
| 57 | +-spec groups() -> markdown_test:groups(). |
| 58 | +groups() -> |
| 59 | + [ |
| 60 | + {static, [parallel], [ |
| 61 | + test_gfm_tagfilter_case_1, |
| 62 | + test_gfm_tagfilter_case_2, |
| 63 | + test_gfm_tagfilter_case_3, |
| 64 | + test_gfm_tagfilter_case_4, |
| 65 | + test_gfm_tagfilter_case_5, |
| 66 | + test_gfm_tagfilter_case_6 |
| 67 | + ]} |
| 68 | + ]. |
| 69 | + |
| 70 | +-spec init_per_suite(Config :: ct_suite:ct_config()) -> markdown_test:init_per_suite(). |
| 71 | +init_per_suite(Config) -> |
| 72 | + Config. |
| 73 | + |
| 74 | +-spec end_per_suite(Config :: ct_suite:ct_config()) -> markdown_test:end_per_suite(). |
| 75 | +end_per_suite(_Config) -> |
| 76 | + ok. |
| 77 | + |
| 78 | +-spec init_per_group(GroupName :: ct_suite:ct_groupname(), Config :: ct_suite:ct_config()) -> |
| 79 | + markdown_test:init_per_group(). |
| 80 | +init_per_group(_Group, Config) -> |
| 81 | + Config. |
| 82 | + |
| 83 | +-spec end_per_group(GroupName :: ct_suite:ct_groupname(), Config :: ct_suite:ct_config()) -> |
| 84 | + markdown_test:end_per_group(). |
| 85 | +end_per_group(_Group, _Config) -> |
| 86 | + ok. |
| 87 | + |
| 88 | +%%%============================================================================= |
| 89 | +%%% Test Cases |
| 90 | +%%%============================================================================= |
| 91 | + |
| 92 | +-spec test_gfm_tagfilter_case_1(Config) -> markdown_test:testcase() when |
| 93 | + Config :: ct_suite:ct_config(). |
| 94 | +test_gfm_tagfilter_case_1(_Config) -> |
| 95 | + ?assertMatch( |
| 96 | + {ok, <<"<iframe>"/utf8>>}, |
| 97 | + markdown:to_html_with_options( |
| 98 | + <<"<iframe>"/utf8>>, markdown_options:default(#{compile => #{allow_dangerous_html => true}}) |
| 99 | + ), |
| 100 | + "should not filter by default" |
| 101 | + ), |
| 102 | + ok. |
| 103 | + |
| 104 | +-spec test_gfm_tagfilter_case_2(Config) -> markdown_test:testcase() when |
| 105 | + Config :: ct_suite:ct_config(). |
| 106 | +test_gfm_tagfilter_case_2(_Config) -> |
| 107 | + ?assertMatch( |
| 108 | + {ok, <<"<p>a <i></p>\n<script>"/utf8>>}, |
| 109 | + markdown:to_html_with_options( |
| 110 | + <<"a <i>\n<script>"/utf8>>, markdown_options:default(#{compile => #{gfm_tagfilter => true}}) |
| 111 | + ), |
| 112 | + "should not turn `allow_dangerous_html` on" |
| 113 | + ), |
| 114 | + ok. |
| 115 | + |
| 116 | +-spec test_gfm_tagfilter_case_3(Config) -> markdown_test:testcase() when |
| 117 | + Config :: ct_suite:ct_config(). |
| 118 | +test_gfm_tagfilter_case_3(_Config) -> |
| 119 | + ?assertMatch( |
| 120 | + {ok, <<"<iframe>"/utf8>>}, |
| 121 | + markdown:to_html_with_options( |
| 122 | + <<"<iframe>"/utf8>>, |
| 123 | + markdown_options:default(#{compile => #{allow_dangerous_html => true, gfm_tagfilter => true}}) |
| 124 | + ), |
| 125 | + "should filter" |
| 126 | + ), |
| 127 | + ok. |
| 128 | + |
| 129 | +-spec test_gfm_tagfilter_case_4(Config) -> markdown_test:testcase() when |
| 130 | + Config :: ct_suite:ct_config(). |
| 131 | +test_gfm_tagfilter_case_4(_Config) -> |
| 132 | + ?assertMatch( |
| 133 | + {ok, <<"<iframe\n>"/utf8>>}, |
| 134 | + markdown:to_html_with_options( |
| 135 | + <<"<iframe\n>"/utf8>>, |
| 136 | + markdown_options:default(#{compile => #{allow_dangerous_html => true, gfm_tagfilter => true}}) |
| 137 | + ), |
| 138 | + "should filter when followed by a line ending (1)" |
| 139 | + ), |
| 140 | + ok. |
| 141 | + |
| 142 | +-spec test_gfm_tagfilter_case_5(Config) -> markdown_test:testcase() when |
| 143 | + Config :: ct_suite:ct_config(). |
| 144 | +test_gfm_tagfilter_case_5(_Config) -> |
| 145 | + ?assertMatch( |
| 146 | + {ok, <<"<div\n>"/utf8>>}, |
| 147 | + markdown:to_html_with_options( |
| 148 | + <<"<div\n>"/utf8>>, |
| 149 | + markdown_options:default(#{compile => #{allow_dangerous_html => true, gfm_tagfilter => true}}) |
| 150 | + ), |
| 151 | + "should filter when followed by a line ending (2)" |
| 152 | + ), |
| 153 | + ok. |
| 154 | + |
| 155 | +-spec test_gfm_tagfilter_case_6(Config) -> markdown_test:testcase() when |
| 156 | + Config :: ct_suite:ct_config(). |
| 157 | +test_gfm_tagfilter_case_6(_Config) -> |
| 158 | + ?assertMatch( |
| 159 | + {ok, <<""" |
| 160 | + <title> |
| 161 | + <div title="<title>"></div> |
| 162 | + <p><span title="<title>"></span></p> |
| 163 | + <div><title></title></div> |
| 164 | + <p><span><title></title></span></p> |
| 165 | + <p><b><textarea></textarea></b></p> |
| 166 | + <p><script/src="#"></p> |
| 167 | + <SCRIPT SRC=http://xss.rocks/xss.js></SCRIPT> |
| 168 | + <IMG SRC="javascript:alert('XSS');"> |
| 169 | + <p><IMG SRC=javascript:alert('XSS')></p> |
| 170 | + <p><IMG SRC=<code>javascript:alert("RSnake says, 'XSS'")</code>></p> |
| 171 | + <p><IMG """><SCRIPT>alert("XSS")</SCRIPT>"></p> |
| 172 | + <p><SCRIPT/XSS SRC="http://xss.rocks/xss.js"></SCRIPT></p> |
| 173 | + <BODY onload!#$%&()*~+-_.,:;?@[/|\]^`=alert("XSS")> |
| 174 | + <p><<SCRIPT>alert("XSS");//<</SCRIPT></p> |
| 175 | + <SCRIPT SRC=http://xss.rocks/xss.js?< B > |
| 176 | +
|
| 177 | + <SCRIPT SRC=//xss.rocks/.j> |
| 178 | +
|
| 179 | + </TITLE><SCRIPT>alert("XSS");</SCRIPT> |
| 180 | + <STYLE>li {list-style-image: url("javascript:alert('XSS')");}</STYLE><UL><LI>XSS</br> |
| 181 | + <p>javascript:/<em>--></title></style></textarea></script></xmp><svg/onload='+/"/+/onmouseover=1/+/[</em>/[]/+alert(1)//'></p> |
| 182 | + <STYLE>@import'http://xss.rocks/xss.css';</STYLE> |
| 183 | +
|
| 184 | + """/utf8>>}, |
| 185 | + markdown:to_html_with_options( |
| 186 | + <<"\n<title>\n\n<div title=\"<title>\"></div>\n\n<span title=\"<title>\"></span>\n\n<div><title></title></div>\n\n<span><title></title></span>\n\n<b><textarea></textarea></b>\n\n<script/src=\"#\">\n\n<SCRIPT SRC=http://xss.rocks/xss.js></SCRIPT>\n\n<IMG SRC=\"javascript:alert('XSS');\">\n\n<IMG SRC=javascript:alert('XSS')>\n\n<IMG SRC=`javascript:alert(\"RSnake says, 'XSS'\")`>\n\n<IMG \"\"\"><SCRIPT>alert(\"XSS\")</SCRIPT>\"\\>\n\n<SCRIPT/XSS SRC=\"http://xss.rocks/xss.js\"></SCRIPT>\n\n<BODY onload!#$%&()*~+-_.,:;?@[/|\\]^`=alert(\"XSS\")>\n\n<<SCRIPT>alert(\"XSS\");//\\<</SCRIPT>\n\n<SCRIPT SRC=http://xss.rocks/xss.js?< B >\n\n<SCRIPT SRC=//xss.rocks/.j>\n\n</TITLE><SCRIPT>alert(\"XSS\");</SCRIPT>\n\n<STYLE>li {list-style-image: url(\"javascript:alert('XSS')\");}</STYLE><UL><LI>XSS</br>\n\njavascript:/*--></title></style></textarea></script></xmp><svg/onload='+/\"/+/onmouseover=1/+/[*/[]/+alert(1)//'>\n\n<STYLE>@import'http://xss.rocks/xss.css';</STYLE>\n"/utf8>>, |
| 187 | + markdown_options:default(#{compile => #{allow_dangerous_html => true, gfm_tagfilter => true}}) |
| 188 | + ), |
| 189 | + "should handle things like GitHub" |
| 190 | + ), |
| 191 | + ok. |
0 commit comments