diff options
author | Ashod Nakashian <ashod.nakashian@collabora.co.uk> | 2019-04-14 12:21:19 -0400 |
---|---|---|
committer | Ashod Nakashian <ashnakash@gmail.com> | 2019-08-17 04:26:35 +0200 |
commit | 919a93cd4b123f3757ce1ae454ed622019d1d02c (patch) | |
tree | 3ef401bec279fde2655aa86b72fd72d4919a3d69 /test/WhiteBoxTests.cpp | |
parent | 226c2fe71c53f4c8e460bf13a30870aaa0ea7581 (diff) |
wsd: improved anonymization algorithm
Better hashing algorithm based on FNV-1a.
Adds support for salting the hash, and
for providing salt via configuration.
More unit-tests added, and better formatting.
Change-Id: I2be42675d0cdbaa73c3d7faed99e07631a9c20fc
Reviewed-on: https://gerrit.libreoffice.org/70034
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
Reviewed-on: https://gerrit.libreoffice.org/71091
Diffstat (limited to 'test/WhiteBoxTests.cpp')
-rw-r--r-- | test/WhiteBoxTests.cpp | 72 |
1 files changed, 52 insertions, 20 deletions
diff --git a/test/WhiteBoxTests.cpp b/test/WhiteBoxTests.cpp index 8c5bdc70c..39aa197e3 100644 --- a/test/WhiteBoxTests.cpp +++ b/test/WhiteBoxTests.cpp @@ -669,35 +669,67 @@ void WhiteBoxTests::testJson() void WhiteBoxTests::testAnonymization() { static const std::string name = "some name with space"; - CPPUNIT_ASSERT_EQUAL(std::string("#0#77d#"), Util::anonymizeUrl(name)); + static const std::string filename = "filename.ext"; + static const std::string filenameTestx = "testx (6).odt"; + static const std::string path = "/path/to/filename.ext"; + static const std::string plainUrl + = "http://localhost/owncloud/index.php/apps/richdocuments/wopi/files/" + "736_ocgdpzbkm39u?access_token=Hn0zttjbwkvGWb5BHbDa5ArgTykJAyBl&access_token_ttl=0&" + "permission=edit"; + static const std::string fileUrl = "http://localhost/owncloud/index.php/apps/richdocuments/" + "wopi/files/736_ocgdpzbkm39u/" + "secret.odt?access_token=Hn0zttjbwkvGWb5BHbDa5ArgTykJAyBl&" + "access_token_ttl=0&permission=edit"; + + std::uint64_t nAnonymizationSalt = 1111111111182589933; + + CPPUNIT_ASSERT_EQUAL(std::string("#0#5e45aef91248a8aa#"), + Util::anonymizeUrl(name, nAnonymizationSalt)); + CPPUNIT_ASSERT_EQUAL(std::string("#1#8f8d95bd2a202d00#.odt"), + Util::anonymizeUrl(filenameTestx, nAnonymizationSalt)); + CPPUNIT_ASSERT_EQUAL(std::string("/path/to/#2#5c872b2d82ecc8a0#.ext"), + Util::anonymizeUrl(path, nAnonymizationSalt)); + CPPUNIT_ASSERT_EQUAL( + std::string("http://localhost/owncloud/index.php/apps/richdocuments/wopi/files/" + "#3#22c6f0caad277666#?access_token=Hn0zttjbwkvGWb5BHbDa5ArgTykJAyBl&access_" + "token_ttl=0&permission=edit"), + Util::anonymizeUrl(plainUrl, nAnonymizationSalt)); + CPPUNIT_ASSERT_EQUAL( + std::string("http://localhost/owncloud/index.php/apps/richdocuments/wopi/files/" + "736_ocgdpzbkm39u/" + "#4#294f0dfb18f6a80b#.odt?access_token=Hn0zttjbwkvGWb5BHbDa5ArgTykJAyBl&access_" + "token_ttl=0&permission=edit"), + Util::anonymizeUrl(fileUrl, nAnonymizationSalt)); + + nAnonymizationSalt = 0; + + CPPUNIT_ASSERT_EQUAL(std::string("#0#5e45aef91248a8aa#"), Util::anonymizeUrl(name, nAnonymizationSalt)); Util::mapAnonymized(name, name); - CPPUNIT_ASSERT_EQUAL(name, Util::anonymizeUrl(name)); + CPPUNIT_ASSERT_EQUAL(name, Util::anonymizeUrl(name, nAnonymizationSalt)); - static const std::string filename = "filename.ext"; - CPPUNIT_ASSERT_EQUAL(std::string("#1#341#.ext"), Util::anonymizeUrl(filename)); - Util::mapAnonymized("filename", "filename"); - CPPUNIT_ASSERT_EQUAL(name, Util::anonymizeUrl(name)); + CPPUNIT_ASSERT_EQUAL(std::string("#2#5c872b2d82ecc8a0#.ext"), + Util::anonymizeUrl(filename, nAnonymizationSalt)); + Util::mapAnonymized("filename", "filename"); // Identity map of the filename without extension. + CPPUNIT_ASSERT_EQUAL(filename, Util::anonymizeUrl(filename, nAnonymizationSalt)); - static const std::string filenameTestx = "testx (6).odt"; - CPPUNIT_ASSERT_EQUAL(std::string("#2#2df#.odt"), Util::anonymizeUrl(filenameTestx)); - Util::mapAnonymized("testx (6)", "testx (6)"); - CPPUNIT_ASSERT_EQUAL(filenameTestx, Util::anonymizeUrl(filenameTestx)); + CPPUNIT_ASSERT_EQUAL(std::string("#1#8f8d95bd2a202d00#.odt"), + Util::anonymizeUrl(filenameTestx, nAnonymizationSalt)); + Util::mapAnonymized("testx (6)", + "testx (6)"); // Identity map of the filename without extension. + CPPUNIT_ASSERT_EQUAL(filenameTestx, Util::anonymizeUrl(filenameTestx, nAnonymizationSalt)); - static const std::string path = "/path/to/filename.ext"; - CPPUNIT_ASSERT_EQUAL(path, Util::anonymizeUrl(path)); + CPPUNIT_ASSERT_EQUAL(path, Util::anonymizeUrl(path, nAnonymizationSalt)); - static const std::string plainUrl = "http://localhost/owncloud/index.php/apps/richdocuments/wopi/files/736_ocgdpzbkm39u?access_token=Hn0zttjbwkvGWb5BHbDa5ArgTykJAyBl&access_token_ttl=0&permission=edit"; - const std::string urlAnonymized = Util::replace(plainUrl, "736_ocgdpzbkm39u", "#3#5a1#"); - CPPUNIT_ASSERT_EQUAL(urlAnonymized, Util::anonymizeUrl(plainUrl)); + const std::string urlAnonymized = Util::replace(plainUrl, "736_ocgdpzbkm39u", "#3#22c6f0caad277666#"); + CPPUNIT_ASSERT_EQUAL(urlAnonymized, Util::anonymizeUrl(plainUrl, nAnonymizationSalt)); Util::mapAnonymized("736_ocgdpzbkm39u", "736_ocgdpzbkm39u"); - CPPUNIT_ASSERT_EQUAL(plainUrl, Util::anonymizeUrl(plainUrl)); + CPPUNIT_ASSERT_EQUAL(plainUrl, Util::anonymizeUrl(plainUrl, nAnonymizationSalt)); - static const std::string fileUrl = "http://localhost/owncloud/index.php/apps/richdocuments/wopi/files/736_ocgdpzbkm39u/secret.odt?access_token=Hn0zttjbwkvGWb5BHbDa5ArgTykJAyBl&access_token_ttl=0&permission=edit"; - const std::string urlAnonymized2 = Util::replace(fileUrl, "secret", "#4#286#"); - CPPUNIT_ASSERT_EQUAL(urlAnonymized2, Util::anonymizeUrl(fileUrl)); + const std::string urlAnonymized2 = Util::replace(fileUrl, "secret", "#4#294f0dfb18f6a80b#"); + CPPUNIT_ASSERT_EQUAL(urlAnonymized2, Util::anonymizeUrl(fileUrl, nAnonymizationSalt)); Util::mapAnonymized("secret", "736_ocgdpzbkm39u"); const std::string urlAnonymized3 = Util::replace(fileUrl, "secret", "736_ocgdpzbkm39u"); - CPPUNIT_ASSERT_EQUAL(urlAnonymized3, Util::anonymizeUrl(fileUrl)); + CPPUNIT_ASSERT_EQUAL(urlAnonymized3, Util::anonymizeUrl(fileUrl, nAnonymizationSalt)); } CPPUNIT_TEST_SUITE_REGISTRATION(WhiteBoxTests); |