summaryrefslogtreecommitdiff
path: root/src/test/fixtures/identity.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/fixtures/identity.rs')
-rw-r--r--src/test/fixtures/identity.rs27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/test/fixtures/identity.rs b/src/test/fixtures/identity.rs
new file mode 100644
index 0000000..16463aa
--- /dev/null
+++ b/src/test/fixtures/identity.rs
@@ -0,0 +1,27 @@
+use uuid::Uuid;
+
+use crate::{app::App, clock::RequestedAt, login::extract::IdentityToken};
+
+pub fn not_logged_in() -> IdentityToken {
+ IdentityToken::new()
+}
+
+pub async fn logged_in(app: &App, login: &(String, String), now: &RequestedAt) -> IdentityToken {
+ let (name, password) = login;
+ let token = app
+ .logins()
+ .login(name, password, now)
+ .await
+ .expect("should succeed given known-valid credentials");
+
+ IdentityToken::new().set(&token)
+}
+
+pub fn secret(identity: &IdentityToken) -> &str {
+ identity.secret().expect("identity contained a secret")
+}
+
+pub fn fictitious() -> IdentityToken {
+ let token = Uuid::new_v4().to_string();
+ IdentityToken::new().set(&token)
+}