pub struct TestClient<'a> { /* private fields */ }Expand description
Sends requests carrying cookies and tenant.
Implementations§
Source§impl<'a> TestClient<'a>
impl<'a> TestClient<'a>
pub fn new(router: &'a Router) -> Self
Attaches a cookie to every request; a later value for the same name replaces the earlier one.
Attaches every (name, value) pair, replacing earlier values for the
same name.
Sourcepub fn csrf(&self, token: &str) -> Self
pub fn csrf(&self, token: &str) -> Self
Attach the CSRF cookie the form’s csrf_token field must match.
Sourcepub async fn sign_in(&self, db: &Db, panel: &str, user: &impl PanelUser) -> Self
pub async fn sign_in(&self, db: &Db, panel: &str, user: &impl PanelUser) -> Self
Signs user in to the panel Panel::new(panel) mounts, as a successful login does, and
attaches the session cookie; no password is hashed or checked.
The session row goes into db, the router’s database, keyed to PanelUser::user_id:
each request loads the user back through the panel’s Authenticator::find_by_id, so a
custom authenticator works as the shipped one does.
let admin = tablo_core::auth::create_admin(&mut db, "admin@example.com", "secret", "Admin")
.await
.expect("seed the admin");
let client = TestClient::new(router).sign_in(&db, "admin", &admin).await;§Panics
When the session row cannot be written, e.g. the database does not register
AuthSession.
Sourcepub fn tenant(&self, tenant: Uuid) -> Self
pub fn tenant(&self, tenant: Uuid) -> Self
Scopes the request to another tenant, taking precedence over the logged-in user’s tenant.
pub async fn get(&self, uri: &str) -> Response<Body>
pub async fn post_form(&self, uri: &str, body: String) -> Response<Body>
Sourcepub async fn submit(&self, uri: &str, body: &str) -> Response<Body>
pub async fn submit(&self, uri: &str, body: &str) -> Response<Body>
Posts the urlencoded body as a panel form does: with a fresh CSRF token in both the
cookie and the csrf_token field.