Skip to content

Commit

Permalink
chore: fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Wei Zhang <kweizh@tabbyml.com>
  • Loading branch information
zwpaper committed Jan 20, 2025
1 parent d691cc0 commit 982b10a
Showing 1 changed file with 70 additions and 3 deletions.
73 changes: 70 additions & 3 deletions ee/tabby-webserver/src/service/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1627,19 +1627,24 @@ mod tests {
let service = test_authentication_service().await;
let id = service
.db
.create_user("test@example.com".into(), None, true, None)
.create_user(
"test@example.com".into(),
password_hash("pass").ok(),
true,
None,
)
.await
.unwrap();

let id = id.as_id();

assert!(service
.update_user_password(&id, None, "newpass")
.update_user_password(&id, Some("pass"), "newpass")
.await
.is_ok());

assert!(service
.update_user_password(&id, None, "newpass2")
.update_user_password(&id, Some("wrong"), "newpass2")
.await
.is_err());

Expand All @@ -1649,6 +1654,68 @@ mod tests {
.is_ok());
}

#[tokio::test]
async fn test_sso_user_forbid_update_password() {
let service = test_authentication_service().await;
let id = service
.db
.create_user("test@example.com".into(), None, true, None)
.await
.unwrap();

let id = id.as_id();

assert!(service
.update_user_password(&id, None, "newpass2")
.await
.is_err());
}

#[tokio::test]
async fn test_sso_user_forbid_update_name() {
let service = test_authentication_service().await;
let id = service
.db
.create_user("test@example.com".into(), None, true, None)
.await
.unwrap();

assert!(service
.update_user_name(&id.as_id(), "newname".into())
.await
.is_err());
}

#[tokio::test]
async fn test_sso_user_forbid_generate_password_reset_url() {
let service = test_authentication_service().await;
let id = service
.db
.create_user("test@example.com".into(), None, true, None)
.await
.unwrap();

assert!(service
.generate_reset_password_url(&id.as_id())
.await
.is_err());
}

#[tokio::test]
async fn test_sso_user_forbid_request_password_reset_email() {
let service = test_authentication_service().await;
let id = service
.db
.create_user("test@example.com".into(), None, true, None)
.await
.unwrap();

assert!(service
.request_password_reset_email("test@example.com".into())
.await
.is_err());
}

#[tokio::test]
async fn test_cannot_reset_same_password() {
let (service, _mail) = test_authentication_service_with_mail().await;
Expand Down

0 comments on commit 982b10a

Please sign in to comment.