From ddaf36c6420a1182cab7dcd1d089c35560855f58 Mon Sep 17 00:00:00 2001 From: Alexander Borsuk Date: Tue, 21 Jun 2022 09:35:30 +0200 Subject: [PATCH 01/12] Fixed OSM auth tests Signed-off-by: Alexander Borsuk --- editor/osm_auth.cpp | 4 ++-- editor/osm_auth_tests/osm_auth_tests.cpp | 2 +- editor/osm_auth_tests/server_api_test.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/editor/osm_auth.cpp b/editor/osm_auth.cpp index f81d0df92d..ab5ac002ac 100644 --- a/editor/osm_auth.cpp +++ b/editor/osm_auth.cpp @@ -92,8 +92,8 @@ OsmOAuth OsmOAuth::ServerAuth(KeySecret const & userKeySecret) OsmOAuth OsmOAuth::DevServerAuth() { constexpr char const * kOsmDevServer = "https://master.apis.dev.openstreetmap.org"; - constexpr char const * kOsmDevConsumerKey = "eRtN6yKZZf34oVyBnyaVbsWtHIIeptLArQKdTwN3"; - constexpr char const * kOsmDevConsumerSecret = "lC124mtm2VqvKJjSh35qBpKfrkeIjpKuGe38Hd1H"; + constexpr char const * kOsmDevConsumerKey = "jOxkndim5PiuIlgsYxUH8H0broKt5qJM2enN5vF5"; + constexpr char const * kOsmDevConsumerSecret = "g3jTJz6CUws3c04MHdAhbUTmnNH16ls8XxurQEIc"; return OsmOAuth(kOsmDevConsumerKey, kOsmDevConsumerSecret, kOsmDevServer, kOsmDevServer); } // static diff --git a/editor/osm_auth_tests/osm_auth_tests.cpp b/editor/osm_auth_tests/osm_auth_tests.cpp index 3bbe35a6e3..2714a1a9b1 100644 --- a/editor/osm_auth_tests/osm_auth_tests.cpp +++ b/editor/osm_auth_tests/osm_auth_tests.cpp @@ -12,7 +12,7 @@ char const * kValidOsmPassword = "12345678"; namespace { constexpr char const * kInvalidOsmPassword = "123"; -constexpr char const * kForgotPasswordEmail = "osmtest@organicmaps.app"; +constexpr char const * kForgotPasswordEmail = "osmtest1@organicmaps.app"; } // namespace UNIT_TEST(OSM_Auth_InvalidLogin) diff --git a/editor/osm_auth_tests/server_api_test.cpp b/editor/osm_auth_tests/server_api_test.cpp index 902f6d3ba4..bd5b1f2bf5 100644 --- a/editor/osm_auth_tests/server_api_test.cpp +++ b/editor/osm_auth_tests/server_api_test.cpp @@ -41,7 +41,7 @@ ServerApi06 CreateAPI() osm::UserPreferences prefs; TEST_NO_THROW(prefs = api.GetUserPreferences(), ()); TEST_EQUAL(prefs.m_displayName, kValidOsmUser, ("User display name")); - TEST_EQUAL(prefs.m_id, 11600, ("User id")); + TEST_EQUAL(prefs.m_id, 14235, ("User id")); return api; } -- 2.45.3 From 09a17d20a76eb6de99b98ed275a547a05eeac6b4 Mon Sep 17 00:00:00 2001 From: "S. Kozyr" Date: Tue, 21 Jun 2022 11:13:07 +0300 Subject: [PATCH 02/12] Changed facebook nickname validation regex. Updated unittests Signed-off-by: S. Kozyr --- indexer/indexer_tests/validate_and_format_contacts_test.cpp | 3 ++- indexer/validate_and_format_contacts.cpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/indexer/indexer_tests/validate_and_format_contacts_test.cpp b/indexer/indexer_tests/validate_and_format_contacts_test.cpp index d26b6383c0..2ab849ee79 100644 --- a/indexer/indexer_tests/validate_and_format_contacts_test.cpp +++ b/indexer/indexer_tests/validate_and_format_contacts_test.cpp @@ -17,13 +17,14 @@ UNIT_TEST(EditableMapObject_ValidateFacebookPage) TEST(osm::ValidateFacebookPage("OpenStreetMap"), ()); TEST(osm::ValidateFacebookPage("some.good.page"), ()); TEST(osm::ValidateFacebookPage("Quaama-Volunteer-Bushfire-Brigade-526790054021506"), ()); + TEST(osm::ValidateFacebookPage("P\xE1ter-Bonif\xE1""c-Restaurant-Budapest-111001693867133"), ()); TEST(osm::ValidateFacebookPage("@tree-house-interiors"), ()); + TEST(osm::ValidateFacebookPage("allow_underscore-1234567890"), ()); TEST(osm::ValidateFacebookPage("alexander.net"), ()); TEST(!osm::ValidateFacebookPage("instagram.com/openstreetmapus"), ()); TEST(!osm::ValidateFacebookPage("https://instagram.com/openstreetmapus"), ()); TEST(!osm::ValidateFacebookPage("osm"), ()); - TEST(!osm::ValidateFacebookPage("invalid_username"), ()); } UNIT_TEST(EditableMapObject_ValidateInstagramPage) diff --git a/indexer/validate_and_format_contacts.cpp b/indexer/validate_and_format_contacts.cpp index 0b4a3d2adf..a73b6d5ae2 100644 --- a/indexer/validate_and_format_contacts.cpp +++ b/indexer/validate_and_format_contacts.cpp @@ -10,7 +10,7 @@ using namespace std; namespace osm { -static auto const s_fbRegex = regex(R"(^@?[a-zA-Z\d.\-]{5,}$)"); +static auto const s_fbRegex = regex(R"(^@?[a-zA-Z\xE1\d.\-_]{5,}$)"); static auto const s_instaRegex = regex(R"(^@?[A-Za-z0-9_][A-Za-z0-9_.]{0,28}[A-Za-z0-9_]$)"); static auto const s_twitterRegex = regex(R"(^@?[A-Za-z0-9_]{1,15}$)"); static auto const s_badVkRegex = regex(R"(^\d\d\d.+$)"); -- 2.45.3 From 81e7970e84bdde58e80aecdfe0e6df681a6fc148 Mon Sep 17 00:00:00 2001 From: "S. Kozyr" Date: Tue, 21 Jun 2022 13:19:38 +0300 Subject: [PATCH 03/12] Added test with unicode character received from JNI Signed-off-by: S. Kozyr --- indexer/indexer_tests/validate_and_format_contacts_test.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/indexer/indexer_tests/validate_and_format_contacts_test.cpp b/indexer/indexer_tests/validate_and_format_contacts_test.cpp index 2ab849ee79..25aa6f9863 100644 --- a/indexer/indexer_tests/validate_and_format_contacts_test.cpp +++ b/indexer/indexer_tests/validate_and_format_contacts_test.cpp @@ -18,6 +18,7 @@ UNIT_TEST(EditableMapObject_ValidateFacebookPage) TEST(osm::ValidateFacebookPage("some.good.page"), ()); TEST(osm::ValidateFacebookPage("Quaama-Volunteer-Bushfire-Brigade-526790054021506"), ()); TEST(osm::ValidateFacebookPage("P\xE1ter-Bonif\xE1""c-Restaurant-Budapest-111001693867133"), ()); + TEST(osm::ValidateFacebookPage("P\xc3\xa1ter-Bonif\xc3\xa1""c-Restaurant-Budapest-111001693867133"), ()); TEST(osm::ValidateFacebookPage("@tree-house-interiors"), ()); TEST(osm::ValidateFacebookPage("allow_underscore-1234567890"), ()); TEST(osm::ValidateFacebookPage("alexander.net"), ()); -- 2.45.3 From ef9d748d7bb3cb74d98dec1bf6ae9b2735ca89c9 Mon Sep 17 00:00:00 2001 From: "S. Kozyr" Date: Mon, 27 Jun 2022 12:18:56 +0300 Subject: [PATCH 04/12] Replaced Facebook validation regexp with the list of forbidden symbols. Updated tests. Signed-off-by: S. Kozyr --- .../validate_and_format_contacts_test.cpp | 10 ++++- indexer/validate_and_format_contacts.cpp | 37 ++++++++++++++----- 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/indexer/indexer_tests/validate_and_format_contacts_test.cpp b/indexer/indexer_tests/validate_and_format_contacts_test.cpp index 25aa6f9863..7a1ac44791 100644 --- a/indexer/indexer_tests/validate_and_format_contacts_test.cpp +++ b/indexer/indexer_tests/validate_and_format_contacts_test.cpp @@ -17,8 +17,11 @@ UNIT_TEST(EditableMapObject_ValidateFacebookPage) TEST(osm::ValidateFacebookPage("OpenStreetMap"), ()); TEST(osm::ValidateFacebookPage("some.good.page"), ()); TEST(osm::ValidateFacebookPage("Quaama-Volunteer-Bushfire-Brigade-526790054021506"), ()); - TEST(osm::ValidateFacebookPage("P\xE1ter-Bonif\xE1""c-Restaurant-Budapest-111001693867133"), ()); TEST(osm::ValidateFacebookPage("P\xc3\xa1ter-Bonif\xc3\xa1""c-Restaurant-Budapest-111001693867133"), ()); + TEST(osm::ValidateFacebookPage("M\xc3\x8aG\xc3\x85--C\xc3\x84""F\xc3\x8b-3141592653589793"), ()); + TEST(osm::ValidateFacebookPage("\xd0\xb0\xd0\xb0\xd0\xb1\xd0\xb1\xd0\xb2\xd0\xb2"), ()); // Cyrillic + TEST(osm::ValidateFacebookPage("\xe1\x83\xa1\xe1\x83\x90\xe1\x83\xa5\xe1\x83\x90\xe1\x83\xa0\xe1\x83\x97\xe1\x83\x95\xe1\x83\x94\xe1\x83\x9a\xe1\x83\x9d"), ()); // Georgian + TEST(osm::ValidateFacebookPage("\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e"), ()); // Japanese TEST(osm::ValidateFacebookPage("@tree-house-interiors"), ()); TEST(osm::ValidateFacebookPage("allow_underscore-1234567890"), ()); TEST(osm::ValidateFacebookPage("alexander.net"), ()); @@ -26,6 +29,11 @@ UNIT_TEST(EditableMapObject_ValidateFacebookPage) TEST(!osm::ValidateFacebookPage("instagram.com/openstreetmapus"), ()); TEST(!osm::ValidateFacebookPage("https://instagram.com/openstreetmapus"), ()); TEST(!osm::ValidateFacebookPage("osm"), ()); + TEST(!osm::ValidateFacebookPage("@spaces are not welcome here"), ()); + TEST(!osm::ValidateFacebookPage("spaces are not welcome here"), ()); + + // Symbols "£¤¥" are not allowed, but to check such cases it requires unicode magic. Not supported currently + //TEST(!osm::ValidateFacebookPage("you-shall-not-pass-\xc2\xa3\xc2\xa4\xc2\xa5"), ()); } UNIT_TEST(EditableMapObject_ValidateInstagramPage) diff --git a/indexer/validate_and_format_contacts.cpp b/indexer/validate_and_format_contacts.cpp index a73b6d5ae2..f4e2587288 100644 --- a/indexer/validate_and_format_contacts.cpp +++ b/indexer/validate_and_format_contacts.cpp @@ -10,26 +10,40 @@ using namespace std; namespace osm { -static auto const s_fbRegex = regex(R"(^@?[a-zA-Z\xE1\d.\-_]{5,}$)"); +static string const s_forbiddenFBSymbols = " !@^*()~@[]{}#$%&;,:+\"'/\\"; static auto const s_instaRegex = regex(R"(^@?[A-Za-z0-9_][A-Za-z0-9_.]{0,28}[A-Za-z0-9_]$)"); static auto const s_twitterRegex = regex(R"(^@?[A-Za-z0-9_]{1,15}$)"); static auto const s_badVkRegex = regex(R"(^\d\d\d.+$)"); static auto const s_goodVkRegex = regex(R"(^[A-Za-z0-9_.]{5,32}$)"); static auto const s_lineRegex = regex(R"(^[a-z0-9-_.]{4,20}$)"); +bool hasIntersections(string txtA, string txtB) { + auto txtASize = txtA.length(); + for(size_t i=0; i= 6 && !hasIntersections(page.substr(1), s_forbiddenFBSymbols); + else if (page.length() >= 5 && !hasIntersections(page, s_forbiddenFBSymbols)) return true; if (!EditableMapObject::ValidateWebsite(page)) -- 2.45.3 From f044b181d039a01076fe91eea504dd588ee2dc34 Mon Sep 17 00:00:00 2001 From: "S. Kozyr" Date: Tue, 28 Jun 2022 21:36:55 +0300 Subject: [PATCH 05/12] Simplified Facebook validation. Updated tests. Signed-off-by: S. Kozyr --- .../validate_and_format_contacts_test.cpp | 15 +++++++----- indexer/validate_and_format_contacts.cpp | 23 +++++++------------ 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/indexer/indexer_tests/validate_and_format_contacts_test.cpp b/indexer/indexer_tests/validate_and_format_contacts_test.cpp index 7a1ac44791..1698d35ab0 100644 --- a/indexer/indexer_tests/validate_and_format_contacts_test.cpp +++ b/indexer/indexer_tests/validate_and_format_contacts_test.cpp @@ -17,11 +17,11 @@ UNIT_TEST(EditableMapObject_ValidateFacebookPage) TEST(osm::ValidateFacebookPage("OpenStreetMap"), ()); TEST(osm::ValidateFacebookPage("some.good.page"), ()); TEST(osm::ValidateFacebookPage("Quaama-Volunteer-Bushfire-Brigade-526790054021506"), ()); - TEST(osm::ValidateFacebookPage("P\xc3\xa1ter-Bonif\xc3\xa1""c-Restaurant-Budapest-111001693867133"), ()); - TEST(osm::ValidateFacebookPage("M\xc3\x8aG\xc3\x85--C\xc3\x84""F\xc3\x8b-3141592653589793"), ()); - TEST(osm::ValidateFacebookPage("\xd0\xb0\xd0\xb0\xd0\xb1\xd0\xb1\xd0\xb2\xd0\xb2"), ()); // Cyrillic - TEST(osm::ValidateFacebookPage("\xe1\x83\xa1\xe1\x83\x90\xe1\x83\xa5\xe1\x83\x90\xe1\x83\xa0\xe1\x83\x97\xe1\x83\x95\xe1\x83\x94\xe1\x83\x9a\xe1\x83\x9d"), ()); // Georgian - TEST(osm::ValidateFacebookPage("\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e"), ()); // Japanese + TEST(osm::ValidateFacebookPage(u8"Páter-Bonifác-Restaurant-Budapest-111001693867133"), ()); + TEST(osm::ValidateFacebookPage(u8"MÊGÅ--CÄFË-3141592653589793"), ()); + TEST(osm::ValidateFacebookPage(u8"ресторан"), ()); // Cyrillic + TEST(osm::ValidateFacebookPage(u8"საქართველო"), ()); // Georgian + TEST(osm::ValidateFacebookPage(u8"日本語"), ()); // Japanese TEST(osm::ValidateFacebookPage("@tree-house-interiors"), ()); TEST(osm::ValidateFacebookPage("allow_underscore-1234567890"), ()); TEST(osm::ValidateFacebookPage("alexander.net"), ()); @@ -31,9 +31,12 @@ UNIT_TEST(EditableMapObject_ValidateFacebookPage) TEST(!osm::ValidateFacebookPage("osm"), ()); TEST(!osm::ValidateFacebookPage("@spaces are not welcome here"), ()); TEST(!osm::ValidateFacebookPage("spaces are not welcome here"), ()); + TEST(!osm::ValidateFacebookPage("slash/is_wrong"), ()); + TEST(!osm::ValidateFacebookPage("special-symbols@forbidden"), ()); + TEST(!osm::ValidateFacebookPage("special#symbols-forbidden"), ()); // Symbols "£¤¥" are not allowed, but to check such cases it requires unicode magic. Not supported currently - //TEST(!osm::ValidateFacebookPage("you-shall-not-pass-\xc2\xa3\xc2\xa4\xc2\xa5"), ()); + //TEST(!osm::ValidateFacebookPage(u8"you-shall-not-pass-£€¥"), ()); } UNIT_TEST(EditableMapObject_ValidateInstagramPage) diff --git a/indexer/validate_and_format_contacts.cpp b/indexer/validate_and_format_contacts.cpp index f4e2587288..c710c7ffc7 100644 --- a/indexer/validate_and_format_contacts.cpp +++ b/indexer/validate_and_format_contacts.cpp @@ -10,22 +10,13 @@ using namespace std; namespace osm { -static string const s_forbiddenFBSymbols = " !@^*()~@[]{}#$%&;,:+\"'/\\"; +constexpr char kForbiddenFBSymbols[] = " !@^*()~[]{}#$%&;,:+\"'/\\"; static auto const s_instaRegex = regex(R"(^@?[A-Za-z0-9_][A-Za-z0-9_.]{0,28}[A-Za-z0-9_]$)"); static auto const s_twitterRegex = regex(R"(^@?[A-Za-z0-9_]{1,15}$)"); static auto const s_badVkRegex = regex(R"(^\d\d\d.+$)"); static auto const s_goodVkRegex = regex(R"(^[A-Za-z0-9_.]{5,32}$)"); static auto const s_lineRegex = regex(R"(^[a-z0-9-_.]{4,20}$)"); -bool hasIntersections(string txtA, string txtB) { - auto txtASize = txtA.length(); - for(size_t i=0; i= 5 + // * no forbidden symbols in the string + // * optional '@' at the start if (page.front() == '@') - return page.length() >= 6 && !hasIntersections(page.substr(1), s_forbiddenFBSymbols); - else if (page.length() >= 5 && !hasIntersections(page, s_forbiddenFBSymbols)) + return page.length() >= 6 && page.substr(1).find_first_of(kForbiddenFBSymbols) == string::npos; + else if (page.length() >= 5 && page.find_first_of(kForbiddenFBSymbols) == string::npos) return true; if (!EditableMapObject::ValidateWebsite(page)) -- 2.45.3 From 70e16395110f32e15d19bc2f3aa97bab1969ae06 Mon Sep 17 00:00:00 2001 From: "S. Kozyr" Date: Wed, 29 Jun 2022 15:20:56 +0300 Subject: [PATCH 06/12] Formatting Signed-off-by: S. Kozyr --- indexer/validate_and_format_contacts.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/indexer/validate_and_format_contacts.cpp b/indexer/validate_and_format_contacts.cpp index c710c7ffc7..9a10e9ca43 100644 --- a/indexer/validate_and_format_contacts.cpp +++ b/indexer/validate_and_format_contacts.cpp @@ -22,19 +22,21 @@ string ValidateAndFormat_facebook(string const & facebookPage) if (facebookPage.empty()) return {}; - if (facebookPage.front() == '@') { - // Validate facebookPage as username or page name - if (facebookPage.substr(1).find_first_of(kForbiddenFBSymbols) == string::npos) + if (facebookPage.front() == '@') + { + // Validate facebookPage as username or page name. + if (facebookPage.find_first_of(kForbiddenFBSymbols, 1) == string::npos) return facebookPage.substr(1); else - return {}; // Invalid symbol in Facebook username of page name + return {}; // Invalid symbol in Facebook username of page name. } - else { + else + { if (facebookPage.find_first_of(kForbiddenFBSymbols) == string::npos) return facebookPage; } - // facebookPage is not a valid username it must be an URL + // facebookPage is not a valid username it must be an URL. if (!EditableMapObject::ValidateWebsite(facebookPage)) return {}; @@ -240,7 +242,7 @@ bool ValidateFacebookPage(string const & page) // * no forbidden symbols in the string // * optional '@' at the start if (page.front() == '@') - return page.length() >= 6 && page.substr(1).find_first_of(kForbiddenFBSymbols) == string::npos; + return page.length() >= 6 && page.find_first_of(kForbiddenFBSymbols, 1) == string::npos; else if (page.length() >= 5 && page.find_first_of(kForbiddenFBSymbols) == string::npos) return true; -- 2.45.3 From 708fe4aa7268b7381d1bcfc51563931a46bf034b Mon Sep 17 00:00:00 2001 From: "S. Kozyr" Date: Fri, 1 Jul 2022 19:57:40 +0300 Subject: [PATCH 07/12] Introduced containsInvalidFBSymbol(string) to validate Facebook page. Signed-off-by: S. Kozyr --- indexer/validate_and_format_contacts.cpp | 32 ++++++++++++++++++++---- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/indexer/validate_and_format_contacts.cpp b/indexer/validate_and_format_contacts.cpp index 9a10e9ca43..672f4b7e3b 100644 --- a/indexer/validate_and_format_contacts.cpp +++ b/indexer/validate_and_format_contacts.cpp @@ -10,13 +10,33 @@ using namespace std; namespace osm { -constexpr char kForbiddenFBSymbols[] = " !@^*()~[]{}#$%&;,:+\"'/\\"; static auto const s_instaRegex = regex(R"(^@?[A-Za-z0-9_][A-Za-z0-9_.]{0,28}[A-Za-z0-9_]$)"); static auto const s_twitterRegex = regex(R"(^@?[A-Za-z0-9_]{1,15}$)"); static auto const s_badVkRegex = regex(R"(^\d\d\d.+$)"); static auto const s_goodVkRegex = regex(R"(^[A-Za-z0-9_.]{5,32}$)"); static auto const s_lineRegex = regex(R"(^[a-z0-9-_.]{4,20}$)"); + +bool containsInvalidFBSymbol(string const & facebookPage, int startIndex = 0) +{ + int size = facebookPage.size(); + for (int i=startIndex; i= ' ' && ch <= ',') || + ch == '/' || + (ch >= ':' && ch <= '@') || + (ch >= '[' && ch <= '^') || + ch == '`' || + (ch >= '{' && ch <= '~') ) + { + return true; + } + } + return false; +} + string ValidateAndFormat_facebook(string const & facebookPage) { if (facebookPage.empty()) @@ -25,14 +45,14 @@ string ValidateAndFormat_facebook(string const & facebookPage) if (facebookPage.front() == '@') { // Validate facebookPage as username or page name. - if (facebookPage.find_first_of(kForbiddenFBSymbols, 1) == string::npos) + if (!containsInvalidFBSymbol(facebookPage, 1)) return facebookPage.substr(1); else return {}; // Invalid symbol in Facebook username of page name. } else { - if (facebookPage.find_first_of(kForbiddenFBSymbols) == string::npos) + if (!containsInvalidFBSymbol(facebookPage)) return facebookPage; } @@ -242,9 +262,11 @@ bool ValidateFacebookPage(string const & page) // * no forbidden symbols in the string // * optional '@' at the start if (page.front() == '@') - return page.length() >= 6 && page.find_first_of(kForbiddenFBSymbols, 1) == string::npos; - else if (page.length() >= 5 && page.find_first_of(kForbiddenFBSymbols) == string::npos) + return page.length() >= 6 && !containsInvalidFBSymbol(page, 1); + else if (page.length() >= 5 && !containsInvalidFBSymbol(page)) return true; + //else + // LOG(LWARNING, ("containsInvalidFBSymbol == false")); if (!EditableMapObject::ValidateWebsite(page)) return false; -- 2.45.3 From fe160191da4b1cdb8ce274beddd41dbf020739f0 Mon Sep 17 00:00:00 2001 From: "S. Kozyr" Date: Fri, 1 Jul 2022 21:02:58 +0300 Subject: [PATCH 08/12] Added test for each forbidden Facebook symbol Signed-off-by: S. Kozyr --- .../validate_and_format_contacts_test.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/indexer/indexer_tests/validate_and_format_contacts_test.cpp b/indexer/indexer_tests/validate_and_format_contacts_test.cpp index 1698d35ab0..04a6c5cb8f 100644 --- a/indexer/indexer_tests/validate_and_format_contacts_test.cpp +++ b/indexer/indexer_tests/validate_and_format_contacts_test.cpp @@ -31,11 +31,15 @@ UNIT_TEST(EditableMapObject_ValidateFacebookPage) TEST(!osm::ValidateFacebookPage("osm"), ()); TEST(!osm::ValidateFacebookPage("@spaces are not welcome here"), ()); TEST(!osm::ValidateFacebookPage("spaces are not welcome here"), ()); - TEST(!osm::ValidateFacebookPage("slash/is_wrong"), ()); - TEST(!osm::ValidateFacebookPage("special-symbols@forbidden"), ()); - TEST(!osm::ValidateFacebookPage("special#symbols-forbidden"), ()); - // Symbols "£¤¥" are not allowed, but to check such cases it requires unicode magic. Not supported currently + constexpr char kForbiddenFBSymbols[] = " !@^*()~[]{}#$%&;,:+\"'/\\"; + for(size_t i=0; i Date: Fri, 1 Jul 2022 22:34:58 +0300 Subject: [PATCH 09/12] Fixed unit test compilation Signed-off-by: S. Kozyr --- indexer/indexer_tests/validate_and_format_contacts_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indexer/indexer_tests/validate_and_format_contacts_test.cpp b/indexer/indexer_tests/validate_and_format_contacts_test.cpp index 04a6c5cb8f..2d5371415a 100644 --- a/indexer/indexer_tests/validate_and_format_contacts_test.cpp +++ b/indexer/indexer_tests/validate_and_format_contacts_test.cpp @@ -33,7 +33,7 @@ UNIT_TEST(EditableMapObject_ValidateFacebookPage) TEST(!osm::ValidateFacebookPage("spaces are not welcome here"), ()); constexpr char kForbiddenFBSymbols[] = " !@^*()~[]{}#$%&;,:+\"'/\\"; - for(size_t i=0; i Date: Mon, 4 Jul 2022 19:33:39 +0300 Subject: [PATCH 10/12] Added TODO comment Signed-off-by: S. Kozyr --- indexer/indexer_tests/validate_and_format_contacts_test.cpp | 2 ++ indexer/validate_and_format_contacts.cpp | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/indexer/indexer_tests/validate_and_format_contacts_test.cpp b/indexer/indexer_tests/validate_and_format_contacts_test.cpp index 2d5371415a..4828f928e9 100644 --- a/indexer/indexer_tests/validate_and_format_contacts_test.cpp +++ b/indexer/indexer_tests/validate_and_format_contacts_test.cpp @@ -40,6 +40,8 @@ UNIT_TEST(EditableMapObject_ValidateFacebookPage) } // Symbols "£€¥" are not allowed, but to check such cases it requires unicode magic. Not supported currently. + // TODO: find all restricted *Unicode* symbols from https://www.facebook.com/pages/create page + // and them to the test //TEST(!osm::ValidateFacebookPage(u8"you-shall-not-pass-£€¥"), ()); } diff --git a/indexer/validate_and_format_contacts.cpp b/indexer/validate_and_format_contacts.cpp index 672f4b7e3b..338e7c49c2 100644 --- a/indexer/validate_and_format_contacts.cpp +++ b/indexer/validate_and_format_contacts.cpp @@ -17,6 +17,10 @@ static auto const s_goodVkRegex = regex(R"(^[A-Za-z0-9_.]{5,32}$)"); static auto const s_lineRegex = regex(R"(^[a-z0-9-_.]{4,20}$)"); +// TODO: Current implementation looks only for restricted symbols from ASCII block ignoring +// unicode. Need to find all restricted *Unicode* symbols +// from https://www.facebook.com/pages/create page and verify those symbols +// using MakeUniString or utf8cpp. bool containsInvalidFBSymbol(string const & facebookPage, int startIndex = 0) { int size = facebookPage.size(); -- 2.45.3 From 3c4bf59fd03b7bcaf03b46ed423cd88a4e101674 Mon Sep 17 00:00:00 2001 From: "S. Kozyr" Date: Mon, 4 Jul 2022 23:08:17 +0300 Subject: [PATCH 11/12] Added tests for "ValidateAndFormat_*" functions Signed-off-by: S. Kozyr --- .../validate_and_format_contacts_test.cpp | 94 +++++++++++++++++++ indexer/validate_and_format_contacts.cpp | 4 +- 2 files changed, 96 insertions(+), 2 deletions(-) diff --git a/indexer/indexer_tests/validate_and_format_contacts_test.cpp b/indexer/indexer_tests/validate_and_format_contacts_test.cpp index 4828f928e9..ea8212f9bf 100644 --- a/indexer/indexer_tests/validate_and_format_contacts_test.cpp +++ b/indexer/indexer_tests/validate_and_format_contacts_test.cpp @@ -4,6 +4,100 @@ #include +UNIT_TEST(EditableMapObject_ValidateAndFormat_facebook) +{ + TEST_EQUAL(osm::ValidateAndFormat_facebook(""), "", ()); + TEST_EQUAL(osm::ValidateAndFormat_facebook("facebook.com/OpenStreetMap"), "OpenStreetMap", ()); + TEST_EQUAL(osm::ValidateAndFormat_facebook("www.facebook.com/OpenStreetMap"), "OpenStreetMap", ()); + TEST_EQUAL(osm::ValidateAndFormat_facebook("http://facebook.com/OpenStreetMap"), "OpenStreetMap", ()); + TEST_EQUAL(osm::ValidateAndFormat_facebook("https://facebook.com/OpenStreetMap"), "OpenStreetMap", ()); + TEST_EQUAL(osm::ValidateAndFormat_facebook("http://www.facebook.com/OpenStreetMap"), "OpenStreetMap", ()); + TEST_EQUAL(osm::ValidateAndFormat_facebook("https://www.facebook.com/OpenStreetMap"), "OpenStreetMap", ()); + TEST_EQUAL(osm::ValidateAndFormat_facebook("https://en-us.facebook.com/OpenStreetMap"), "OpenStreetMap", ()); + TEST_EQUAL(osm::ValidateAndFormat_facebook("some.good.page"), "some.good.page", ()); + TEST_EQUAL(osm::ValidateAndFormat_facebook("@tree-house-interiors"), "tree-house-interiors", ()); + + TEST_EQUAL(osm::ValidateAndFormat_facebook("instagram.com/openstreetmapus"), "", ()); + TEST_EQUAL(osm::ValidateAndFormat_facebook("https://instagram.com/openstreetmapus"), "", ()); + TEST_EQUAL(osm::ValidateAndFormat_facebook("osm"), "", ()); + TEST_EQUAL(osm::ValidateAndFormat_facebook("@spaces are not welcome here"), "", ()); + TEST_EQUAL(osm::ValidateAndFormat_facebook("spaces are not welcome here"), "", ()); +} + +UNIT_TEST(EditableMapObject_ValidateAndFormat_instagram) +{ + TEST_EQUAL(osm::ValidateAndFormat_instagram(""), "", ()); + TEST_EQUAL(osm::ValidateAndFormat_instagram("instagram.com/openstreetmapus"), "openstreetmapus", ()); + TEST_EQUAL(osm::ValidateAndFormat_instagram("www.instagram.com/openstreetmapus"), "openstreetmapus", ()); + TEST_EQUAL(osm::ValidateAndFormat_instagram("http://instagram.com/openstreetmapus"), "openstreetmapus", ()); + TEST_EQUAL(osm::ValidateAndFormat_instagram("https://instagram.com/openstreetmapus"), "openstreetmapus", ()); + TEST_EQUAL(osm::ValidateAndFormat_instagram("http://www.instagram.com/openstreetmapus"), "openstreetmapus", ()); + TEST_EQUAL(osm::ValidateAndFormat_instagram("https://www.instagram.com/openstreetmapus"), "openstreetmapus", ()); + TEST_EQUAL(osm::ValidateAndFormat_instagram("https://en-us.instagram.com/openstreetmapus"), "openstreetmapus", ()); + TEST_EQUAL(osm::ValidateAndFormat_instagram("@open_street_map_us"), "open_street_map_us", ()); + TEST_EQUAL(osm::ValidateAndFormat_instagram("https://www.instagram.com/explore/locations/358536820/trivium-sport-en-dance/"), "explore/locations/358536820/trivium-sport-en-dance", ()); + TEST_EQUAL(osm::ValidateAndFormat_instagram("https://www.instagram.com/p/BvkgKZNDbqN/?ghid=UwPchX7B"), "p/BvkgKZNDbqN", ()); + + TEST_EQUAL(osm::ValidateAndFormat_instagram("facebook.com/osm_us"), "", ()); + TEST_EQUAL(osm::ValidateAndFormat_instagram(".dots_not_allowed."), "", ()); + TEST_EQUAL(osm::ValidateAndFormat_instagram("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"), "", ()); +} + +UNIT_TEST(EditableMapObject_ValidateAndFormat_twitter) +{ + TEST_EQUAL(osm::ValidateAndFormat_twitter("twitter.com/osm_tech"), "osm_tech", ()); + TEST_EQUAL(osm::ValidateAndFormat_twitter("www.twitter.com/osm_tech"), "osm_tech", ()); + TEST_EQUAL(osm::ValidateAndFormat_twitter("http://twitter.com/osm_tech"), "osm_tech", ()); + TEST_EQUAL(osm::ValidateAndFormat_twitter("https://twitter.com/osm_tech"), "osm_tech", ()); + TEST_EQUAL(osm::ValidateAndFormat_twitter("http://www.twitter.com/osm_tech"), "osm_tech", ()); + TEST_EQUAL(osm::ValidateAndFormat_twitter("https://www.twitter.com/osm_tech"), "osm_tech", ()); + TEST_EQUAL(osm::ValidateAndFormat_twitter("@_osm_tech_"), "_osm_tech_", ()); + + TEST_EQUAL(osm::ValidateAndFormat_twitter("instagram.com/osm_tech"), "", ()); + TEST_EQUAL(osm::ValidateAndFormat_twitter("dots.not.allowed"), "", ()); + TEST_EQUAL(osm::ValidateAndFormat_twitter("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"), "", ()); +} + +UNIT_TEST(EditableMapObject_ValidateAndFormat_vk) +{ + TEST_EQUAL(osm::ValidateAndFormat_vk("vk.com/id404"), "id404", ()); + TEST_EQUAL(osm::ValidateAndFormat_vk("vkontakte.ru/id404"), "id404", ()); + TEST_EQUAL(osm::ValidateAndFormat_vk("www.vk.com/id404"), "id404", ()); + TEST_EQUAL(osm::ValidateAndFormat_vk("http://vk.com/id404"), "id404", ()); + TEST_EQUAL(osm::ValidateAndFormat_vk("https://vk.com/id404"), "id404", ()); + TEST_EQUAL(osm::ValidateAndFormat_vk("https://vkontakte.ru/id404"), "id404", ()); + TEST_EQUAL(osm::ValidateAndFormat_vk("http://www.vk.com/id404"), "id404", ()); + TEST_EQUAL(osm::ValidateAndFormat_vk("https://www.vk.com/id404"), "id404", ()); + TEST_EQUAL(osm::ValidateAndFormat_vk("https://www.vk.com/id405/"), "id405", ()); + TEST_EQUAL(osm::ValidateAndFormat_vk("@22ab.cdef"), "22ab.cdef", ()); + + TEST_EQUAL(osm::ValidateAndFormat_vk("instagram.com/hello_world"), "", ()); +} + +UNIT_TEST(EditableMapObject_ValidateAndFormat_contactLine) +{ + TEST_EQUAL(osm::ValidateAndFormat_contactLine("http://line.me/ti/p/mzog4fnz24"), "mzog4fnz24", ()); + TEST_EQUAL(osm::ValidateAndFormat_contactLine("https://line.me/ti/p/xnv0g02rws"), "xnv0g02rws", ()); + TEST_EQUAL(osm::ValidateAndFormat_contactLine("https://line.me/ti/p/@dgxs9r6wad"), "dgxs9r6wad", ()); + TEST_EQUAL(osm::ValidateAndFormat_contactLine("https://line.me/ti/p/%40vne5uwke17"), "vne5uwke17", ()); + TEST_EQUAL(osm::ValidateAndFormat_contactLine("http://line.me/R/ti/p/bfsg1a8x9u"), "bfsg1a8x9u", ()); + TEST_EQUAL(osm::ValidateAndFormat_contactLine("https://line.me/R/ti/p/gdltt7s380"), "gdltt7s380", ()); + TEST_EQUAL(osm::ValidateAndFormat_contactLine("https://line.me/R/ti/p/@sdb2pb3lsg"), "sdb2pb3lsg", ()); + TEST_EQUAL(osm::ValidateAndFormat_contactLine("https://line.me/R/ti/p/%40b30h5mdj11"), "b30h5mdj11", ()); + TEST_EQUAL(osm::ValidateAndFormat_contactLine("http://line.me/R/home/public/main?id=hmczqsbav5"), "hmczqsbav5", ()); + TEST_EQUAL(osm::ValidateAndFormat_contactLine("https://line.me/R/home/public/main?id=wa1gvx91jb"), "wa1gvx91jb", ()); + TEST_EQUAL(osm::ValidateAndFormat_contactLine("http://line.me/R/home/public/profile?id=5qll5dyqqu"), "5qll5dyqqu", ()); + TEST_EQUAL(osm::ValidateAndFormat_contactLine("https://line.me/R/home/public/profile?id=r90ck7n1rq"), "r90ck7n1rq", ()); + TEST_EQUAL(osm::ValidateAndFormat_contactLine("https://line.me/R/home/public/profile?id=r90ck7n1rq"), "r90ck7n1rq", ()); + TEST_EQUAL(osm::ValidateAndFormat_contactLine("https://page.line.me/fom5198h"), "fom5198h", ()); + TEST_EQUAL(osm::ValidateAndFormat_contactLine("https://page.line.me/qn58n8g?web=mobile"), "qn58n8g", ()); + TEST_EQUAL(osm::ValidateAndFormat_contactLine("https://abc.line.me/en/some/page?id=xaladqv"), "abc.line.me/en/some/page?id=xaladqv", ()); + TEST_EQUAL(osm::ValidateAndFormat_contactLine("@abcd"), "abcd", ()); + TEST_EQUAL(osm::ValidateAndFormat_contactLine("@-hyphen-test-"), "-hyphen-test-", ()); + + TEST_EQUAL(osm::ValidateAndFormat_contactLine("https://line.com/ti/p/invalid-domain"), "", ()); +} + UNIT_TEST(EditableMapObject_ValidateFacebookPage) { TEST(osm::ValidateFacebookPage(""), ()); diff --git a/indexer/validate_and_format_contacts.cpp b/indexer/validate_and_format_contacts.cpp index 338e7c49c2..7549192ebd 100644 --- a/indexer/validate_and_format_contacts.cpp +++ b/indexer/validate_and_format_contacts.cpp @@ -49,14 +49,14 @@ string ValidateAndFormat_facebook(string const & facebookPage) if (facebookPage.front() == '@') { // Validate facebookPage as username or page name. - if (!containsInvalidFBSymbol(facebookPage, 1)) + if (facebookPage.length() >= 6 && !containsInvalidFBSymbol(facebookPage, 1)) return facebookPage.substr(1); else return {}; // Invalid symbol in Facebook username of page name. } else { - if (!containsInvalidFBSymbol(facebookPage)) + if (facebookPage.length() >= 5 && !containsInvalidFBSymbol(facebookPage)) return facebookPage; } -- 2.45.3 From d82e111a9ae52b9624be01b40763262d9eaef5e9 Mon Sep 17 00:00:00 2001 From: "S. Kozyr" Date: Tue, 5 Jul 2022 09:38:37 +0300 Subject: [PATCH 12/12] Fixes according to PR comment Signed-off-by: S. Kozyr --- indexer/validate_and_format_contacts.cpp | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/indexer/validate_and_format_contacts.cpp b/indexer/validate_and_format_contacts.cpp index 7549192ebd..f70bb6d49d 100644 --- a/indexer/validate_and_format_contacts.cpp +++ b/indexer/validate_and_format_contacts.cpp @@ -21,22 +21,20 @@ static auto const s_lineRegex = regex(R"(^[a-z0-9-_.]{4,20}$)"); // unicode. Need to find all restricted *Unicode* symbols // from https://www.facebook.com/pages/create page and verify those symbols // using MakeUniString or utf8cpp. -bool containsInvalidFBSymbol(string const & facebookPage, int startIndex = 0) +bool containsInvalidFBSymbol(string const & facebookPage, size_t startIndex = 0) { - int size = facebookPage.size(); - for (int i=startIndex; i= ' ' && ch <= ',') || + if ((ch >= ' ' && ch <= ',') || ch == '/' || (ch >= ':' && ch <= '@') || (ch >= '[' && ch <= '^') || ch == '`' || - (ch >= '{' && ch <= '~') ) - { + (ch >= '{' && ch <= '~')) return true; - } } return false; } @@ -269,8 +267,6 @@ bool ValidateFacebookPage(string const & page) return page.length() >= 6 && !containsInvalidFBSymbol(page, 1); else if (page.length() >= 5 && !containsInvalidFBSymbol(page)) return true; - //else - // LOG(LWARNING, ("containsInvalidFBSymbol == false")); if (!EditableMapObject::ValidateWebsite(page)) return false; -- 2.45.3