add token infrastructure: service_users table, localpart helper
new SQLite table service_users maps OIDC identities (matrix localpart) to service-specific usernames, handling auth boundary mismatches. localpart() extracts the username from a matrix user ID. delete_all_conversations() added for bulk reset after agent recreation. all delete_* methods now log failures instead of silently discarding. removed dead user_tokens table (tokens now live in vault).
This commit is contained in:
@@ -16,6 +16,14 @@ pub struct ResponseContext {
|
||||
pub room_id: String,
|
||||
}
|
||||
|
||||
/// Extract the localpart from a Matrix user ID.
|
||||
///
|
||||
/// `@sienna:sunbeam.pt` → `sienna`
|
||||
pub fn localpart(matrix_user_id: &str) -> &str {
|
||||
let stripped = matrix_user_id.strip_prefix('@').unwrap_or(matrix_user_id);
|
||||
stripped.split(':').next().unwrap_or(stripped)
|
||||
}
|
||||
|
||||
/// Derive a portable user ID from a Matrix user ID.
|
||||
///
|
||||
/// `@sienna:sunbeam.pt` → `sienna@sunbeam.pt`
|
||||
@@ -53,4 +61,24 @@ mod tests {
|
||||
"user@server:8448"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_localpart_standard() {
|
||||
assert_eq!(localpart("@sienna:sunbeam.pt"), "sienna");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_localpart_no_at_prefix() {
|
||||
assert_eq!(localpart("sienna:sunbeam.pt"), "sienna");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_localpart_no_colon() {
|
||||
assert_eq!(localpart("@sienna"), "sienna");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_localpart_complex() {
|
||||
assert_eq!(localpart("@user.name:matrix.org"), "user.name");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user