-
-
Notifications
You must be signed in to change notification settings - Fork 189
Add support for Text fragment feature (#1545) #1600
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
base: master
Are you sure you want to change the base?
Changes from 5 commits
7e1e2e1
e3e09d6
1085f7c
584f460
b6d5b5a
4ebb039
c040e3a
6d99f78
aaf9796
68bcd58
e63bd50
61bbb58
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -278,6 +278,9 @@ pub struct ClientBuilder { | |
| /// Enable the checking of fragments in links. | ||
| include_fragments: bool, | ||
|
|
||
| /// Enable the checking of text fragment in a website | ||
| include_text_fragments: bool, | ||
|
|
||
| /// Requests run through this chain where each item in the chain | ||
| /// can modify the request. A chained item can also decide to exit | ||
| /// early and return a status, so that subsequent chain items are | ||
|
|
@@ -391,6 +394,7 @@ impl ClientBuilder { | |
| self.accepted, | ||
| github_client, | ||
| self.require_https, | ||
| self.include_text_fragments, | ||
| self.plugin_request_chain, | ||
| ); | ||
|
|
||
|
|
@@ -665,6 +669,7 @@ mod tests { | |
| // Same, but ignore certificate error | ||
| let res = ClientBuilder::builder() | ||
| .allow_insecure(true) | ||
| .include_text_fragments(true) | ||
| .build() | ||
| .client() | ||
| .unwrap() | ||
|
|
@@ -841,6 +846,65 @@ mod tests { | |
| assert!(res.status().is_unsupported()); | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn test_fragment_directive() { | ||
| let client = ClientBuilder::builder() | ||
| .include_text_fragments(true) | ||
| .build() | ||
| .client() | ||
| .unwrap(); | ||
|
|
||
| // Start only | ||
| println!("testing START only directive..."); | ||
| let res = client.check("https://developer.mozilla.org/en-US/docs/Web/URI/Fragment/Text_fragments#:~:text=without%20relying%20on%20the%20presence%20of%20IDs").await.unwrap(); | ||
| assert!(res.status().is_success()); | ||
|
|
||
| // Start and End | ||
| println!("\ntesting START and END directive..."); | ||
| let res = client.check("https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#:~:text=linked%20URL,defining%20a%20value").await.unwrap(); | ||
| assert!(res.status().is_success()); | ||
|
|
||
| // Prefix and start | ||
| println!("\ntesting Prefix with START..."); | ||
| let res = client | ||
| .check("https://example.com/#:~:text=asking-,for") | ||
| .await | ||
| .unwrap(); | ||
| assert!(res.status().is_success()); | ||
|
|
||
| // start with suffix | ||
| println!("\ntesting start with suffix..."); | ||
|
||
| let res = client.check("https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#:~:text=linked%20URL\'s,-format").await.unwrap(); | ||
| assert!(res.status().is_success()); | ||
|
|
||
| let res = client.check("https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#:~:text=downgrade:-,The%20Referer,be%20sent,-to%20origins").await.unwrap(); | ||
| assert!(res.status().is_success()); | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn test_multiple_directives() { | ||
| let client = ClientBuilder::builder() | ||
| .include_text_fragments(true) | ||
| .build() | ||
| .client() | ||
| .unwrap(); | ||
|
|
||
| let res = client.check("https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#:~:text=causes&text=linked").await.unwrap(); | ||
| assert!(res.status().is_success()); | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn fail_fragment_directive_test() { | ||
| let client = ClientBuilder::builder() | ||
| .include_text_fragments(true) | ||
| .build() | ||
| .client() | ||
| .unwrap(); | ||
|
|
||
| let res = client.check("https://developer.mozilla.org/en-US/docs/Web/URI/Fragment/Text_fragments#:~:text=without%20relying%20on%20the%20presence%20of%20DIs").await.unwrap(); | ||
| assert!(res.status().is_error()); | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn test_max_redirects() { | ||
| let mock_server = wiremock::MockServer::start().await; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can move that into a function/method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some tests for that part would also be nice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the code is modified to move this into a separate function - as well, bulk of the logic is abstracted at the textfrag crate itself so that the websitechecker will deal with only error responses from the text fragment checker function.