summaryrefslogtreecommitdiffstats
path: root/test/test_text_anonymizer.cc
blob: 162111fd4ad80c3550908a27d6bd7576b3ef74dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/**
 * Copyright (c) 2022, Timothy Stack
 *
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * * Redistributions of source code must retain the above copyright notice, this
 * list of conditions and the following disclaimer.
 * * Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the following disclaimer in the documentation
 * and/or other materials provided with the distribution.
 * * Neither the name of Timothy Stack nor the names of its contributors
 * may be used to endorse or promote products derived from this software
 * without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ''AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include "config.h"

#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "doctest/doctest.h"
#include "text_anonymizer.hh"

TEST_CASE("ipv4")
{
    lnav::text_anonymizer ta;

    CHECK(ta.next(string_fragment::from_const("127.0.1.1 says hi"))
          == "10.0.0.1 says hi");
    CHECK(ta.next(string_fragment::from_const("127.0.1.1 says hi"))
          == "10.0.0.1 says hi");
    CHECK(ta.next(string_fragment::from_const("u'127.0.1.1' says hi"))
          == "u'10.0.0.1' says hi");
}

TEST_CASE("ipv6")
{
    lnav::text_anonymizer ta;

    CHECK(ta.next(
              string_fragment::from_const("fe80::1887:2f2d:bc2e:8e41 says hi"))
          == "2001:db8::1 says hi");
}

TEST_CASE("url")
{
    lnav::text_anonymizer ta;

    CHECK(ta.next(string_fragment::from_const("retrieving https://bob:abc@example.com/fooooooo22/192.168.1.33/barrrrr44?abcdef=foobar&ghijkl=123456&bazzer&ip=192.168.1.2#heading-2")) ==
          "aback https://meerkat:67c93775f715ab8ab01178caf86713c6@achondroplasia.example.com/abaft22/10.0.0.1/abashed44?aberrant=abhorrent&abiding=123456&abject&ip=10.0.0.2#able-2");
}

TEST_CASE("email")
{
    lnav::text_anonymizer ta;

    CHECK(ta.next(string_fragment::from_const("hello support@lnav.org"))
          == "aback meerkat@achondroplasia.example.com");
}

TEST_CASE("symbol")
{
    lnav::text_anonymizer ta;

    CHECK(ta.next(string_fragment::from_const(
              "state is Constants.DOWNLOAD_STARTED"))
          == "aback is Abandoned.ABASHED_ABERRANT");
}

TEST_CASE("date")
{
    lnav::text_anonymizer ta;

    CHECK(ta.next(string_fragment::from_const("2022-06-02T12:26:22.072Z"))
          == "2022-06-02T12:26:22.072Z");
}

TEST_CASE("uuid")
{
    lnav::text_anonymizer ta;

    CHECK(ta.next(string_fragment::from_const(
              "52556d7e-c34d-d7f9-73b6-f52ad939952e"))
          == "bc8b6954-c2a4-e7f3-0e18-2fa4035db1c9");
}

TEST_CASE("MAC-address")
{
    lnav::text_anonymizer ta;

    CHECK(ta.next(string_fragment::from_const("ether f2:09:1a:a2:e3:e2"))
          == "aback 00:00:5e:00:53:00");
}

TEST_CASE("hex-dump")
{
    lnav::text_anonymizer ta;

    CHECK(ta.next(string_fragment::from_const("key f2:09:1a:a2"))
          == "key 68:48:d3:93");
}

TEST_CASE("cc")
{
    lnav::text_anonymizer ta;

    CHECK(ta.next(string_fragment::from_const("cc 6011 1111 1111 1117"))
          == "cc 1a49 c794 31d9 3eb2");
    CHECK(ta.next(string_fragment::from_const("cc 6011111111111117"))
          == "cc 1a49c79431d93eb2");
}

TEST_CASE("xml")
{
    lnav::text_anonymizer ta;

    CHECK(ta.next(string_fragment::from_const("<o:gupdate xmlns:o=\"http://www.google.com/update2/request\" protocol=\"2.0\" version=\"KeystoneDaemon-1.2.0.7709\" ismachine=\"1\" requestid=\"{0DFDBCD1-5E29-4DFC-BD99-31A2397198FE}\">")) ==
          "<o:gupdate  xmlns:o=\"http://achondroplasia.example.com/aback2/abandoned\" protocol=\"2.0\" version=\"Abashed-1.2.0.7709\" ismachine=\"1\" requestid=\"{1ca0a968-cbe9-e75b-d00b-4859609878ea}\">");
}