diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index d53e084e9..b779b33fa 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,3 +1,6 @@ + + + ## PR Type @@ -12,6 +15,7 @@ Check your PR fulfills the following: - [ ] Tests for the changes have been added / updated. - [ ] Documentation comments have been added / updated. - [ ] A changelog entry has been made for the appropriate packages. +- [ ] Format code with the latest stable rustfmt ## Overview diff --git a/.github/workflows/clippy.yml b/.github/workflows/clippy.yml index 5f8e47891..fb1ed7f32 100644 --- a/.github/workflows/clippy.yml +++ b/.github/workflows/clippy.yml @@ -2,19 +2,31 @@ on: pull_request: types: [opened, synchronize, reopened] -name: Clippy Check +name: Clippy and rustfmt Check jobs: clippy_check: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 + + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + components: rustfmt + override: true + - name: Check with rustfmt + uses: actions-rs/cargo@v1 + with: + command: fmt + args: --all -- --check + - uses: actions-rs/toolchain@v1 with: toolchain: nightly - profile: minimal components: clippy override: true - - uses: actions-rs/clippy-check@v1 + - name: Check with Clippy + uses: actions-rs/clippy-check@v1 with: token: ${{ secrets.GITHUB_TOKEN }} args: --all-features --all --tests diff --git a/actix-identity/src/lib.rs b/actix-identity/src/lib.rs index 20d376ad6..349ecbdcd 100644 --- a/actix-identity/src/lib.rs +++ b/actix-identity/src/lib.rs @@ -552,7 +552,11 @@ impl IdentityPolicy for CookieIdentityPolicy { fn from_request(&self, req: &mut ServiceRequest) -> Self::Future { ok(self.0.load(req).map( - |CookieValue { identity, login_timestamp, .. }| { + |CookieValue { + identity, + login_timestamp, + .. + }| { if self.0.requires_oob_data() { req.extensions_mut() .insert(CookieIdentityExtention { login_timestamp }); diff --git a/actix-web-httpauth/examples/middleware-closure.rs b/actix-web-httpauth/examples/middleware-closure.rs index 0f623bfe0..e26a11478 100644 --- a/actix-web-httpauth/examples/middleware-closure.rs +++ b/actix-web-httpauth/examples/middleware-closure.rs @@ -5,8 +5,7 @@ use actix_web_httpauth::middleware::HttpAuthentication; #[actix_rt::main] async fn main() -> std::io::Result<()> { HttpServer::new(|| { - let auth = - HttpAuthentication::basic(|req, _credentials| async { Ok(req) }); + let auth = HttpAuthentication::basic(|req, _credentials| async { Ok(req) }); App::new() .wrap(middleware::Logger::default()) .wrap(auth) diff --git a/actix-web-httpauth/src/headers/authorization/errors.rs b/actix-web-httpauth/src/headers/authorization/errors.rs index f2c620063..bb79547c3 100644 --- a/actix-web-httpauth/src/headers/authorization/errors.rs +++ b/actix-web-httpauth/src/headers/authorization/errors.rs @@ -29,9 +29,7 @@ impl fmt::Display for ParseError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let display = match self { ParseError::Invalid => "Invalid header value".to_string(), - ParseError::MissingScheme => { - "Missing authorization scheme".to_string() - } + ParseError::MissingScheme => "Missing authorization scheme".to_string(), ParseError::MissingField(_) => "Missing header field".to_string(), ParseError::ToStrError(e) => e.to_string(), ParseError::Base64DecodeError(e) => e.to_string(), diff --git a/actix-web-httpauth/src/headers/authorization/header.rs b/actix-web-httpauth/src/headers/authorization/header.rs index 3fb9531d2..1c38c4c6f 100644 --- a/actix-web-httpauth/src/headers/authorization/header.rs +++ b/actix-web-httpauth/src/headers/authorization/header.rs @@ -81,8 +81,7 @@ impl Header for Authorization { } fn parse(msg: &T) -> Result { - let header = - msg.headers().get(AUTHORIZATION).ok_or(ParseError::Header)?; + let header = msg.headers().get(AUTHORIZATION).ok_or(ParseError::Header)?; let scheme = S::parse(header).map_err(|_| ParseError::Header)?; Ok(Authorization(scheme)) diff --git a/actix-web-httpauth/src/headers/authorization/scheme/basic.rs b/actix-web-httpauth/src/headers/authorization/scheme/basic.rs index 76b2ec451..78ad28ba1 100644 --- a/actix-web-httpauth/src/headers/authorization/scheme/basic.rs +++ b/actix-web-httpauth/src/headers/authorization/scheme/basic.rs @@ -2,9 +2,7 @@ use std::borrow::Cow; use std::fmt; use std::str; -use actix_web::http::header::{ - HeaderValue, IntoHeaderValue, InvalidHeaderValue, -}; +use actix_web::http::header::{HeaderValue, IntoHeaderValue, InvalidHeaderValue}; use bytes::{BufMut, BytesMut}; use crate::headers::authorization::errors::ParseError; @@ -80,10 +78,7 @@ impl Scheme for Basic { } })?; - Ok(Basic { - user_id, - password, - }) + Ok(Basic { user_id, password }) } } @@ -133,8 +128,7 @@ mod tests { #[test] fn test_parse_header() { - let value = - HeaderValue::from_static("Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=="); + let value = HeaderValue::from_static("Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=="); let scheme = Basic::parse(&value); assert!(scheme.is_ok()); diff --git a/actix-web-httpauth/src/headers/authorization/scheme/bearer.rs b/actix-web-httpauth/src/headers/authorization/scheme/bearer.rs index ed52ee1b5..e33694704 100644 --- a/actix-web-httpauth/src/headers/authorization/scheme/bearer.rs +++ b/actix-web-httpauth/src/headers/authorization/scheme/bearer.rs @@ -1,9 +1,7 @@ use std::borrow::Cow; use std::fmt; -use actix_web::http::header::{ - HeaderValue, IntoHeaderValue, InvalidHeaderValue, -}; +use actix_web::http::header::{HeaderValue, IntoHeaderValue, InvalidHeaderValue}; use bytes::{BufMut, BytesMut}; use crate::headers::authorization::errors::ParseError; diff --git a/actix-web-httpauth/src/headers/authorization/scheme/mod.rs b/actix-web-httpauth/src/headers/authorization/scheme/mod.rs index 1ab534c93..3224e2c43 100644 --- a/actix-web-httpauth/src/headers/authorization/scheme/mod.rs +++ b/actix-web-httpauth/src/headers/authorization/scheme/mod.rs @@ -9,9 +9,7 @@ use crate::headers::authorization::errors::ParseError; /// Authentication scheme for [`Authorization`](./struct.Authorization.html) /// header. -pub trait Scheme: - IntoHeaderValue + Debug + Display + Clone + Send + Sync -{ +pub trait Scheme: IntoHeaderValue + Debug + Display + Clone + Send + Sync { /// Try to parse the authentication scheme from the `Authorization` header. fn parse(header: &HeaderValue) -> Result; } diff --git a/actix-web-httpauth/src/headers/www_authenticate/challenge/basic.rs b/actix-web-httpauth/src/headers/www_authenticate/challenge/basic.rs index 1a01c965d..c18a37d7d 100644 --- a/actix-web-httpauth/src/headers/www_authenticate/challenge/basic.rs +++ b/actix-web-httpauth/src/headers/www_authenticate/challenge/basic.rs @@ -5,9 +5,7 @@ use std::default::Default; use std::fmt; use std::str; -use actix_web::http::header::{ - HeaderValue, IntoHeaderValue, InvalidHeaderValue, -}; +use actix_web::http::header::{HeaderValue, IntoHeaderValue, InvalidHeaderValue}; use bytes::{BufMut, Bytes, BytesMut}; use super::Challenge; @@ -120,9 +118,7 @@ mod tests { #[test] fn test_plain_into_header_value() { - let challenge = Basic { - realm: None, - }; + let challenge = Basic { realm: None }; let value = challenge.try_into(); assert!(value.is_ok()); diff --git a/actix-web-httpauth/src/headers/www_authenticate/challenge/bearer/challenge.rs b/actix-web-httpauth/src/headers/www_authenticate/challenge/bearer/challenge.rs index 9207b59d0..b045edcbd 100644 --- a/actix-web-httpauth/src/headers/www_authenticate/challenge/bearer/challenge.rs +++ b/actix-web-httpauth/src/headers/www_authenticate/challenge/bearer/challenge.rs @@ -2,9 +2,7 @@ use std::borrow::Cow; use std::fmt; use std::str; -use actix_web::http::header::{ - HeaderValue, IntoHeaderValue, InvalidHeaderValue, -}; +use actix_web::http::header::{HeaderValue, IntoHeaderValue, InvalidHeaderValue}; use bytes::{BufMut, Bytes, BytesMut}; use super::super::Challenge; diff --git a/actix-web-httpauth/src/headers/www_authenticate/challenge/bearer/tests.rs b/actix-web-httpauth/src/headers/www_authenticate/challenge/bearer/tests.rs index 015c07d33..03f088e17 100644 --- a/actix-web-httpauth/src/headers/www_authenticate/challenge/bearer/tests.rs +++ b/actix-web-httpauth/src/headers/www_authenticate/challenge/bearer/tests.rs @@ -4,9 +4,7 @@ use super::*; fn to_bytes() { let b = Bearer::build() .error(Error::InvalidToken) - .error_description( - "Subject 8740827c-2e0a-447b-9716-d73042e4039d not found", - ) + .error_description("Subject 8740827c-2e0a-447b-9716-d73042e4039d not found") .finish(); assert_eq!( diff --git a/actix-web-httpauth/src/headers/www_authenticate/challenge/mod.rs b/actix-web-httpauth/src/headers/www_authenticate/challenge/mod.rs index 619c5ef51..ce70f4fe2 100644 --- a/actix-web-httpauth/src/headers/www_authenticate/challenge/mod.rs +++ b/actix-web-httpauth/src/headers/www_authenticate/challenge/mod.rs @@ -7,9 +7,7 @@ pub mod basic; pub mod bearer; /// Authentication challenge for `WWW-Authenticate` header. -pub trait Challenge: - IntoHeaderValue + Debug + Display + Clone + Send + Sync -{ +pub trait Challenge: IntoHeaderValue + Debug + Display + Clone + Send + Sync { /// Converts the challenge into a bytes suitable for HTTP transmission. fn to_bytes(&self) -> Bytes; } diff --git a/actix-web-httpauth/src/middleware.rs b/actix-web-httpauth/src/middleware.rs index 31f08fcf6..48a9c4dba 100644 --- a/actix-web-httpauth/src/middleware.rs +++ b/actix-web-httpauth/src/middleware.rs @@ -124,11 +124,8 @@ where impl Transform for HttpAuthentication where - S: Service< - Request = ServiceRequest, - Response = ServiceResponse, - Error = Error, - > + 'static, + S: Service, Error = Error> + + 'static, S::Future: 'static, F: Fn(ServiceRequest, T) -> O + 'static, O: Future> + 'static, @@ -162,11 +159,8 @@ where impl Service for AuthenticationMiddleware where - S: Service< - Request = ServiceRequest, - Response = ServiceResponse, - Error = Error, - > + 'static, + S: Service, Error = Error> + + 'static, S::Future: 'static, F: Fn(ServiceRequest, T) -> O + 'static, O: Future> + 'static, @@ -177,13 +171,8 @@ where type Error = S::Error; type Future = LocalBoxFuture<'static, Result, Error>>; - fn poll_ready( - &mut self, - ctx: &mut Context<'_>, - ) -> Poll> { - self.service - .borrow_mut() - .poll_ready(ctx) + fn poll_ready(&mut self, ctx: &mut Context<'_>) -> Poll> { + self.service.borrow_mut().poll_ready(ctx) } fn call(&mut self, req: Self::Request) -> Self::Future { @@ -227,13 +216,9 @@ where { type Output = Result<(ServiceRequest, T), Error>; - fn poll( - mut self: Pin<&mut Self>, - ctx: &mut Context<'_>, - ) -> Poll { + fn poll(mut self: Pin<&mut Self>, ctx: &mut Context<'_>) -> Poll { if self.f.is_none() { - let req = - self.req.as_ref().expect("Extract future was polled twice!"); + let req = self.req.as_ref().expect("Extract future was polled twice!"); let f = T::from_service_request(req).map_err(Into::into); self.f = Some(f.boxed_local()); } @@ -252,24 +237,23 @@ where #[cfg(test)] mod tests { use super::*; - use actix_web::test::TestRequest; - use actix_service::{into_service, Service}; - use futures_util::join; use crate::extractors::bearer::BearerAuth; + use actix_service::{into_service, Service}; use actix_web::error; - + use actix_web::test::TestRequest; + use futures_util::join; /// This is a test for https://github.com/actix/actix-extras/issues/10 #[actix_rt::test] async fn test_middleware_panic() { let mut middleware = AuthenticationMiddleware { - service: Rc::new(RefCell::new(into_service(|_: ServiceRequest| { - async move { + service: Rc::new(RefCell::new(into_service( + |_: ServiceRequest| async move { actix_rt::time::delay_for(std::time::Duration::from_secs(1)).await; Err::(error::ErrorBadRequest("error")) - }}))), - process_fn: Arc::new(|req, _: BearerAuth| async { - Ok(req) }), + }, + ))), + process_fn: Arc::new(|req, _: BearerAuth| async { Ok(req) }), _extractor: PhantomData, }; @@ -277,8 +261,7 @@ mod tests { let f = middleware.call(req); - let res = futures_util::future::lazy(|cx| middleware.poll_ready(cx) ); - + let res = futures_util::future::lazy(|cx| middleware.poll_ready(cx)); assert!(join!(f, res).0.is_err()); } @@ -287,13 +270,13 @@ mod tests { #[actix_rt::test] async fn test_middleware_panic_several_orders() { let mut middleware = AuthenticationMiddleware { - service: Rc::new(RefCell::new(into_service(|_: ServiceRequest| { - async move { + service: Rc::new(RefCell::new(into_service( + |_: ServiceRequest| async move { actix_rt::time::delay_for(std::time::Duration::from_secs(1)).await; Err::(error::ErrorBadRequest("error")) - }}))), - process_fn: Arc::new(|req, _: BearerAuth| async { - Ok(req) }), + }, + ))), + process_fn: Arc::new(|req, _: BearerAuth| async { Ok(req) }), _extractor: PhantomData, };