Skip to main content

mas_router/
lib.rs

1// Copyright 2025, 2026 Element Creations Ltd.
2// Copyright 2024, 2025 New Vector Ltd.
3// Copyright 2022-2024 The Matrix.org Foundation C.I.C.
4//
5// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
6// Please see LICENSE files in the repository root for full details.
7
8pub(crate) mod endpoints;
9pub(crate) mod traits;
10mod url_builder;
11
12pub use self::{endpoints::*, traits::Route, url_builder::UrlBuilder};
13
14#[cfg(test)]
15mod tests {
16    use std::borrow::Cow;
17
18    use ulid::Ulid;
19    use url::Url;
20
21    use super::*;
22
23    #[test]
24    fn test_relative_urls() {
25        assert_eq!(
26            OidcConfiguration.path_and_query(),
27            Cow::Borrowed("/.well-known/openid-configuration")
28        );
29        assert_eq!(Index.path_and_query(), Cow::Borrowed("/"));
30        assert_eq!(
31            Login::and_continue_grant(Ulid::nil()).path_and_query(),
32            Cow::Borrowed("/login?kind=continue_authorization_grant&id=00000000000000000000000000")
33        );
34    }
35
36    #[test]
37    fn test_register_urls() {
38        assert_eq!(
39            Register::default().path_and_query(),
40            Cow::Borrowed("/register")
41        );
42        assert_eq!(
43            Register::default()
44                .with_token("a token&more".to_owned())
45                .path_and_query(),
46            Cow::Borrowed("/register?token=a+token%26more")
47        );
48        assert_eq!(
49            Register::and_continue_grant(Ulid::nil())
50                .with_token("invite".to_owned())
51                .path_and_query(),
52            Cow::Borrowed(
53                "/register?token=invite&kind=continue_authorization_grant&id=00000000000000000000000000"
54            )
55        );
56    }
57
58    #[test]
59    fn test_absolute_urls() {
60        let base = Url::try_from("https://example.com/").unwrap();
61        assert_eq!(Index.absolute_url(&base).as_str(), "https://example.com/");
62        assert_eq!(
63            OidcConfiguration.absolute_url(&base).as_str(),
64            "https://example.com/.well-known/openid-configuration"
65        );
66    }
67}