Apertura del repositorio

This commit is contained in:
2025-05-24 18:09:39 -03:00
parent 76e6359dad
commit d883ddd0d0
35253 changed files with 2891973 additions and 2 deletions
+3
View File
@@ -0,0 +1,3 @@
# -*- cmake -*-
add_subdirectory(login)
+9
View File
@@ -0,0 +1,9 @@
This directory only exists as a place for the build_data.json file to exist when the unit tests are run on a Mac, where the file goes to a sibling directory of the scripts dir. In Linux and Windows, the JSON file goes into the same directory as the script.
See:
test_get_summary.py
update_manager.get_summary()
for more details
- coyot 201606.02
@@ -0,0 +1 @@
{"Type":"viewer","Version":"4.0.5.315117","Channel":"Second Life Release"}
@@ -0,0 +1,49 @@
# -*- cmake -*-
project(login)
include(00-Common)
if(LL_TESTS)
include(LLAddBuildTest)
endif(LL_TESTS)
include(LLCommon)
include(LLCoreHttp)
set(login_SOURCE_FILES
lllogin.cpp
)
set(login_HEADER_FILES
lllogin.h
)
list(APPEND
login_SOURCE_FILES
${login_HEADER_FILES}
)
add_library(lllogin
${login_SOURCE_FILES}
)
target_include_directories( lllogin INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(lllogin
llmessage
llcorehttp
llcommon
llmath
llxml
)
if(LL_TESTS)
SET(lllogin_TEST_SOURCE_FILES
lllogin.cpp
)
set_source_files_properties(
lllogin.cpp
PROPERTIES
LL_TEST_ADDITIONAL_LIBRARIES llmessage llcorehttp llcommon
)
LL_ADD_PROJECT_UNIT_TESTS(lllogin "${lllogin_TEST_SOURCE_FILES}")
endif(LL_TESTS)
+444
View File
@@ -0,0 +1,444 @@
/**
* @file lllogin.cpp
*
* $LicenseInfo:firstyear=2009&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#include "llwin32headers.h"
#include "linden_common.h"
#include "llsd.h"
#include "llsdutil.h"
#include "lllogin.h"
#include <boost/bind.hpp>
#include "llcoros.h"
#include "llevents.h"
#include "lleventfilter.h"
#include "lleventcoro.h"
#include "llexception.h"
#include "stringize.h"
//*********************
// LLLogin
// *NOTE:Mani - Is this Impl needed now that the state machine runs the show?
class LLLogin::Impl
{
public:
Impl():
mPump("login", true) // Create the module's event pump with a tweaked (unique) name.
{
mValidAuthResponse["status"] = LLSD();
mValidAuthResponse["errorcode"] = LLSD();
mValidAuthResponse["error"] = LLSD();
mValidAuthResponse["transfer_rate"] = LLSD();
}
void connect(const std::string& uri, const LLSD& credentials);
void disconnect();
LLEventPump& getEventPump() { return mPump; }
private:
LLSD hidePasswd(const LLSD& data)
{
LLSD result(data);
if (result.has("params") && result["params"].has("passwd"))
{
result["params"]["passwd"] = "*******";
}
return result;
}
LLSD getProgressEventLLSD(const std::string& state, const std::string& change,
const LLSD& data = LLSD())
{
LLSD status_data;
status_data["state"] = state;
status_data["change"] = change;
status_data["progress"] = 0.0f;
if (mAuthResponse.has("transfer_rate"))
{
status_data["transfer_rate"] = mAuthResponse["transfer_rate"];
}
if (data.isDefined())
{
status_data["data"] = data;
}
return status_data;
}
void sendProgressEvent(const std::string& state, const std::string& change,
const LLSD& data = LLSD())
{
LLSD status_data = getProgressEventLLSD(state, change, data);
mPump.post(status_data);
}
LLSD validateResponse(const std::string& pumpName, const LLSD& response)
{
// Validate the response. If we don't recognize it, things
// could get ugly.
std::string mismatch(llsd_matches(mValidAuthResponse, response));
if (! mismatch.empty())
{
LL_ERRS("LLLogin") << "Received unrecognized event (" << mismatch << ") on "
<< pumpName << "pump: " << response
<< LL_ENDL;
return LLSD();
}
return response;
}
// In a coroutine's top-level function args, do NOT NOT NOT accept
// references (const or otherwise) to anything! Pass by value only!
void loginCoro(std::string uri, LLSD credentials);
LLEventStream mPump;
LLSD mAuthResponse, mValidAuthResponse;
};
void LLLogin::Impl::connect(const std::string& uri, const LLSD& login_params)
{
LL_DEBUGS("LLLogin") << " connect with uri '" << uri << "', login_params " << login_params << LL_ENDL;
// Launch a coroutine with our login_() method. Run the coroutine until
// its first wait; at that point, return here.
std::string coroname =
LLCoros::instance().launch("LLLogin::Impl::login_", [=, this]() { loginCoro(uri, login_params); });
LL_DEBUGS("LLLogin") << " connected with uri '" << uri << "', login_params " << login_params << LL_ENDL;
}
namespace
{
// Instantiate this rendezvous point at namespace scope so it's already
// present no matter how early the updater might post to it.
// Use an LLEventMailDrop, which has future-like semantics: regardless of the
// relative order in which post() or listen() are called, it delivers each
// post() event to its listener(s) until one of them consumes that event.
static LLEventMailDrop sSyncPoint("LoginSync");
}
void LLLogin::Impl::loginCoro(std::string uri, LLSD login_params)
{
LLSD printable_params = hidePasswd(login_params);
try
{
LL_DEBUGS("LLLogin") << "Entering coroutine " << LLCoros::getName()
<< " with uri '" << uri << "', parameters " << printable_params << LL_ENDL;
LLEventPump& xmlrpcPump(LLEventPumps::instance().obtain("LLXMLRPCTransaction"));
// EXT-4193: use a DIFFERENT reply pump than for the SRV request. We used
// to share them -- but the EXT-3934 fix made it possible for an abandoned
// SRV response to arrive just as we were expecting the XMLRPC response.
LLEventStream loginReplyPump("loginreply", true);
LLSD::Integer attempts = 0;
LLSD request(login_params);
request["reply"] = loginReplyPump.getName();
request["uri"] = uri;
std::string status;
// Loop back to here if login attempt redirects to a different
// request["uri"]
for (;;)
{
++attempts;
LLSD progress_data;
progress_data["attempt"] = attempts;
progress_data["request"] = hidePasswd(request);
sendProgressEvent("offline", "authenticating", progress_data);
// We expect zero or more "Downloading" status events, followed by
// exactly one event with some other status. Use postAndSuspend() the
// first time, because -- at least in unit-test land -- it's
// possible for the reply to arrive before the post() call
// returns. Subsequent responses, of course, must be awaited
// without posting again.
for (mAuthResponse = validateResponse(loginReplyPump.getName(),
llcoro::postAndSuspend(request, xmlrpcPump, loginReplyPump, "reply"));
mAuthResponse["status"].asString() == "Downloading";
mAuthResponse = validateResponse(loginReplyPump.getName(),
llcoro::suspendUntilEventOn(loginReplyPump)))
{
// Still Downloading -- send progress update.
sendProgressEvent("offline", "downloading");
}
LL_DEBUGS("LLLogin") << "Auth Response: " << mAuthResponse << LL_ENDL;
status = mAuthResponse["status"].asString();
// Okay, we've received our final status event for this
// request. Unless we got a redirect response, break the retry
// loop for the current rewrittenURIs entry.
if (!(status == "Complete" &&
mAuthResponse["responses"]["login"].asString() == "indeterminate"))
{
break;
}
sendProgressEvent("offline", "indeterminate", mAuthResponse["responses"]);
// Here the login service at the current URI is redirecting us
// to some other URI ("indeterminate" -- why not "redirect"?).
// The response should contain another uri to try, with its
// own auth method.
request["uri"] = mAuthResponse["responses"]["next_url"].asString();
request["method"] = mAuthResponse["responses"]["next_method"].asString();
} // loop back to try the redirected URI
// Here we're done with redirects.
if (status == "Complete")
{
// StatusComplete does not imply auth success. Check the
// actual outcome of the request. We've already handled the
// "indeterminate" case in the loop above.
if (mAuthResponse["responses"]["login"].asString() == "true")
{
sendProgressEvent("online", "connect", mAuthResponse["responses"]);
}
else
{
// Synchronize here with the updater. We synchronize here rather
// than in the fail.login handler, which actually examines the
// response from login.cgi, because here we are definitely in a
// coroutine and can definitely use suspendUntilBlah(). Whoever's
// listening for fail.login might not be.
// If the reason for login failure is that we must install a
// required update, we definitely want to pass control to the
// updater to manage that for us. We'll handle any other login
// failure ourselves, as usual. We figure that no matter where you
// are in the world, or what kind of network you're on, we can
// reasonably expect the Viewer Version Manager to respond more or
// less as quickly as login.cgi. This synchronization is only
// intended to smooth out minor races between the two services.
// But what if the updater crashes? Use a timeout so that
// eventually we'll tire of waiting for it and carry on as usual.
// Given the above, it can be a fairly short timeout, at least
// from a human point of view.
// Since sSyncPoint is an LLEventMailDrop, we DEFINITELY want to
// consume the posted event.
LLCoros::OverrideConsuming oc(true);
LLSD responses(mAuthResponse["responses"]);
LLSD updater;
if (printable_params["wait_for_updater"].asBoolean())
{
std::string reason_response = responses["data"]["reason"].asString();
// Timeout should produce the isUndefined() object passed here.
if (reason_response == "update")
{
LL_INFOS("LLLogin") << "Login failure, waiting for sync from updater" << LL_ENDL;
updater = llcoro::suspendUntilEventOnWithTimeout(sSyncPoint, 10, LLSD());
}
else
{
LL_DEBUGS("LLLogin") << "Login failure, waiting for sync from updater" << LL_ENDL;
updater = llcoro::suspendUntilEventOnWithTimeout(sSyncPoint, 3, LLSD());
}
if (updater.isUndefined())
{
LL_WARNS("LLLogin") << "Failed to hear from updater, proceeding with fail.login"
<< LL_ENDL;
}
else
{
LL_DEBUGS("LLLogin") << "Got responses from updater and login.cgi" << LL_ENDL;
}
}
// Let the fail.login handler deal with empty updater response.
responses["updater"] = updater;
sendProgressEvent("offline", "fail.login", responses);
}
return; // Done!
}
/*==========================================================================*|
// Sometimes we end with "Started" here. Slightly slow server? Seems
// to be ok to just skip it. Otherwise we'd error out and crash in the
// if below.
if( status == "Started")
{
LL_DEBUGS("LLLogin") << mAuthResponse << LL_ENDL;
continue;
}
|*==========================================================================*/
// If we don't recognize status at all, trouble
if (! (status == "CURLError"
|| status == "BadType"
|| status == "XMLRPCError"
|| status == "OtherError"))
{
LL_ERRS("LLLogin") << "Unexpected status " << status
<< " from " << xmlrpcPump.getName()
<< " pump: " << mAuthResponse << LL_ENDL;
return;
}
if (status == "BadType")
{
// Invalid xmlrpc type
// Dump this response into logs
LL_WARNS("LLLogin") << "Failed to parse response"
<< " from " << xmlrpcPump.getName()
<< " pump: " << mAuthResponse << LL_ENDL;
}
// Here status IS one of the errors tested above.
// Tell caller this didn't work out so well.
// *NOTE: The response from LLXMLRPCListener's Poller::poll method returns an
// llsd with no "responses" node. To make the output from an incomplete login symmetrical
// to success, add a data/message and data/reason fields.
LLSD error_response(LLSDMap
("reason", mAuthResponse["status"])
("errorcode", mAuthResponse["errorcode"])
("message", mAuthResponse["error"]));
if(mAuthResponse.has("certificate"))
{
error_response["certificate"] = mAuthResponse["certificate"];
}
sendProgressEvent("offline", "fail.login", error_response);
}
catch (...) {
LOG_UNHANDLED_EXCEPTION(STRINGIZE("coroutine " << LLCoros::getName()
<< "('" << uri << "', " << printable_params << ")"));
throw;
}
}
void LLLogin::Impl::disconnect()
{
sendProgressEvent("offline", "disconnect");
}
//*********************
// LLLogin
LLLogin::LLLogin() :
mImpl(new LLLogin::Impl())
{
}
LLLogin::~LLLogin()
{
}
void LLLogin::connect(const std::string& uri, const LLSD& credentials)
{
mImpl->connect(uri, credentials);
}
void LLLogin::disconnect()
{
mImpl->disconnect();
}
LLEventPump& LLLogin::getEventPump()
{
return mImpl->getEventPump();
}
// The following is the list of important functions that happen in the
// current login process that we want to move to this login module.
// The list associates to event with the original idle_startup() 'STATE'.
// Setup login
// State_LOGIN_AUTH_INIT
// Authenticate
// STATE_LOGIN_AUTHENTICATE
// Connect to the login server, presumably login.cgi, requesting the login
// and a slew of related initial connection information.
// This is an asynch action. The final response, whether success or error
// is handled by STATE_LOGIN_PROCESS_REPONSE.
// There is no immediate error or output from this call.
//
// Input:
// URI
// Credentials (first, last, password)
// Start location
// Bool Flags:
// skip optional update
// accept terms of service
// accept critical message
// Last exec event. (crash state of previous session)
// requested optional data (inventory skel, initial outfit, etc.)
// local mac address
// viewer serial no. (md5 checksum?)
//sAuthUriNum = llclamp(sAuthUriNum, 0, (S32)sAuthUris.size()-1);
//LLUserAuth::getInstance()->authenticate(
// sAuthUris[sAuthUriNum],
// auth_method,
// firstname,
// lastname,
// password, // web_login_key,
// start.str(),
// gSkipOptionalUpdate,
// gAcceptTOS,
// gAcceptCriticalMessage,
// gLastExecEvent,
// requested_options,
// hashed_mac_string,
// LLAppViewer::instance()->getSerialNumber());
//
// Download the Response
// STATE_LOGIN_NO_REPONSE_YET and STATE_LOGIN_DOWNLOADING
// I had assumed that this was default behavior of the message system. However...
// During login, the message system is checked only by these two states in idle_startup().
// I guess this avoids the overhead of checking network messages for those login states
// that don't need to do so, but geez!
// There are two states to do this one function just to update the login
// status text from 'Logging In...' to 'Downloading...'
//
//
// Handle Login Response
// STATE_LOGIN_PROCESS_RESPONSE
//
// This state handle the result of the request to login. There is a metric ton of
// code in this case. This state will transition to:
// STATE_WORLD_INIT, on success.
// STATE_AUTHENTICATE, on failure.
// STATE_UPDATE_CHECK, to handle user during login interaction like TOS display.
//
// Much of the code in this case belongs on the viewer side of the fence and not in login.
// Login should probably return with a couple of events, success and failure.
// Failure conditions can be specified in the events data pacet to allow the viewer
// to re-engauge login as is appropriate. (Or should there be multiple failure messages?)
// Success is returned with the data requested from the login. According to OGP specs
// there may be intermediate steps before reaching this result in future login
// implementations.
+127
View File
@@ -0,0 +1,127 @@
/**
* @file lllogin.h
*
* $LicenseInfo:firstyear=2009&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#ifndef LL_LLLOGIN_H
#define LL_LLLOGIN_H
#include <boost/scoped_ptr.hpp>
class LLSD;
class LLEventPump;
/**
* @class LLLogin
* @brief Class to encapsulate the action and state of grid login.
*/
class LLLogin
{
public:
LLLogin();
~LLLogin();
/**
* Make a connection to a grid.
* @param uri The 'well known and published' authentication URL.
* @param credentials LLSD data that contians the credentials.
* *NOTE:Mani The credential data can vary depending upon the authentication
* method used. The current interface matches the values passed to
* the XMLRPC login request.
{
method : string,
first : string,
last : string,
passwd : string,
start : string,
skipoptional : bool,
agree_to_tos : bool,
read_critical : bool,
last_exec_event : int,
version : string,
channel : string,
mac : string,
id0 : string,
options : [ strings ]
}
*/
void connect(const std::string& uri, const LLSD& credentials);
/**
* Disconnect from a the current connection.
*/
void disconnect();
/**
* Retrieve the event pump from this login class.
*/
LLEventPump& getEventPump();
/*
Event API
LLLogin will issue multiple events to it pump to indicate the
progression of states through login. The most important
states are "offline" and "online" which indicate auth failure
and auth success respectively.
pump: login (tweaked)
These are the events posted to the 'login'
event pump from the login module.
{
state : string, // See below for the list of states.
progress : real // for progress bar.
data : LLSD // Dependent upon state.
}
States for method 'login_to_simulator'
offline - set initially state and upon failure. data is the server response.
srvrequest - upon uri rewrite request. no data.
authenticating - upon auth request. data, 'attempt' number and 'request' llsd.
downloading - upon ack from auth server, before completion. no data
online - upon auth success. data is server response.
Dependencies:
pump: LLAres
LLLogin makes a request for a SRV record from the uri provided by the connect method.
The following event pump should exist to service that request.
pump name: LLAres
request = {
op : "rewriteURI"
uri : string
reply : string
pump: LLXMLRPCListener
The request merely passes the credentials LLSD along, with one additional
member, 'reply', which is the string name of the event pump to reply on.
*/
private:
class Impl;
std::unique_ptr<Impl> mImpl;
};
#endif // LL_LLLOGIN_H
@@ -0,0 +1,343 @@
/**
* @file lllogin_test.cpp
* @author Mark Palange
* @date 2009-02-26
* @brief Tests of lllogin.cpp.
*
* $LicenseInfo:firstyear=2009&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2009-2010, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#if LL_WINDOWS
#pragma warning (disable : 4355) // 'this' used in initializer list: yes, intentionally
#endif
// Precompiled header
#include "linden_common.h"
// associated header
#include "../lllogin.h"
// STL headers
// std headers
#include <chrono>
#include <iostream>
// external library headers
// other Linden headers
#include "../../../test/debug.h"
#include "../../../test/lltestapp.h"
#include "../../../test/lltut.h"
#include "llevents.h"
#include "lleventcoro.h"
#include "llsd.h"
#include "stringize.h"
#if LL_WINDOWS
#define skipwin(arg) skip(arg)
#define skipmac(arg)
#define skiplinux(arg)
#elif LL_DARWIN
#define skipwin(arg)
#define skipmac(arg) skip(arg)
#define skiplinux(arg)
#elif LL_LINUX
#define skipwin(arg)
#define skipmac(arg)
#define skiplinux(arg) skip(arg)
#endif
/*****************************************************************************
* Helper classes
*****************************************************************************/
// This is a listener to receive results from lllogin.
class LoginListener: public LLEventTrackable
{
std::string mName;
LLSD mLastEvent;
size_t mCalls{ 0 };
Debug mDebug;
public:
LoginListener(const std::string& name) :
mName(name),
mDebug(stringize(*this))
{}
bool call(const LLSD& event)
{
mDebug(STRINGIZE("LoginListener called!: " << event));
mLastEvent = event;
++mCalls;
return false;
}
LLBoundListener listenTo(LLEventPump& pump)
{
return pump.listen(mName, boost::bind(&LoginListener::call, this, _1));
}
LLSD lastEvent() const { return mLastEvent; }
size_t getCalls() const { return mCalls; }
// wait for arbitrary predicate to become true
template <typename PRED>
LLSD waitFor(const std::string& desc, PRED&& pred, double seconds=2.0) const
{
// remember when we started waiting
auto start = std::chrono::system_clock::now();
// Break loop when the passed predicate returns true
while (! std::forward<PRED>(pred)())
{
// but if we've been spinning here too long, test failed
// how long have we been here, anyway?
auto now = std::chrono::system_clock::now();
// the default ratio for duration is seconds
std::chrono::duration<double> elapsed = (now - start);
if (elapsed.count() > seconds)
{
tut::fail(STRINGIZE("LoginListener::waitFor() took more than "
<< seconds << " seconds waiting for " << desc));
}
// haven't yet received the new call, nor have we timed out --
// just wait
llcoro::suspend();
}
// oh good, we've gotten at least one new call! Return its event.
return lastEvent();
}
// wait for any call() calls beyond prevcalls
LLSD waitFor(size_t prevcalls, double seconds) const
{
return waitFor(STRINGIZE("more than " << prevcalls << " calls"),
[this, prevcalls]()->bool{ return getCalls() > prevcalls; },
seconds);
}
friend std::ostream& operator<<(std::ostream& out, const LoginListener& listener)
{
return out << "LoginListener(" << listener.mName << ')';
}
};
class LLXMLRPCListener: public LLEventTrackable
{
std::string mName;
LLSD mEvent;
bool mImmediateResponse;
LLSD mResponse;
Debug mDebug;
public:
LLXMLRPCListener(const std::string& name,
bool i = false,
const LLSD& response = LLSD()
) :
mName(name),
mImmediateResponse(i),
mResponse(response),
mDebug(stringize(*this))
{
if(mResponse.isUndefined())
{
mResponse["status"] = "Complete"; // StatusComplete
mResponse["errorcode"] = 0;
mResponse["error"] = "dummy response";
mResponse["transfer_rate"] = 0;
mResponse["responses"]["login"] = true;
}
}
void setResponse(const LLSD& r)
{
mResponse = r;
}
bool handle_event(const LLSD& event)
{
mDebug(STRINGIZE("LLXMLRPCListener called!: " << event));
mEvent = event;
if(mImmediateResponse)
{
sendReply();
}
return false;
}
void sendReply()
{
LLEventPumps::instance().obtain(mEvent["reply"]).post(mResponse);
}
LLBoundListener listenTo(LLEventPump& pump)
{
return pump.listen(mName, boost::bind(&LLXMLRPCListener::handle_event, this, _1));
}
friend std::ostream& operator<<(std::ostream& out, const LLXMLRPCListener& listener)
{
return out << "LLXMLRPCListener(" << listener.mName << ')';
}
};
/*****************************************************************************
* TUT
*****************************************************************************/
namespace tut
{
struct llviewerlogin_data
{
llviewerlogin_data() :
pumps(LLEventPumps::instance())
{}
~llviewerlogin_data()
{
pumps.clear();
}
LLEventPumps& pumps;
LLTestApp testApp;
};
typedef test_group<llviewerlogin_data> llviewerlogin_group;
typedef llviewerlogin_group::object llviewerlogin_object;
llviewerlogin_group llviewerlogingrp("LLViewerLogin");
template<> template<>
void llviewerlogin_object::test<1>()
{
DEBUG;
// Testing login with an immediate response from XMLPRC
// The response will come before the post request exits.
// This tests an edge case of the login state handling.
LLEventStream xmlrpcPump("LLXMLRPCTransaction"); // Dummy XMLRPC pump
bool respond_immediately = true;
// Have dummy XMLRPC respond immediately.
LLXMLRPCListener dummyXMLRPC("dummy_xmlrpc", respond_immediately);
LLTempBoundListener conn1 = dummyXMLRPC.listenTo(xmlrpcPump);
LLLogin login;
LoginListener listener("test_ear");
LLTempBoundListener conn2 = listener.listenTo(login.getEventPump());
LLSD credentials;
credentials["first"] = "foo";
credentials["last"] = "bar";
credentials["passwd"] = "secret";
login.connect("login.bar.com", credentials);
listener.waitFor(
"online state",
[&listener]()->bool{ return listener.lastEvent()["state"].asString() == "online"; });
}
template<> template<>
void llviewerlogin_object::test<2>()
{
DEBUG;
// Test completed response, that fails to login.
set_test_name("LLLogin valid response, failure (eg. bad credentials)");
// Testing normal login procedure.
LLEventStream xmlrpcPump("LLXMLRPCTransaction"); // Dummy XMLRPC pump
LLXMLRPCListener dummyXMLRPC("dummy_xmlrpc");
LLTempBoundListener conn1 = dummyXMLRPC.listenTo(xmlrpcPump);
LLLogin login;
LoginListener listener("test_ear");
LLTempBoundListener conn2 = listener.listenTo(login.getEventPump());
LLSD credentials;
credentials["first"] = "who";
credentials["last"] = "what";
credentials["passwd"] = "badpasswd";
login.connect("login.bar.com", credentials);
llcoro::suspend();
ensure_equals("Auth state", listener.lastEvent()["change"].asString(), "authenticating");
auto prev = listener.getCalls();
// Send the failed auth request reponse
LLSD data;
data["status"] = "Complete";
data["errorcode"] = 0;
data["error"] = "dummy response";
data["transfer_rate"] = 0;
data["responses"]["login"] = "false";
dummyXMLRPC.setResponse(data);
dummyXMLRPC.sendReply();
// we happen to know LLLogin uses a 10-second timeout to try to sync
// with SLVersionChecker -- allow at least that much time before
// giving up
listener.waitFor(prev, 11.0);
ensure_equals("Failed to offline", listener.lastEvent()["state"].asString(), "offline");
}
template<> template<>
void llviewerlogin_object::test<3>()
{
DEBUG;
// Test incomplete response, that end the attempt.
set_test_name("LLLogin valid response, failure (eg. bad credentials)");
// Testing normal login procedure.
LLEventStream xmlrpcPump("LLXMLRPCTransaction"); // Dummy XMLRPC pump
LLXMLRPCListener dummyXMLRPC("dummy_xmlrpc");
LLTempBoundListener conn1 = dummyXMLRPC.listenTo(xmlrpcPump);
LLLogin login;
LoginListener listener("test_ear");
LLTempBoundListener conn2 = listener.listenTo(login.getEventPump());
LLSD credentials;
credentials["first"] = "these";
credentials["last"] = "don't";
credentials["passwd"] = "matter";
login.connect("login.bar.com", credentials);
llcoro::suspend();
ensure_equals("Auth state", listener.lastEvent()["change"].asString(), "authenticating");
auto prev = listener.getCalls();
// Send the failed auth request reponse
LLSD data;
data["status"] = "OtherError";
data["errorcode"] = 0;
data["error"] = "dummy response";
data["transfer_rate"] = 0;
dummyXMLRPC.setResponse(data);
dummyXMLRPC.sendReply();
// we happen to know LLLogin uses a 10-second timeout to try to sync
// with SLVersionChecker -- allow at least that much time before
// giving up
listener.waitFor(prev, 11.0);
ensure_equals("Failed to offline", listener.lastEvent()["state"].asString(), "offline");
}
}