You've already forked authentication-service
mirror of
https://github.com/matrix-org/matrix-authentication-service.git
synced 2025-07-31 09:24:31 +03:00
Make the upstream provider URL better display & fix test
This commit is contained in:
@ -388,15 +388,11 @@ mod test {
|
|||||||
let response = state.request(Request::get("/login").empty()).await;
|
let response = state.request(Request::get("/login").empty()).await;
|
||||||
response.assert_status(StatusCode::OK);
|
response.assert_status(StatusCode::OK);
|
||||||
response.assert_header_value(CONTENT_TYPE, "text/html; charset=utf-8");
|
response.assert_header_value(CONTENT_TYPE, "text/html; charset=utf-8");
|
||||||
assert!(response
|
assert!(response.body().contains(&escape_html("first.com/")));
|
||||||
.body()
|
|
||||||
.contains(&escape_html(&first_provider.issuer)));
|
|
||||||
assert!(response
|
assert!(response
|
||||||
.body()
|
.body()
|
||||||
.contains(&escape_html(&first_provider_login.path_and_query())));
|
.contains(&escape_html(&first_provider_login.path_and_query())));
|
||||||
assert!(response
|
assert!(response.body().contains(&escape_html("second.com/")));
|
||||||
.body()
|
|
||||||
.contains(&escape_html(&second_provider.issuer)));
|
|
||||||
assert!(response
|
assert!(response
|
||||||
.body()
|
.body()
|
||||||
.contains(&escape_html(&second_provider_login.path_and_query())));
|
.contains(&escape_html(&second_provider_login.path_and_query())));
|
||||||
|
@ -118,10 +118,10 @@ fn filter_to_params(params: &Value, kwargs: Kwargs) -> Result<String, Error> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Filter which simplifies a URL to its domain name for HTTP(S) URLs
|
/// Filter which simplifies a URL to its domain name for HTTP(S) URLs
|
||||||
fn filter_simplify_url(url: &str) -> String {
|
fn filter_simplify_url(url: &str, kwargs: Kwargs) -> Result<String, minijinja::Error> {
|
||||||
// Do nothing if the URL is not valid
|
// Do nothing if the URL is not valid
|
||||||
let Ok(mut url) = Url::from_str(url) else {
|
let Ok(mut url) = Url::from_str(url) else {
|
||||||
return url.to_owned();
|
return Ok(url.to_owned());
|
||||||
};
|
};
|
||||||
|
|
||||||
// Always at least remove the query parameters and fragment
|
// Always at least remove the query parameters and fragment
|
||||||
@ -130,15 +130,26 @@ fn filter_simplify_url(url: &str) -> String {
|
|||||||
|
|
||||||
// Do nothing else for non-HTTPS URLs
|
// Do nothing else for non-HTTPS URLs
|
||||||
if url.scheme() != "https" {
|
if url.scheme() != "https" {
|
||||||
return url.to_string();
|
return Ok(url.to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let keep_path = kwargs.get::<Option<bool>>("keep_path")?.unwrap_or_default();
|
||||||
|
kwargs.assert_all_used()?;
|
||||||
|
|
||||||
// Only return the domain name
|
// Only return the domain name
|
||||||
let Some(domain) = url.domain() else {
|
let Some(domain) = url.domain() else {
|
||||||
return url.to_string();
|
return Ok(url.to_string());
|
||||||
};
|
};
|
||||||
|
|
||||||
domain.to_owned()
|
if keep_path {
|
||||||
|
Ok(format!(
|
||||||
|
"{domain}{path}",
|
||||||
|
domain = domain,
|
||||||
|
path = url.path(),
|
||||||
|
))
|
||||||
|
} else {
|
||||||
|
Ok(domain.to_owned())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum ParamsWhere {
|
enum ParamsWhere {
|
||||||
|
@ -79,7 +79,7 @@ limitations under the License.
|
|||||||
{% set params = next["params"] | default({}) | to_params(prefix="?") %}
|
{% set params = next["params"] | default({}) | to_params(prefix="?") %}
|
||||||
{% for provider in providers %}
|
{% for provider in providers %}
|
||||||
<a class="cpd-button" data-kind="secondary" data-size="lg" href="{{ ('/upstream/authorize/' ~ provider.id ~ params) | prefix_url }}">
|
<a class="cpd-button" data-kind="secondary" data-size="lg" href="{{ ('/upstream/authorize/' ~ provider.id ~ params) | prefix_url }}">
|
||||||
{{ _("mas.login.continue_with_provider", provider=provider.issuer | simplify_url) }}
|
{{ _("mas.login.continue_with_provider", provider=provider.issuer | simplify_url(keep_path=True)) }}
|
||||||
</a>
|
</a>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -193,7 +193,7 @@
|
|||||||
},
|
},
|
||||||
"continue_with_provider": "Continue with %(provider)s",
|
"continue_with_provider": "Continue with %(provider)s",
|
||||||
"@continue_with_provider": {
|
"@continue_with_provider": {
|
||||||
"context": "pages/login.html:82:13-91",
|
"context": "pages/login.html:82:13-107",
|
||||||
"description": "Button to log in with an upstream provider"
|
"description": "Button to log in with an upstream provider"
|
||||||
},
|
},
|
||||||
"description": "Please sign in to continue:",
|
"description": "Please sign in to continue:",
|
||||||
|
Reference in New Issue
Block a user