tests
This commit is contained in:
@@ -51,6 +51,13 @@ static DB_LOCK: Lazy<Mutex<()>> = Lazy::new(|| Mutex::new(()));
|
||||
|
||||
const TEST_TENANT_NAME: &str = "test_tenant";
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub enum TestUserRole {
|
||||
Owner,
|
||||
Member,
|
||||
WebDav,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Clone)]
|
||||
pub struct StoredObject {
|
||||
@@ -241,9 +248,8 @@ impl TestApp {
|
||||
Ok(format!("{}{}", root, key))
|
||||
}
|
||||
|
||||
pub async fn insert_user(&self, username: &str, _password: &str, role: &str) -> Result<Uuid> {
|
||||
pub async fn insert_user(&self, username: &str, role: TestUserRole) -> Result<Uuid> {
|
||||
let username = username.to_string();
|
||||
let role = role.to_string();
|
||||
let tenant_id = self.ensure_default_tenant().await?;
|
||||
let user_id = self
|
||||
.with_conn(move |conn| {
|
||||
@@ -256,10 +262,10 @@ impl TestApp {
|
||||
.execute(conn)
|
||||
.context("failed to insert user")?;
|
||||
|
||||
let capabilities = match role.as_str() {
|
||||
"admin" => owner_capabilities(),
|
||||
"webdav" => webdav_capabilities(),
|
||||
_ => user_capabilities(),
|
||||
let capabilities = match role {
|
||||
TestUserRole::Owner => owner_capabilities(),
|
||||
TestUserRole::Member => user_capabilities(),
|
||||
TestUserRole::WebDav => webdav_capabilities(),
|
||||
};
|
||||
|
||||
let capability_set = ensure_capability_set(conn, tenant_id, capabilities)
|
||||
@@ -788,7 +794,7 @@ mod helper_tests {
|
||||
|
||||
let username = "helper-login";
|
||||
let password = "irrelevant";
|
||||
app.insert_user(username, password, "admin").await?;
|
||||
app.insert_user(username, TestUserRole::Owner).await?;
|
||||
|
||||
let (access, refresh, refresh_id) = app.create_session(username).await?;
|
||||
assert!(!access.is_empty(), "access token should not be empty");
|
||||
@@ -812,7 +818,7 @@ mod helper_tests {
|
||||
let app = TestApp::new().await?;
|
||||
let username = "helper-passkey";
|
||||
let password = "unused";
|
||||
let user_id = app.insert_user(username, password, "admin").await?;
|
||||
let user_id = app.insert_user(username, TestUserRole::Owner).await?;
|
||||
|
||||
let passkey_id = app.insert_passkey(user_id, Some("Laptop")).await?;
|
||||
assert_ne!(passkey_id, Uuid::nil());
|
||||
|
||||
Reference in New Issue
Block a user