You've already forked authentication-service
mirror of
https://github.com/matrix-org/matrix-authentication-service.git
synced 2025-08-09 04:22:45 +03:00
Implement a mocked HomeserverConnection which keeps state around
This commit is contained in:
@@ -23,7 +23,7 @@ use headers::{Authorization, ContentType, HeaderMapExt, HeaderName};
|
||||
use hyper::{header::CONTENT_TYPE, Request, Response, StatusCode};
|
||||
use mas_axum_utils::http_client_factory::HttpClientFactory;
|
||||
use mas_keystore::{Encrypter, JsonWebKey, JsonWebKeySet, Keystore, PrivateKey};
|
||||
use mas_matrix::{HomeserverConnection, MatrixUser, ProvisionRequest};
|
||||
use mas_matrix::{HomeserverConnection, MatrixUser, MockHomeserverConnection, ProvisionRequest};
|
||||
use mas_policy::PolicyFactory;
|
||||
use mas_router::{SimpleRoute, UrlBuilder};
|
||||
use mas_storage::{clock::MockClock, BoxClock, BoxRepository, BoxRng, Repository};
|
||||
@@ -69,40 +69,6 @@ pub(crate) struct TestState {
|
||||
pub rng: Arc<Mutex<ChaChaRng>>,
|
||||
}
|
||||
|
||||
/// A Mock implementation of a [`HomeserverConnection`], which never fails and
|
||||
/// doesn't do anything.
|
||||
struct MockHomeserverConnection {
|
||||
homeserver: String,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl HomeserverConnection for MockHomeserverConnection {
|
||||
type Error = anyhow::Error;
|
||||
|
||||
fn homeserver(&self) -> &str {
|
||||
&self.homeserver
|
||||
}
|
||||
|
||||
async fn query_user(&self, _mxid: &str) -> Result<MatrixUser, Self::Error> {
|
||||
Ok(MatrixUser {
|
||||
displayname: None,
|
||||
avatar_url: None,
|
||||
})
|
||||
}
|
||||
|
||||
async fn provision_user(&self, _request: &ProvisionRequest) -> Result<bool, Self::Error> {
|
||||
Ok(false)
|
||||
}
|
||||
|
||||
async fn create_device(&self, _mxid: &str, _device_id: &str) -> Result<(), Self::Error> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn delete_device(&self, _mxid: &str, _device_id: &str) -> Result<(), Self::Error> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl TestState {
|
||||
/// Create a new test state from the given database pool
|
||||
pub async fn from_pool(pool: PgPool) -> Result<Self, anyhow::Error> {
|
||||
@@ -145,9 +111,7 @@ impl TestState {
|
||||
)
|
||||
.await?;
|
||||
|
||||
let homeserver_connection = MockHomeserverConnection {
|
||||
homeserver: "example.com".to_owned(),
|
||||
};
|
||||
let homeserver_connection = MockHomeserverConnection::new("example.com");
|
||||
|
||||
let policy_factory = Arc::new(policy_factory);
|
||||
|
||||
|
Reference in New Issue
Block a user