text
stringlengths
0
234
Query.Set_Join ("inner join awa_email e on e.user_id = o.user_id");
Query.Set_Filter ("e.email = ? AND o.kind = ?");
Query.Bind_Param (1, Email);
Query.Bind_Param (2, Signup_Kind);
Key.Find (DB, Query, Found);
if not Found then
Query.Bind_Param (2, Password_Kind);
Key.Find (DB, Query, Found);
if not Found then
Log.Error ("Cannot find access key for email {0}", Email);
end if;
end if;
end Find_Access_Key;
-- ------------------------------
-- Login a user and create a session
-- ------------------------------
procedure Login (Principal : in out Test_User) is
begin
Initialize (Principal);
Principal.Manager.Authenticate (Email => Principal.Email.Get_Email,
Password => "admin",
IpAddr => "192.168.1.1",
Principal => Principal.Principal);
Principal.User := Principal.Principal.Get_User;
Principal.Session := Principal.Principal.Get_Session;
end Login;
-- ------------------------------
-- Logout the user and closes the current session.
-- ------------------------------
procedure Logout (Principal : in out Test_User) is
begin
Initialize (Principal);
Principal.Manager.Close_Session (Principal.Session.Get_Id, True);
end Logout;
-- ------------------------------
-- Simulate a user login in the given service context.
-- ------------------------------
procedure Login (Context : in out AWA.Services.Contexts.Service_Context'Class;
Sec_Context : in out Security.Contexts.Security_Context;
Email : in String) is
User : Test_User;
Principal : AWA.Users.Principals.Principal_Access;
App : constant AWA.Applications.Application_Access := AWA.Tests.Get_Application;
begin
AWA.Tests.Set_Application_Context;
Create_User (User, Email);
Principal := AWA.Users.Principals.Create (User.User, User.Session);
Context.Set_Context (App, Principal);
Sec_Context.Set_Context (Manager => App.Get_Security_Manager,
Principal => Principal.all'Access);
-- Keep track of the Principal instance so that Tear_Down will release it.
-- Most tests will call Login but don't call Logout because there is no real purpose
-- for the test in doing that and it allows to keep the unit test simple. This creates
-- memory leak because the Principal instance is not freed.
for I in Logged_Users'Range loop
if Logged_Users (I) = null then
Logged_Users (I) := Principal;
exit;
end if;
end loop;
end Login;
-- ------------------------------
-- Simulate a user login on the request. Upon successful login, a session that is
-- authentified is associated with the request object.
-- ------------------------------
procedure Login (Email : in String;
Request : in out ASF.Requests.Mockup.Request) is
User : Test_User;
Reply : ASF.Responses.Mockup.Response;
begin
Create_User (User, Email);
ASF.Tests.Do_Get (Request, Reply, "/auth/login.html", "login-user-1.html");
Request.Set_Parameter ("email", Email);
Request.Set_Parameter ("password", "admin");
Request.Set_Parameter ("login", "1");
Request.Set_Parameter ("login-button", "1");
ASF.Tests.Do_Post (Request, Reply, "/auth/login.html", "login-user-2.html");
end Login;
-- ------------------------------
-- Setup the context and security context to simulate an anonymous user.
-- ------------------------------
procedure Anonymous (Context : in out AWA.Services.Contexts.Service_Context'Class;
Sec_Context : in out Security.Contexts.Security_Context) is
App : constant AWA.Applications.Application_Access := AWA.Tests.Get_Application;
begin
AWA.Tests.Set_Application_Context;
Context.Set_Context (App, null);
Sec_Context.Set_Context (Manager => App.Get_Security_Manager,
Principal => null);
end Anonymous;
-- ------------------------------
-- Simulate the recovery password process for the given user.