client: Ensure query string values are URL-encoded (#17235)

This PR fixes an issue where the query string values weren't URL-encoded
when authenticating as an admin in development.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2024-09-01 09:53:34 -04:00 committed by GitHub
parent b386b6c237
commit 54ac963bcd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1456,16 +1456,32 @@ impl Client {
user user
}; };
let query_params = [
("github_login", &github_user.login),
("github_user_id", &github_user.id.to_string()),
(
"github_user_created_at",
&github_user.created_at.to_rfc3339(),
),
];
// Use the collab server's admin API to retrieve the ID // Use the collab server's admin API to retrieve the ID
// of the impersonated user. // of the impersonated user.
let mut url = self.rpc_url(http.clone(), None).await?; let mut url = self.rpc_url(http.clone(), None).await?;
url.set_path("/user"); url.set_path("/user");
url.set_query(Some(&format!( url.set_query(Some(
"github_login={login}&github_user_id={id}&github_user_created_at={created_at}", &query_params
login = github_user.login, .iter()
id = github_user.id, .map(|(key, value)| {
created_at = github_user.created_at.to_rfc3339() format!(
))); "{}={}",
key,
url::form_urlencoded::byte_serialize(value.as_bytes()).collect::<String>()
)
})
.collect::<Vec<String>>()
.join("&"),
));
let request: http_client::Request<AsyncBody> = Request::get(url.as_str()) let request: http_client::Request<AsyncBody> = Request::get(url.as_str())
.header("Authorization", format!("token {api_token}")) .header("Authorization", format!("token {api_token}"))
.body("".into())?; .body("".into())?;