Skip to content

Commit 9680fc3

Browse files
committed
test: Test that the skip_auth option works correctly
1 parent 422f925 commit 9680fc3

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

crates/matrix-sdk/tests/integration/client.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1527,6 +1527,46 @@ async fn test_server_vendor_info() {
15271527
assert_eq!(server_info.version, "1.70.0");
15281528
}
15291529

1530+
#[async_test]
1531+
async fn test_server_version_without_auth() {
1532+
let server = MatrixMockServer::new().await;
1533+
let client = server.client_builder().build().await;
1534+
1535+
// If we provide an access token, we encounter a failure, likely because the
1536+
// token has expired.
1537+
Mock::given(method("GET"))
1538+
.and(path_regex(r"^/_matrix/client/versions"))
1539+
.and(header("authorization", "Bearer 1234"))
1540+
.respond_with(ResponseTemplate::new(401))
1541+
.mount(server.server())
1542+
.await;
1543+
1544+
// If we do not provide an access token, all is fine as the endpoint does not
1545+
// require one.
1546+
Mock::given(method("GET"))
1547+
.and(path_regex(r"^/_matrix/client/versions"))
1548+
.respond_with(ResponseTemplate::new(200).set_body_json(json!({
1549+
"versions": [
1550+
"r0.0.1",
1551+
"v1.1"
1552+
]
1553+
})))
1554+
.mount(server.server())
1555+
.await;
1556+
1557+
let request_config = RequestConfig::new().disable_retry();
1558+
client
1559+
.fetch_server_versions(Some(request_config))
1560+
.await
1561+
.expect_err("We should fail here since we provided an auth token.");
1562+
1563+
let request_config = RequestConfig::new().disable_retry().skip_auth();
1564+
client
1565+
.fetch_server_versions(Some(request_config))
1566+
.await
1567+
.expect("We should not fail here since we did not provide an auth token.");
1568+
}
1569+
15301570
#[async_test]
15311571
async fn test_server_vendor_info_with_missing_fields() {
15321572
let server = MatrixMockServer::new().await;

0 commit comments

Comments
 (0)