Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

don't borrow references immediately dereferenced #341

Merged
merged 1 commit into from
Aug 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- add test to confirm a `base_url` can include a path and be joined with a relative path
- fix documentation typo
- introduce `pretty` log format for `--error-format`, `--debug-format`, `--request-format`, and `--task-format`
- clippy cleanups: don't borrow references that are immediately dereferenced by the compiler: https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow

## 0.13.0 July 19, 2021
- enable [`gzip`](https://docs.rs/reqwest/*/reqwest/struct.ClientBuilder.html#method.gzip) support and set Accept-Encoding header by default in the client; disable with `--no-gzip` or `GooseDefault::NoGzip`
Expand Down
20 changes: 10 additions & 10 deletions examples/drupal_loadtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ async fn drupal_loadtest_front_page(user: &GooseUser) -> GooseTaskResult {
return user.set_failure(
&format!("front_page: failed to parse page: {}", e),
&mut goose.request,
Some(&headers),
Some(headers),
None,
);
}
Expand Down Expand Up @@ -167,7 +167,7 @@ async fn drupal_loadtest_login(user: &GooseUser) -> GooseTaskResult {
return user.set_failure(
"login: no form_build_id on page: /user page",
&mut goose.request,
Some(&headers),
Some(headers),
Some(&html),
);
}
Expand All @@ -193,7 +193,7 @@ async fn drupal_loadtest_login(user: &GooseUser) -> GooseTaskResult {
return user.set_failure(
&format!("login: unexpected error when loading /user page: {}", e),
&mut goose.request,
Some(&headers),
Some(headers),
None,
);
}
Expand Down Expand Up @@ -239,7 +239,7 @@ async fn drupal_loadtest_post_comment(user: &GooseUser) -> GooseTaskResult {
return user.set_failure(
&format!("post_comment: no form_build_id found on {}", &node_path),
&mut goose.request,
Some(&headers),
Some(headers),
Some(&html),
);
}
Expand All @@ -254,7 +254,7 @@ async fn drupal_loadtest_post_comment(user: &GooseUser) -> GooseTaskResult {
return user.set_failure(
&format!("post_comment: no form_token found on {}", &node_path),
&mut goose.request,
Some(&headers),
Some(headers),
Some(&html),
);
}
Expand All @@ -269,7 +269,7 @@ async fn drupal_loadtest_post_comment(user: &GooseUser) -> GooseTaskResult {
return user.set_failure(
&format!("post_comment: no form_id found on {}", &node_path),
&mut goose.request,
Some(&headers),
Some(headers),
Some(&html),
);
}
Expand All @@ -283,15 +283,15 @@ async fn drupal_loadtest_post_comment(user: &GooseUser) -> GooseTaskResult {
&form_id[1], &form_build_id[1], &form_token[1]
),
Some(&goose.request),
Some(&headers),
Some(headers),
Some(&html),
);
*/

let comment_body = "this is a test comment body";
let params = [
("subject", "this is a test comment subject"),
("comment_body[und][0][value]", &comment_body),
("comment_body[und][0][value]", comment_body),
("comment_body[und][0][format]", "filtered_html"),
("form_build_id", &form_build_id[1]),
("form_token", &form_token[1]),
Expand All @@ -316,7 +316,7 @@ async fn drupal_loadtest_post_comment(user: &GooseUser) -> GooseTaskResult {
return user.set_failure(
&format!("post_comment: no comment showed up after posting to {}", &comment_path),
&mut goose.request,
Some(&headers),
Some(headers),
Some(&html),
);
}
Expand All @@ -330,7 +330,7 @@ async fn drupal_loadtest_post_comment(user: &GooseUser) -> GooseTaskResult {
&comment_path, e
),
&mut goose.request,
Some(&headers),
Some(headers),
None,
);
}
Expand Down
18 changes: 9 additions & 9 deletions examples/umami/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub async fn log_in(user: &GooseUser) -> GooseTaskResult {
return user.set_failure(
&format!("{}: title not found: {}", &goose.request.raw.url, title),
&mut goose.request,
Some(&headers),
Some(headers),
Some(&html),
);
}
Expand All @@ -53,7 +53,7 @@ pub async fn log_in(user: &GooseUser) -> GooseTaskResult {
return user.set_failure(
&format!("{}: no form_build_id on page", goose.request.raw.url),
&mut goose.request,
Some(&headers),
Some(headers),
Some(&html),
);
}
Expand All @@ -77,7 +77,7 @@ pub async fn log_in(user: &GooseUser) -> GooseTaskResult {
logged_in_user.request.final_url
),
&mut logged_in_user.request,
Some(&headers),
Some(headers),
None,
);
}
Expand All @@ -86,7 +86,7 @@ pub async fn log_in(user: &GooseUser) -> GooseTaskResult {
return user.set_failure(
&format!("{}: failed to parse page: {}", goose.request.raw.url, e),
&mut goose.request,
Some(&headers),
Some(headers),
None,
);
}
Expand Down Expand Up @@ -133,7 +133,7 @@ pub async fn edit_article(user: &GooseUser) -> GooseTaskResult {
return user.set_failure(
&format!("{}: title not found: {}", &goose.request.raw.url, title),
&mut goose.request,
Some(&headers),
Some(headers),
Some(&html),
);
}
Expand All @@ -148,7 +148,7 @@ pub async fn edit_article(user: &GooseUser) -> GooseTaskResult {
return user.set_failure(
&format!("{}: no form_build_id on page", goose.request.raw.url),
&mut goose.request,
Some(&headers),
Some(headers),
Some(&html),
);
}
Expand All @@ -157,7 +157,7 @@ pub async fn edit_article(user: &GooseUser) -> GooseTaskResult {
return user.set_failure(
&format!("{}: no form_token on page", goose.request.raw.url),
&mut goose.request,
Some(&headers),
Some(headers),
Some(&html),
);
}
Expand All @@ -179,7 +179,7 @@ pub async fn edit_article(user: &GooseUser) -> GooseTaskResult {
return user.set_failure(
&format!("{}: saving article failed", saved_article.request.final_url),
&mut saved_article.request,
Some(&headers),
Some(headers),
None,
);
}
Expand All @@ -188,7 +188,7 @@ pub async fn edit_article(user: &GooseUser) -> GooseTaskResult {
return user.set_failure(
&format!("{}: failed to parse page: {}", goose.request.raw.url, e),
&mut goose.request,
Some(&headers),
Some(headers),
None,
);
}
Expand Down
34 changes: 17 additions & 17 deletions examples/umami/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ pub fn random_words(count: usize, english: bool) -> Vec<String> {
];
let content_type = content_types.choose(&mut rand::thread_rng());
// Then randomly select a node of this content type.
let nodes = get_nodes(&content_type.unwrap());
let nodes = get_nodes(content_type.unwrap());
let page = nodes.choose(&mut rand::thread_rng());
// Randomly select a word from the title to use in our search.
let title = if english {
Expand Down Expand Up @@ -428,7 +428,7 @@ pub async fn load_static_elements(user: &GooseUser, html: &str) {
// @TODO: parse HTML5 srcset= also
let image = Regex::new(r#"src="(.*?)""#).unwrap();
let mut urls = Vec::new();
for url in image.captures_iter(&html) {
for url in image.captures_iter(html) {
if url[1].starts_with("/sites") || url[1].starts_with("/core") {
urls.push(url[1].to_string());
}
Expand All @@ -437,7 +437,7 @@ pub async fn load_static_elements(user: &GooseUser, html: &str) {
// Use a regular expression to find all href=<foo> in the HTML, where foo
// is the URL to css assets.
let css = Regex::new(r#"href="(/sites/default/files/css/.*?)""#).unwrap();
for url in css.captures_iter(&html) {
for url in css.captures_iter(html) {
urls.push(url[1].to_string());
}

Expand All @@ -460,11 +460,11 @@ pub async fn validate_and_load_static_assets(
let headers = &response.headers().clone();
match response.text().await {
Ok(html) => {
if !valid_title(&html, &title) {
if !valid_title(&html, title) {
return user.set_failure(
&format!("{}: title not found: {}", goose.request.raw.url, title),
&mut goose.request,
Some(&headers),
Some(headers),
Some(&html),
);
}
Expand All @@ -475,7 +475,7 @@ pub async fn validate_and_load_static_assets(
return user.set_failure(
&format!("{}: failed to parse page: {}", goose.request.raw.url, e),
&mut goose.request,
Some(&headers),
Some(headers),
None,
);
}
Expand All @@ -497,7 +497,7 @@ pub async fn validate_and_load_static_assets(
/// Use regular expression to get the value of a named form element.
pub fn get_form_value(html: &str, name: &str) -> Option<String> {
let re = Regex::new(&format!(r#"name="{}" value=['"](.*?)['"]"#, name)).unwrap();
re.captures(&html).map(|value| value[1].to_string())
re.captures(html).map(|value| value[1].to_string())
}

/// Anonymously load the contact form and POST feedback. The english boolean flag indicates
Expand Down Expand Up @@ -531,7 +531,7 @@ pub async fn anonymous_contact_form(user: &GooseUser, english: bool) -> GooseTas
return user.set_failure(
&format!("{}: title not found: {}", goose.request.raw.url, title),
&mut goose.request,
Some(&headers),
Some(headers),
Some(&html),
);
}
Expand All @@ -546,7 +546,7 @@ pub async fn anonymous_contact_form(user: &GooseUser, english: bool) -> GooseTas
return user.set_failure(
&format!("{}: no form_build_id on page", goose.request.raw.url),
&mut goose.request,
Some(&headers),
Some(headers),
Some(&html),
);
}
Expand All @@ -572,7 +572,7 @@ pub async fn anonymous_contact_form(user: &GooseUser, english: bool) -> GooseTas
return user.set_failure(
&format!("{}: failed to parse page: {}", goose.request.raw.url, e),
&mut goose.request,
Some(&headers),
Some(headers),
None,
);
}
Expand Down Expand Up @@ -616,7 +616,7 @@ pub async fn anonymous_contact_form(user: &GooseUser, english: bool) -> GooseTas
return user.set_failure(
&format!("{}: failed to parse page: {}", goose.request.raw.url, e),
&mut goose.request,
Some(&headers),
Some(headers),
None,
);
}
Expand Down Expand Up @@ -663,7 +663,7 @@ pub async fn search(user: &GooseUser, english: bool) -> GooseTaskResult {
return user.set_failure(
&format!("{}: title not found: {}", goose.request.raw.url, title),
&mut goose.request,
Some(&headers),
Some(headers),
Some(&html),
);
}
Expand All @@ -678,7 +678,7 @@ pub async fn search(user: &GooseUser, english: bool) -> GooseTaskResult {
return user.set_failure(
&format!("{}: no form_build_id on page", goose.request.raw.url),
&mut goose.request,
Some(&headers),
Some(headers),
Some(&html),
);
}
Expand All @@ -702,7 +702,7 @@ pub async fn search(user: &GooseUser, english: bool) -> GooseTaskResult {
return user.set_failure(
&format!("{}: search didn't redirect", search_form.request.final_url),
&mut search_form.request,
Some(&headers),
Some(headers),
None,
);
}
Expand All @@ -711,7 +711,7 @@ pub async fn search(user: &GooseUser, english: bool) -> GooseTaskResult {
return user.set_failure(
&format!("{}: failed to parse page: {}", goose.request.raw.url, e),
&mut goose.request,
Some(&headers),
Some(headers),
None,
);
}
Expand Down Expand Up @@ -740,7 +740,7 @@ pub async fn search(user: &GooseUser, english: bool) -> GooseTaskResult {
goose.request.raw.url, &search_phrase
),
&mut goose.request,
Some(&headers),
Some(headers),
Some(&html),
);
}
Expand All @@ -752,7 +752,7 @@ pub async fn search(user: &GooseUser, english: bool) -> GooseTaskResult {
return user.set_failure(
&format!("{}: failed to parse page: {}", goose.request.raw.url, e),
&mut goose.request,
Some(&headers),
Some(headers),
None,
);
}
Expand Down
2 changes: 1 addition & 1 deletion examples/umami/english.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub async fn page_by_nid(user: &GooseUser) -> GooseTaskResult {
];
let content_type = content_types.choose(&mut rand::thread_rng());
// Then randomly select a node of this content type.
let nodes = common::get_nodes(&content_type.unwrap());
let nodes = common::get_nodes(content_type.unwrap());
let page = nodes.choose(&mut rand::thread_rng());
// Load the page by nid instead of by URL.
let goose = user
Expand Down
8 changes: 4 additions & 4 deletions src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ impl GooseControllerState {
// Extract the command string in a protocol-specific way.
if let Ok(command_string) = self.get_command_string(buf).await {
// Extract the command and value in a generic way.
if let Ok(request_message) = self.get_match(&command_string.trim()).await {
if let Ok(request_message) = self.get_match(command_string.trim()).await {
// Act on the commmand received.
if self.execute_command(&mut socket, request_message).await {
// If execute_command returns true, it's time to exit.
Expand Down Expand Up @@ -411,7 +411,7 @@ impl GooseControllerState {
// Extract the command string in a protocol-specific way.
if let Ok(command_string) = self.get_command_string(data).await {
// Extract the command and value in a generic way.
if let Ok(request_message) = self.get_match(&command_string.trim()).await {
if let Ok(request_message) = self.get_match(command_string.trim()).await {
if self.execute_command(&mut ws_sender, request_message).await {
// If execute_command() returns true, it's time to exit.
info!(
Expand Down Expand Up @@ -441,7 +441,7 @@ impl GooseControllerState {

// Both Controllers use a common function to identify commands.
async fn get_match(&self, command_string: &str) -> Result<GooseControllerRequestMessage, ()> {
let matches = self.commands.matches(&command_string);
let matches = self.commands.matches(command_string);
if matches.matched(GooseControllerCommand::Help as usize) {
Ok(GooseControllerRequestMessage {
command: GooseControllerCommand::Help,
Expand Down Expand Up @@ -1253,7 +1253,7 @@ impl GooseAttack {
);
// Use expect() as Controller uses regex to validate this is an integer.
self.configuration.users = Some(
usize::from_str(&users)
usize::from_str(users)
.expect("failed to convert string to usize"),
);
self.reply_to_controller(
Expand Down
2 changes: 1 addition & 1 deletion src/goose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1435,7 +1435,7 @@ impl GooseUser {
None => b"",
};
// Convert the bytes into a &str if valid utf8.
str::from_utf8(&body_bytes).unwrap_or("")
str::from_utf8(body_bytes).unwrap_or("")
} else {
""
};
Expand Down
Loading