Skip to content

Commit

Permalink
Check code with rustfmt not to introduce format commits (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnTitor authored Jul 20, 2020
1 parent e5fe8d4 commit 7e6bdf2
Show file tree
Hide file tree
Showing 14 changed files with 59 additions and 80 deletions.
4 changes: 4 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<!-- Thanks for considering contributing actix! -->
<!-- Please fill out the following to make our reviews easy. -->

## PR Type
<!-- What kind of change does this PR make? -->
<!-- Bug Fix / Feature / Refactor / Code Style / Other -->
Expand All @@ -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
Expand Down
18 changes: 15 additions & 3 deletions .github/workflows/clippy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 5 additions & 1 deletion actix-identity/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
3 changes: 1 addition & 2 deletions actix-web-httpauth/examples/middleware-closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions actix-web-httpauth/src/headers/authorization/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
3 changes: 1 addition & 2 deletions actix-web-httpauth/src/headers/authorization/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ impl<S: Scheme> Header for Authorization<S> {
}

fn parse<T: HttpMessage>(msg: &T) -> Result<Self, ParseError> {
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))
Expand Down
12 changes: 3 additions & 9 deletions actix-web-httpauth/src/headers/authorization/scheme/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -80,10 +78,7 @@ impl Scheme for Basic {
}
})?;

Ok(Basic {
user_id,
password,
})
Ok(Basic { user_id, password })
}
}

Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
4 changes: 1 addition & 3 deletions actix-web-httpauth/src/headers/authorization/scheme/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self, ParseError>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
61 changes: 22 additions & 39 deletions actix-web-httpauth/src/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,8 @@ where

impl<S, B, T, F, O> Transform<S> for HttpAuthentication<T, F>
where
S: Service<
Request = ServiceRequest,
Response = ServiceResponse<B>,
Error = Error,
> + 'static,
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>, Error = Error>
+ 'static,
S::Future: 'static,
F: Fn(ServiceRequest, T) -> O + 'static,
O: Future<Output = Result<ServiceRequest, Error>> + 'static,
Expand Down Expand Up @@ -162,11 +159,8 @@ where

impl<S, B, F, T, O> Service for AuthenticationMiddleware<S, F, T>
where
S: Service<
Request = ServiceRequest,
Response = ServiceResponse<B>,
Error = Error,
> + 'static,
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>, Error = Error>
+ 'static,
S::Future: 'static,
F: Fn(ServiceRequest, T) -> O + 'static,
O: Future<Output = Result<ServiceRequest, Error>> + 'static,
Expand All @@ -177,13 +171,8 @@ where
type Error = S::Error;
type Future = LocalBoxFuture<'static, Result<ServiceResponse<B>, Error>>;

fn poll_ready(
&mut self,
ctx: &mut Context<'_>,
) -> Poll<Result<(), Self::Error>> {
self.service
.borrow_mut()
.poll_ready(ctx)
fn poll_ready(&mut self, ctx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
self.service.borrow_mut().poll_ready(ctx)
}

fn call(&mut self, req: Self::Request) -> Self::Future {
Expand Down Expand Up @@ -227,13 +216,9 @@ where
{
type Output = Result<(ServiceRequest, T), Error>;

fn poll(
mut self: Pin<&mut Self>,
ctx: &mut Context<'_>,
) -> Poll<Self::Output> {
fn poll(mut self: Pin<&mut Self>, ctx: &mut Context<'_>) -> Poll<Self::Output> {
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());
}
Expand All @@ -252,33 +237,31 @@ 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::<ServiceResponse, _>(error::ErrorBadRequest("error"))
}}))),
process_fn: Arc::new(|req, _: BearerAuth| async {
Ok(req) }),
},
))),
process_fn: Arc::new(|req, _: BearerAuth| async { Ok(req) }),
_extractor: PhantomData,
};

let req = TestRequest::with_header("Authorization", "Bearer 1").to_srv_request();

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());
}
Expand All @@ -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::<ServiceResponse, _>(error::ErrorBadRequest("error"))
}}))),
process_fn: Arc::new(|req, _: BearerAuth| async {
Ok(req) }),
},
))),
process_fn: Arc::new(|req, _: BearerAuth| async { Ok(req) }),
_extractor: PhantomData,
};

Expand Down

0 comments on commit 7e6bdf2

Please sign in to comment.