mirror of
https://github.com/Blah-IM/blahrs.git
synced 2025-07-10 08:05:33 +00:00
feat(webapi): expose server metadata
This commit is contained in:
parent
8551540798
commit
fa14844d0d
4 changed files with 88 additions and 4 deletions
|
@ -15,7 +15,7 @@ use blah_types::msg::{
|
|||
MemberPermission, RichText, RoomAdminOp, RoomAdminPayload, RoomAttrs, ServerPermission,
|
||||
SignedChatMsg, SignedChatMsgWithId, UserRegisterPayload, WithMsgId,
|
||||
};
|
||||
use blah_types::server::{RoomMetadata, X_BLAH_DIFFICULTY, X_BLAH_NONCE};
|
||||
use blah_types::server::{RoomMetadata, ServerMetadata, X_BLAH_DIFFICULTY, X_BLAH_NONCE};
|
||||
use blah_types::{Id, SignExt, Signed, UserKey};
|
||||
use blahd::{AppState, Database, RoomList, RoomMsgs};
|
||||
use ed25519_dalek::SigningKey;
|
||||
|
@ -245,6 +245,10 @@ impl Server {
|
|||
msg.sign_msg(&user.pubkeys.id_key, &user.act_priv).unwrap()
|
||||
}
|
||||
|
||||
async fn get_metadata(&self) -> Result<ServerMetadata> {
|
||||
self.get::<ServerMetadata>("/server", None).await
|
||||
}
|
||||
|
||||
fn create_room(
|
||||
&self,
|
||||
user: &User,
|
||||
|
@ -450,6 +454,15 @@ async fn smoke(server: Server) {
|
|||
assert_eq!(got, exp);
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
#[tokio::test]
|
||||
#[expect(clippy::print_stdout, reason = "allowed in tests for debugging")]
|
||||
async fn server_metadata(server: Server) {
|
||||
let meta = server.get_metadata().await.unwrap();
|
||||
println!("{meta:#?}");
|
||||
assert!(meta.server.starts_with("blahd/"));
|
||||
}
|
||||
|
||||
fn auth(user: &User) -> String {
|
||||
let msg = AuthPayload {}
|
||||
.sign_msg(&user.pubkeys.id_key, &user.act_priv)
|
||||
|
@ -1262,6 +1275,10 @@ unsafe_allow_id_url_single_label = {allow_single_label}
|
|||
};
|
||||
let server = server_with(Database::open(&db_config).unwrap(), &config);
|
||||
|
||||
// Report in capabilities.
|
||||
let meta = server.get_metadata().await.unwrap();
|
||||
assert_eq!(meta.capabilities.allow_public_register, enabled);
|
||||
|
||||
// Returns challenge headers only if registration is enabled.
|
||||
let hdrs = server.get_me(Some(&CAROL)).await.unwrap_err();
|
||||
if enabled {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue