Fixed failing osm auth tests

OSMers changed form params again :)

Signed-off-by: Alexander Borsuk <me@alex.bio>
This commit is contained in:
Alexander Borsuk 2021-11-27 00:01:23 +01:00 committed by Alexander Borsuk
parent 0b0a07d22f
commit ae48e46083
4 changed files with 29 additions and 30 deletions

View file

@ -90,14 +90,6 @@ OsmOAuth OsmOAuth::ServerAuth(KeySecret const & userKeySecret) noexcept
return auth;
}
// static
OsmOAuth OsmOAuth::IZServerAuth() noexcept
{
constexpr char const * kIZTestServer = "http://test.osmz.ru";
constexpr char const * kIZConsumerKey = "F0rURWssXDYxtm61279rHdyu3iSLYSP3LdF6DL3Y";
constexpr char const * kIZConsumerSecret = "IoR5TAedXxcybtd5tIBZqAK07rDRAuFMsQ4nhAP6";
return OsmOAuth(kIZConsumerKey, kIZConsumerSecret, kIZTestServer, kIZTestServer);
}
// static
OsmOAuth OsmOAuth::DevServerAuth() noexcept
{
constexpr char const * kOsmDevServer = "https://master.apis.dev.openstreetmap.org";
@ -342,9 +334,9 @@ bool OsmOAuth::ResetPassword(string const & email) const
SessionID const sid = FetchSessionId(kForgotPasswordUrlPart);
map<string, string> const params =
{
{"user[email]", email},
{"email", email},
{"authenticity_token", sid.m_token},
{"commit", "Reset password"}
{"commit", "Reset password"},
};
HttpClient request(m_baseUrl + kForgotPasswordUrlPart);
request.SetBodyData(BuildPostRequest(params), "application/x-www-form-urlencoded");

View file

@ -64,8 +64,6 @@ public:
static OsmOAuth ServerAuth() noexcept;
static OsmOAuth ServerAuth(KeySecret const & userKeySecret) noexcept;
/// Ilya Zverev's test server.
static OsmOAuth IZServerAuth() noexcept;
/// master.apis.dev.openstreetmap.org
static OsmOAuth DevServerAuth() noexcept;
/// api.openstreetmap.org

View file

@ -7,28 +7,28 @@
using osm::OsmOAuth;
using osm::KeySecret;
char const * kValidOsmUser = "OrganicMapsTestUser";
char const * kValidOsmPassword = "12345678";
namespace
{
constexpr char const * kIZTestUser = "Testuser";
constexpr char const * kIZTestPassword = "testtest";
constexpr char const * kIZInvalidPassword = "123";
constexpr char const * kIZForgotPasswordEmail = "test@example.com";
constexpr char const * kInvalidOsmPassword = "123";
constexpr char const * kForgotPasswordEmail = "osmtest@organicmaps.app";
} // namespace
UNIT_TEST(OSM_Auth_InvalidLogin)
{
OsmOAuth auth = OsmOAuth::IZServerAuth();
OsmOAuth auth = OsmOAuth::DevServerAuth();
bool result;
TEST_NO_THROW(result = auth.AuthorizePassword(kIZTestUser, kIZInvalidPassword), ());
TEST_NO_THROW(result = auth.AuthorizePassword(kValidOsmUser, kInvalidOsmPassword), ());
TEST_EQUAL(result, false, ("invalid password"));
TEST(!auth.IsAuthorized(), ("Should not be authorized."));
}
UNIT_TEST(OSM_Auth_Login)
{
OsmOAuth auth = OsmOAuth::IZServerAuth();
OsmOAuth auth = OsmOAuth::DevServerAuth();
bool result;
TEST_NO_THROW(result = auth.AuthorizePassword(kIZTestUser, kIZTestPassword), ());
TEST_NO_THROW(result = auth.AuthorizePassword(kValidOsmUser, kValidOsmPassword), ());
TEST_EQUAL(result, true, ("login to test server"));
TEST(auth.IsAuthorized(), ("Should be authorized."));
OsmOAuth::Response const perm = auth.Request("/permissions");
@ -38,9 +38,9 @@ UNIT_TEST(OSM_Auth_Login)
UNIT_TEST(OSM_Auth_ForgotPassword)
{
OsmOAuth auth = OsmOAuth::IZServerAuth();
OsmOAuth auth = OsmOAuth::DevServerAuth();
bool result;
TEST_NO_THROW(result = auth.ResetPassword(kIZForgotPasswordEmail), ());
TEST_NO_THROW(result = auth.ResetPassword(kForgotPasswordEmail), ());
TEST_EQUAL(result, true, ("Correct email"));
TEST_NO_THROW(result = auth.ResetPassword("not@registered.email"), ());
TEST_EQUAL(result, false, ("Incorrect email"));

View file

@ -9,6 +9,7 @@
#include <cstdint>
#include <string>
#include <random>
#include "3party/pugixml/src/pugixml.hpp"
@ -16,15 +17,14 @@ using osm::ServerApi06;
using osm::OsmOAuth;
using namespace pugi;
constexpr char const * kValidOsmUser = "MapsMeTestUser";
constexpr char const * kInvalidOsmUser = "qwesdxzcgretwr";
constexpr char const * kValidOsmPassword = "12345678";
extern char const * kValidOsmUser;
extern char const * kValidOsmPassword;
UNIT_TEST(OSM_ServerAPI_TestUserExists)
{
ServerApi06 api(OsmOAuth::DevServerAuth());
TEST(api.TestOSMUser(kValidOsmUser), ());
TEST(!api.TestOSMUser(kInvalidOsmUser), ());
TEST(!api.TestOSMUser("donotregisterthisuser"), ());
}
namespace
@ -41,9 +41,18 @@ 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, 3500, ("User id"));
TEST_EQUAL(prefs.m_id, 11600, ("User id"));
return api;
}
// Returns random coordinate to avoid races when several workers run tests at the same time.
ms::LatLon RandomCoordinate()
{
std::random_device rd;
return ms::LatLon(std::uniform_real_distribution<>{-89., 89.}(rd),
std::uniform_real_distribution<>{-179., 179.}(rd));
}
} // namespace
void DeleteOSMNodeIfExists(ServerApi06 const & api, uint64_t changeSetId, ms::LatLon const & ll)
@ -64,8 +73,8 @@ void DeleteOSMNodeIfExists(ServerApi06 const & api, uint64_t changeSetId, ms::La
UNIT_TEST(OSM_ServerAPI_ChangesetAndNode)
{
ms::LatLon const kOriginalLocation(11.11, 12.12);
ms::LatLon const kModifiedLocation(10.10, 12.12);
ms::LatLon const kOriginalLocation = RandomCoordinate();
ms::LatLon const kModifiedLocation = RandomCoordinate();
using editor::XMLFeature;
XMLFeature node(XMLFeature::Type::Node);
@ -123,7 +132,7 @@ UNIT_TEST(OSM_ServerAPI_ChangesetAndNode)
UNIT_TEST(OSM_ServerAPI_Notes)
{
ms::LatLon const pos(59.9, 30.5);
ms::LatLon const pos = RandomCoordinate();
ServerApi06 const api = CreateAPI();
uint64_t id;
TEST_NO_THROW(id = api.CreateNote(pos, "A test note"), ("Creating a note"));