Implement percent url encoder and decoder
[libi2ncommon] / test / test_restricted_html.cpp
CommitLineData
09ca2cbf
JR
1/*
2The software in this package is distributed under the GNU General
3Public License version 2 (with a special exception described below).
4
5A copy of GNU General Public License (GPL) is included in this distribution,
6in the file COPYING.GPL.
7
8As a special exception, if other files instantiate templates or use macros
9or inline functions from this file, or you compile this file and link it
10with other works to produce a work based on this file, this file
11does not by itself cause the resulting work to be covered
12by the GNU General Public License.
13
14However the source code for this file must still be made available
15in accordance with section (3) of the GNU General Public License.
16
17This exception does not invalidate any other reasons why a work based
18on this file might be covered by the GNU General Public License.
19*/
20/** @file
21 * @brief unit test for the restricted html functions.
22 *
23 * @copyright © Copyright 2017 Intra2net AG
24 *
25 */
26#define BOOST_TEST_DYN_LINK
27#include <boost/test/unit_test.hpp>
28
29#include <restricted_html.hpp>
30
31using namespace std;
32using namespace I2n;
33
34BOOST_AUTO_TEST_SUITE(test_restricted_html)
35
36
a93685ca
JR
37BOOST_AUTO_TEST_CASE(DecodeStringURL)
38{
39 string output = decode_url("%77%77%77%2E%67%6F%6F%67%6C%65%2E%63%6F%6D");
40 BOOST_CHECK_EQUAL(string("www.google.com"), output);
41}
42
43BOOST_AUTO_TEST_CASE(DecodeStringURL2)
44{
45 string output = decode_url("%3Cscript%3Ealert%28document.cookie%29%3C%2Fscr"
46 "ipt%3E");
47 BOOST_CHECK_EQUAL(string("<script>alert(document.cookie)</script>"), output);
48}
49
50BOOST_AUTO_TEST_CASE(EncodeStringURL)
51{
52 string output = encode_url("http://www.domain.com/params?param=b'ar:!~/");
53 BOOST_CHECK_EQUAL(string("http%3A%2F%2Fwww%2Edomain%2Ecom%2Fparams%3Fparam%"
54 "3Db%27ar%3A%21%7E%2F"), output);
55}
56
57BOOST_AUTO_TEST_CASE(EncodeStringURL2)
58{
59 string output = encode_url("http://www.google.com/<script>");
60 BOOST_CHECK_EQUAL(string("http%3A%2F%2Fwww%2Egoogle%2Ecom%2F%3Cscript%3E"),
61 output);
62}
63
09ca2cbf 64BOOST_AUTO_TEST_SUITE_END()