#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "components/feedback/redaction_tool/redaction_tool.h"
#include <gtest/gtest.h>
#include <set>
#include <string_view>
#include <utility>
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/location.h"
#include "base/path_service.h"
#include "base/strings/string_util.h"
#include "build/chromeos_buildflags.h"
#include "components/feedback/redaction_tool/metrics_tester.h"
#include "components/feedback/redaction_tool/pii_types.h"
namespace redaction {
const char kFakeFirstPartyID[] = …;
const char* const kFakeFirstPartyExtensionIDs[] = …;
struct StringWithRedaction { … };
const StringWithRedaction kStringsWithRedactions[] = …;
class RedactionToolTest : public testing::Test { … };
TEST_F(RedactionToolTest, Redact) { … }
TEST_F(RedactionToolTest, RedactMACAddresses) { … }
TEST_F(RedactionToolTest, RedactHashes) { … }
TEST_F(RedactionToolTest, RedactCustomPatterns) { … }
TEST_F(RedactionToolTest, RedactCustomPatternWithContext) { … }
TEST_F(RedactionToolTest, RedactCustomPatternWithoutContext) { … }
TEST_F(RedactionToolTest, RedactChunk) { … }
TEST_F(RedactionToolTest, RedactAndKeepSelected) { … }
TEST_F(RedactionToolTest, RedactUid) { … }
TEST_F(RedactionToolTest, RedactAndKeepSelectedHashes) { … }
TEST_F(RedactionToolTest, DetectPII) { … }
#if BUILDFLAG(IS_CHROMEOS_ASH)
TEST_F(RedactionToolTest, RedactAndroidAppStoragePaths) {
EXPECT_EQ("", RedactAndroidAppStoragePaths(""));
EXPECT_EQ("foo\nbar\n", RedactAndroidAppStoragePaths("foo\nbar\n"));
constexpr char kDuOutput[] =
"112K\t/home/root/deadbeef1234/android-data/data/system_de\n"
"8.0K\t/home/root/deadbeef1234/android-data/data/data/pack.age1/a\n"
"8.0K\t/home/root/deadbeef1234/android-data/data/data/pack.age1/bc\n"
"24K\t/home/root/deadbeef1234/android-data/data/data/pack.age1\n"
"8.0K\t/home/root/deadbeef1234/android-data/data/data/pa.ckage2/de\n"
"8.0K\t/home/root/deadbeef1234/android-data/data/data/pa.ckage2/de/"
"\xe3\x81\x82\n"
"8.1K\t/home/root/deadbeef1234/android-data/data/data/pa.ckage2/de/"
"\xe3\x81\x82\xe3\x81\x83\n"
"8.0K\t/home/root/deadbeef1234/android-data/data/data/pa.ckage2/ef\n"
"24K\t/home/root/deadbeef1234/android-data/data/data/pa.ckage2\n"
"8.0K\t/home/root/deadbeef1234/android-data/data/app/pack.age1/a\n"
"8.0K\t/home/root/deadbeef1234/android-data/data/app/pack.age1/bc\n"
"24K\t/home/root/deadbeef1234/android-data/data/app/pack.age1\n"
"8.0K\t/home/root/deadbeef1234/android-data/data/user_de/0/pack.age1/a\n"
"8.0K\t/home/root/deadbeef1234/android-data/data/user_de/0/pack.age1/bc\n"
"24K\t/home/root/deadbeef1234/android-data/data/user_de/0/pack.age1\n"
"78M\t/home/root/deadbeef1234/android-data/data/data\n"
"key=value path=/data/data/pack.age1/bc key=value\n"
"key=value path=/data/user_de/0/pack.age1/bc key=value\n"
"key=value exe=/data/app/pack.age1/bc key=value\n";
constexpr char kDuOutputRedacted[] =
"112K\t/home/root/deadbeef1234/android-data/data/system_de\n"
"8.0K\t/home/root/deadbeef1234/android-data/data/data/pack.age1/a\n"
"8.0K\t/home/root/deadbeef1234/android-data/data/data/pack.age1/b_\n"
"24K\t/home/root/deadbeef1234/android-data/data/data/pack.age1\n"
"8.0K\t/home/root/deadbeef1234/android-data/data/data/pa.ckage2/d_\n"
"8.0K\t/home/root/deadbeef1234/android-data/data/data/pa.ckage2/d_/*_\n"
"8.1K\t/home/root/deadbeef1234/android-data/data/data/pa.ckage2/d_/*_\n"
"8.0K\t/home/root/deadbeef1234/android-data/data/data/pa.ckage2/e_\n"
"24K\t/home/root/deadbeef1234/android-data/data/data/pa.ckage2\n"
"8.0K\t/home/root/deadbeef1234/android-data/data/app/pack.age1/a\n"
"8.0K\t/home/root/deadbeef1234/android-data/data/app/pack.age1/b_\n"
"24K\t/home/root/deadbeef1234/android-data/data/app/pack.age1\n"
"8.0K\t/home/root/deadbeef1234/android-data/data/user_de/0/pack.age1/a\n"
"8.0K\t/home/root/deadbeef1234/android-data/data/user_de/0/pack.age1/b_\n"
"24K\t/home/root/deadbeef1234/android-data/data/user_de/0/pack.age1\n"
"78M\t/home/root/deadbeef1234/android-data/data/data\n"
"key=value path=/data/data/pack.age1/b_ key=value\n"
"key=value path=/data/user_de/0/pack.age1/b_ key=value\n"
"key=value exe=/data/app/pack.age1/b_ key=value\n";
EXPECT_EQ(kDuOutputRedacted, RedactAndroidAppStoragePaths(kDuOutput));
}
#endif
#if !BUILDFLAG(IS_IOS)
TEST_F(RedactionToolTest, RedactTextFileContent) { … }
#endif
TEST_F(RedactionToolTest, RedactBlockDevices) { … }
}