Skip to content

refactor(sdk): Convert some tests to the MatrixMockServer and MockClientBuilder APIs #5351

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/matrix-sdk/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1177,7 +1177,7 @@ mod tests {

#[async_test]
async fn test_dont_ignore_oneself() {
let client = MockClientBuilder::new("https://example.org".to_owned()).build().await;
let client = MockClientBuilder::new(None).build().await;

// It's forbidden to ignore the logged-in user.
assert_matches!(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,7 @@ mod tests {
// Create a client that will use sqlite databases.

let tmp_dir = tempfile::tempdir()?;
let client = MockClientBuilder::new("https://example.org".to_owned())
.sqlite_store(&tmp_dir)
.unlogged()
.build()
.await;
let client = MockClientBuilder::new(None).sqlite_store(&tmp_dir).unlogged().build().await;

let tokens = mock_session_tokens_with_refresh();

Expand Down
12 changes: 5 additions & 7 deletions crates/matrix-sdk/src/authentication/oauth/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,7 @@ async fn test_high_level_login_cancellation() -> anyhow::Result<()> {

assert_eq!(oauth.client_id().map(|id| id.as_str()), Some("test_client_id"));

check_authorization_url(&authorization_data, &oauth, &server.server().uri(), None, None, None)
.await;
check_authorization_url(&authorization_data, &oauth, &server.uri(), None, None, None).await;

// When completing login with a cancellation callback.
redirect_uri.set_query(Some(&format!(
Expand Down Expand Up @@ -206,8 +205,7 @@ async fn test_high_level_login_invalid_state() -> anyhow::Result<()> {

assert_eq!(oauth.client_id().map(|id| id.as_str()), Some("test_client_id"));

check_authorization_url(&authorization_data, &oauth, &server.server().uri(), None, None, None)
.await;
check_authorization_url(&authorization_data, &oauth, &server.uri(), None, None, None).await;

// When completing login with an old/tampered state.
redirect_uri.set_query(Some("code=42&state=imposter_alert"));
Expand All @@ -228,7 +226,7 @@ async fn test_high_level_login_invalid_state() -> anyhow::Result<()> {
#[async_test]
async fn test_login_url() -> anyhow::Result<()> {
let server = MatrixMockServer::new().await;
let server_uri = server.server().uri();
let server_uri = server.uri();

let oauth_server = server.oauth();
oauth_server.mock_server_metadata().ok().expect(3).mount().await;
Expand Down Expand Up @@ -483,7 +481,7 @@ async fn test_finish_login() -> anyhow::Result<()> {

#[async_test]
async fn test_oauth_session() -> anyhow::Result<()> {
let client = MockClientBuilder::new("https://example.org".to_owned()).unlogged().build().await;
let client = MockClientBuilder::new(None).unlogged().build().await;
let oauth = client.oauth();

let tokens = mock_session_tokens_with_refresh();
Expand All @@ -509,7 +507,7 @@ async fn test_oauth_session() -> anyhow::Result<()> {
#[async_test]
async fn test_insecure_clients() -> anyhow::Result<()> {
let server = MatrixMockServer::new().await;
let server_url = server.server().uri();
let server_url = server.uri();

server.mock_well_known().ok().expect(1..).named("well_known").mount().await;
server.mock_versions().ok().expect(1..).named("versions").mount().await;
Expand Down
Loading
Loading