Skip to content

Commit

Permalink
add test for bad connection string
Browse files Browse the repository at this point in the history
  • Loading branch information
paulgb committed Sep 24, 2024
1 parent 5436e8e commit 158fe97
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
25 changes: 25 additions & 0 deletions plane/plane-tests/tests/proxy.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use common::{proxy_mock::MockProxy, test_env::TestEnvironment};
use plane::{protocol::RouteInfoResponse, types::BearerToken};
use plane_test_macro::plane_test;
use reqwest::StatusCode;

Expand All @@ -16,3 +17,27 @@ async fn proxy_no_bearer_token(env: TestEnvironment) {

assert_eq!(response.status(), StatusCode::UNAUTHORIZED);
}

#[plane_test]
async fn proxy_bad_bearer_token(env: TestEnvironment) {
let mut proxy = MockProxy::new().await;
let url = format!("http://{}/abc123/", proxy.addr());
let handle = tokio::spawn(async { reqwest::get(url).await.expect("Failed to send request") });

let route_info_request = proxy.recv_route_info_request().await;
assert_eq!(
route_info_request.token,
BearerToken::from("abc123".to_string())
);

proxy
.send_route_info_response(RouteInfoResponse {
token: BearerToken::from("abc123".to_string()),
route_info: None,
})
.await;

let response = handle.await.unwrap();

assert_eq!(response.status(), StatusCode::UNAUTHORIZED);
}
6 changes: 4 additions & 2 deletions plane/src/proxy/proxy_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,10 @@ impl Service<Request<Incoming>> for ProxyState {
let route_info = inner.route_map.lookup(&bearer_token).await;

let Some(route_info) = route_info else {
// TODO
panic!("Route info not found for bearer token");
return Ok(Response::builder()
.status(StatusCode::UNAUTHORIZED)
.body(simple_empty_body())
.unwrap());

Check warning on line 82 in plane/src/proxy/proxy_server.rs

View workflow job for this annotation

GitHub Actions / clippy

used `unwrap()` on a `Result` value

warning: used `unwrap()` on a `Result` value --> plane/src/proxy/proxy_server.rs:79:27 | 79 | return Ok(Response::builder() | ___________________________^ 80 | | .status(StatusCode::UNAUTHORIZED) 81 | | .body(simple_empty_body()) 82 | | .unwrap()); | |_____________________________^ | = note: if this value is an `Err`, it will panic = help: consider using `expect()` to provide a better panic message = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unwrap_used
};

request.set_upstream_address(route_info.address.0);
Expand Down

0 comments on commit 158fe97

Please sign in to comment.