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

feat: add capability to handle http requests with repeated slashes #258

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

dxfg
Copy link

@dxfg dxfg commented Aug 10, 2022

WIP PR to add capability to handle http requests w/ repeated slashes.

@dxfg dxfg force-pushed the feat/slashes branch 3 times, most recently from cdde52e to f8c3a08 Compare August 11, 2022 17:55
Co-authored-by: Roman <[email protected]>

Signed-off by: Sriram <[email protected]>

Signed-off-by: Sriram <[email protected]>
Signed-off-by: Sriram <[email protected]>
@dxfg dxfg marked this pull request as ready for review August 12, 2022 14:05
@dxfg dxfg requested review from a team and bstrie as code owners August 12, 2022 14:05
Copy link
Member

@rjzak rjzak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

Copy link
Member

@rvolosatovs rvolosatovs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

implementation looks overall, but I don't see how the tests are relevant for the task at hand.

You should be using the actual URLs that this function handles, e.g. https://store.profian.com//api////v0.2.0////examples//////fibonacci-rust////_tag///0.2.0//tree///PATH//IN/TREE

Comment on lines +125 to +126
.trim_start_matches('/')
.trim_end_matches('/')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is redundant due to the split and the filter. You'll never get slashes here.
BTW, just FYI, trim_matches trims from both sides

.uri("https://www.rust-lang.org/")
.header("User-Agent", "my-awesome-agent/1.0")
.body(hyper::Body::empty());
println!("{:?}", request);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant print statement

let res = handle(request.unwrap()).await;

// Temporary print to ensure test is working as intended.
// println!("{}", res.into_response().status());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid commented-out code

Comment on lines +176 to +230

#[async_std::test]
async fn multiple_slashes_missing() {
let request = Request::builder()
.uri("https://www.rust-lang.org/")
.header("User-Agent", "my-awesome-agent/1.0")
.body(hyper::Body::empty());
println!("{:?}", request);

let res = handle(request.unwrap()).await;

// Temporary print to ensure test is working as intended.
// println!("{}", res.into_response().status());
assert_eq!(res.into_response().status(), 404);

let request = Request::builder()
.uri("https://www.rust-lang.org///")
.header("User-Agent", "my-awesome-agent///1.0")
.body(hyper::Body::empty());
println!("{:?}", request);

let res = handle(request.unwrap()).await;

// Temporary print to ensure test is working as intended.
// println!("{}", res.into_response().status());
assert_eq!(res.into_response().status(), 404);
return ();
}

/// Unit test to handle multiple slash path parsing
#[async_std::test]
async fn multiple_slashes_found() {
let request = Request::builder()
.uri("http://httpbin.org/ip")
.body(hyper::Body::empty());
println!("{:?}", request);

let res = handle(request.unwrap()).await;

// Temporary print to ensure test is working as intended.
// println!("{}", res.into_response().status());
assert_eq!(res.into_response().status(), 404);

let request = Request::builder()
.uri("http://httpbin.org///ip")
.body(hyper::Body::empty());
println!("{:?}", request);

let res = handle(request.unwrap()).await;

// Temporary print to ensure test is working as intended.
// println!("{}", res.into_response().status());
assert_eq!(res.into_response().status(), 404);
return ();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to have unit tests in this file, they have to reside in mod tests, see https://doc.rust-lang.org/book/ch11-01-writing-tests.html

It could also be a better idea to write a test for this in https://github.com/profianinc/drawbridge/blob/f03fb5815f28f5196ff4c93c4137791dc6aab67b/tests/mod.rs instead.
We could just add a few direct URL calls there, something like https://github.com/profianinc/drawbridge/blob/1871d2a7f2519c835818e33a9ca6074e67109006/crates/app/tests/helpers/tree.rs, except with additional slashes.

Basically we need to just test at least one URL, something like: https://store.profian.com//api////v0.2.0////examples//////fibonacci-rust////_tag///0.2.0//tree//PATH/////IN/TREE

if that works, we can assume that everything works.
This could be added to the end of the integration test, where the tree already exists.


let request = Request::builder()
.uri("https://www.rust-lang.org///")
.header("User-Agent", "my-awesome-agent///1.0")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unnecessary

@bstrie
Copy link
Contributor

bstrie commented Nov 7, 2022

Status: waiting for review from Roman to be addressed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants