Skip to content
This repository has been archived by the owner on Jul 13, 2024. It is now read-only.

Commit

Permalink
Fix clippy warnings and add build checks
Browse files Browse the repository at this point in the history
  • Loading branch information
stevepryde committed Nov 4, 2020
1 parent b304b99 commit c07e680
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 26 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/audit-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Security audit
on:
push:
paths:
- '**/Cargo.toml'
- '**/Cargo.lock'
pull_request:
paths:
- '**/Cargo.toml'
- '**/Cargo.lock'
jobs:
security_audit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/audit-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
18 changes: 18 additions & 0 deletions .github/workflows/build-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: build-check

on: [push, pull_request]

env:
CARGO_TERM_COLOR: always

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
11 changes: 11 additions & 0 deletions .github/workflows/clippy-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
on: [push, pull_request]
name: Clippy check
jobs:
clippy_check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: rustup component add clippy
- uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion src/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ fn parse_url(url: &str) -> Option<(Scheme, Authority)> {
match url.parse::<Uri>() {
Ok(uri) => {
let scheme = uri.scheme().cloned().unwrap_or(Scheme::HTTP);
let authority = uri.authority().cloned().unwrap_or(default_authority());
let authority = uri.authority().cloned().unwrap_or_else(default_authority);
Some((scheme, authority))
}
Err(_) => None,
Expand Down
14 changes: 13 additions & 1 deletion src/response.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use hyper::{Body, StatusCode};
use hyper::{Body, Response, StatusCode};
use serde::Serialize;

#[derive(Debug, Serialize)]
Expand Down Expand Up @@ -26,6 +26,18 @@ impl XenonResponse {
_ => StatusCode::INTERNAL_SERVER_ERROR,
}
}

pub fn into_response(self) -> Response<Body> {
Response::builder()
.status(self.status())
.body(self.into())
.unwrap_or_else(|_| {
Response::builder()
.status(StatusCode::INTERNAL_SERVER_ERROR)
.body(Body::from("Xenon failed to serialize an error"))
.unwrap()
})
}
}

impl Into<Body> for XenonResponse {
Expand Down
29 changes: 6 additions & 23 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ pub async fn start_server() -> XenonResult<()> {
let remote_addr = conn.remote_addr();
async move {
let state = state.clone();
let remote_addr = remote_addr.clone();
let remote_addr = remote_addr;
Ok::<_, Infallible>(service_fn(move |req| {
let state = state.clone();
handle(req, remote_addr.clone(), state)
handle(req, remote_addr, state)
}))
}
});
Expand Down Expand Up @@ -132,30 +132,13 @@ async fn handle(
Ok(x) => Ok(x),
Err(XenonError::RespondWith(r)) => {
debug!("Xenon replied with error: {:#?}", r);
Ok(Response::builder()
.status(r.status())
.body(r.into())
.unwrap_or_else(|_| {
Response::builder()
.status(StatusCode::INTERNAL_SERVER_ERROR)
.body(Body::from("Xenon failed to serialize an error"))
.unwrap()
}))
Ok(r.into_response())
}
Err(e) => {
// Coerce all errors into WebDriver-compatible response.
error!("Internal Error: {:#?}", e);
let r = XenonResponse::InternalServerError(e.to_string());

Ok(Response::builder()
.status(r.status())
.body(r.into())
.unwrap_or_else(|_| {
Response::builder()
.status(StatusCode::INTERNAL_SERVER_ERROR)
.body(Body::from("Xenon failed to serialize an error"))
.unwrap()
}))
Ok(r.into_response())
}
}
}
Expand Down Expand Up @@ -635,8 +618,8 @@ async fn process_node_init(state: Arc<RwLock<XenonState>>) {
}
};

// Update these. This requires a write lock but only briefly.
let s = state.write().await;
// Update these. Read lock on state. Write lock on nodes.
let s = state.read().await;
let rwlock_nodes = s.remote_nodes();
let mut nodes = rwlock_nodes.write().await;
if let Some(node) = nodes.get_mut(&node.id()) {
Expand Down
2 changes: 1 addition & 1 deletion src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl Session {
Some(p) => p,
None => {
return Err(XenonError::RespondWith(
XenonResponse::ErrorCreatingSession(format!("Port not recognised")),
XenonResponse::ErrorCreatingSession("Port not recognised".to_string()),
))
}
};
Expand Down

0 comments on commit c07e680

Please sign in to comment.