mirror of
https://github.com/actix/actix-extras.git
synced 2025-02-02 10:59:03 +01:00
Check code with rustfmt not to introduce format commits (#88)
This commit is contained in:
parent
e5fe8d42fa
commit
7e6bdf2eb2
4
.github/PULL_REQUEST_TEMPLATE.md
vendored
4
.github/PULL_REQUEST_TEMPLATE.md
vendored
@ -1,3 +1,6 @@
|
|||||||
|
<!-- Thanks for considering contributing actix! -->
|
||||||
|
<!-- Please fill out the following to make our reviews easy. -->
|
||||||
|
|
||||||
## PR Type
|
## PR Type
|
||||||
<!-- What kind of change does this PR make? -->
|
<!-- What kind of change does this PR make? -->
|
||||||
<!-- Bug Fix / Feature / Refactor / Code Style / Other -->
|
<!-- Bug Fix / Feature / Refactor / Code Style / Other -->
|
||||||
@ -12,6 +15,7 @@ Check your PR fulfills the following:
|
|||||||
- [ ] Tests for the changes have been added / updated.
|
- [ ] Tests for the changes have been added / updated.
|
||||||
- [ ] Documentation comments have been added / updated.
|
- [ ] Documentation comments have been added / updated.
|
||||||
- [ ] A changelog entry has been made for the appropriate packages.
|
- [ ] A changelog entry has been made for the appropriate packages.
|
||||||
|
- [ ] Format code with the latest stable rustfmt
|
||||||
|
|
||||||
|
|
||||||
## Overview
|
## Overview
|
||||||
|
18
.github/workflows/clippy.yml
vendored
18
.github/workflows/clippy.yml
vendored
@ -2,19 +2,31 @@ on:
|
|||||||
pull_request:
|
pull_request:
|
||||||
types: [opened, synchronize, reopened]
|
types: [opened, synchronize, reopened]
|
||||||
|
|
||||||
name: Clippy Check
|
name: Clippy and rustfmt Check
|
||||||
jobs:
|
jobs:
|
||||||
clippy_check:
|
clippy_check:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- 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
|
- uses: actions-rs/toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: nightly
|
toolchain: nightly
|
||||||
profile: minimal
|
|
||||||
components: clippy
|
components: clippy
|
||||||
override: true
|
override: true
|
||||||
- uses: actions-rs/clippy-check@v1
|
- name: Check with Clippy
|
||||||
|
uses: actions-rs/clippy-check@v1
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
args: --all-features --all --tests
|
args: --all-features --all --tests
|
||||||
|
@ -552,7 +552,11 @@ impl IdentityPolicy for CookieIdentityPolicy {
|
|||||||
|
|
||||||
fn from_request(&self, req: &mut ServiceRequest) -> Self::Future {
|
fn from_request(&self, req: &mut ServiceRequest) -> Self::Future {
|
||||||
ok(self.0.load(req).map(
|
ok(self.0.load(req).map(
|
||||||
|CookieValue { identity, login_timestamp, .. }| {
|
|CookieValue {
|
||||||
|
identity,
|
||||||
|
login_timestamp,
|
||||||
|
..
|
||||||
|
}| {
|
||||||
if self.0.requires_oob_data() {
|
if self.0.requires_oob_data() {
|
||||||
req.extensions_mut()
|
req.extensions_mut()
|
||||||
.insert(CookieIdentityExtention { login_timestamp });
|
.insert(CookieIdentityExtention { login_timestamp });
|
||||||
|
@ -5,8 +5,7 @@ use actix_web_httpauth::middleware::HttpAuthentication;
|
|||||||
#[actix_rt::main]
|
#[actix_rt::main]
|
||||||
async fn main() -> std::io::Result<()> {
|
async fn main() -> std::io::Result<()> {
|
||||||
HttpServer::new(|| {
|
HttpServer::new(|| {
|
||||||
let auth =
|
let auth = HttpAuthentication::basic(|req, _credentials| async { Ok(req) });
|
||||||
HttpAuthentication::basic(|req, _credentials| async { Ok(req) });
|
|
||||||
App::new()
|
App::new()
|
||||||
.wrap(middleware::Logger::default())
|
.wrap(middleware::Logger::default())
|
||||||
.wrap(auth)
|
.wrap(auth)
|
||||||
|
@ -29,9 +29,7 @@ impl fmt::Display for ParseError {
|
|||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
let display = match self {
|
let display = match self {
|
||||||
ParseError::Invalid => "Invalid header value".to_string(),
|
ParseError::Invalid => "Invalid header value".to_string(),
|
||||||
ParseError::MissingScheme => {
|
ParseError::MissingScheme => "Missing authorization scheme".to_string(),
|
||||||
"Missing authorization scheme".to_string()
|
|
||||||
}
|
|
||||||
ParseError::MissingField(_) => "Missing header field".to_string(),
|
ParseError::MissingField(_) => "Missing header field".to_string(),
|
||||||
ParseError::ToStrError(e) => e.to_string(),
|
ParseError::ToStrError(e) => e.to_string(),
|
||||||
ParseError::Base64DecodeError(e) => e.to_string(),
|
ParseError::Base64DecodeError(e) => e.to_string(),
|
||||||
|
@ -81,8 +81,7 @@ impl<S: Scheme> Header for Authorization<S> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn parse<T: HttpMessage>(msg: &T) -> Result<Self, ParseError> {
|
fn parse<T: HttpMessage>(msg: &T) -> Result<Self, ParseError> {
|
||||||
let header =
|
let header = msg.headers().get(AUTHORIZATION).ok_or(ParseError::Header)?;
|
||||||
msg.headers().get(AUTHORIZATION).ok_or(ParseError::Header)?;
|
|
||||||
let scheme = S::parse(header).map_err(|_| ParseError::Header)?;
|
let scheme = S::parse(header).map_err(|_| ParseError::Header)?;
|
||||||
|
|
||||||
Ok(Authorization(scheme))
|
Ok(Authorization(scheme))
|
||||||
|
@ -2,9 +2,7 @@ use std::borrow::Cow;
|
|||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::str;
|
use std::str;
|
||||||
|
|
||||||
use actix_web::http::header::{
|
use actix_web::http::header::{HeaderValue, IntoHeaderValue, InvalidHeaderValue};
|
||||||
HeaderValue, IntoHeaderValue, InvalidHeaderValue,
|
|
||||||
};
|
|
||||||
use bytes::{BufMut, BytesMut};
|
use bytes::{BufMut, BytesMut};
|
||||||
|
|
||||||
use crate::headers::authorization::errors::ParseError;
|
use crate::headers::authorization::errors::ParseError;
|
||||||
@ -80,10 +78,7 @@ impl Scheme for Basic {
|
|||||||
}
|
}
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
Ok(Basic {
|
Ok(Basic { user_id, password })
|
||||||
user_id,
|
|
||||||
password,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,8 +128,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_parse_header() {
|
fn test_parse_header() {
|
||||||
let value =
|
let value = HeaderValue::from_static("Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==");
|
||||||
HeaderValue::from_static("Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==");
|
|
||||||
let scheme = Basic::parse(&value);
|
let scheme = Basic::parse(&value);
|
||||||
|
|
||||||
assert!(scheme.is_ok());
|
assert!(scheme.is_ok());
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
use actix_web::http::header::{
|
use actix_web::http::header::{HeaderValue, IntoHeaderValue, InvalidHeaderValue};
|
||||||
HeaderValue, IntoHeaderValue, InvalidHeaderValue,
|
|
||||||
};
|
|
||||||
use bytes::{BufMut, BytesMut};
|
use bytes::{BufMut, BytesMut};
|
||||||
|
|
||||||
use crate::headers::authorization::errors::ParseError;
|
use crate::headers::authorization::errors::ParseError;
|
||||||
|
@ -9,9 +9,7 @@ use crate::headers::authorization::errors::ParseError;
|
|||||||
|
|
||||||
/// Authentication scheme for [`Authorization`](./struct.Authorization.html)
|
/// Authentication scheme for [`Authorization`](./struct.Authorization.html)
|
||||||
/// header.
|
/// header.
|
||||||
pub trait Scheme:
|
pub trait Scheme: IntoHeaderValue + Debug + Display + Clone + Send + Sync {
|
||||||
IntoHeaderValue + Debug + Display + Clone + Send + Sync
|
|
||||||
{
|
|
||||||
/// Try to parse the authentication scheme from the `Authorization` header.
|
/// Try to parse the authentication scheme from the `Authorization` header.
|
||||||
fn parse(header: &HeaderValue) -> Result<Self, ParseError>;
|
fn parse(header: &HeaderValue) -> Result<Self, ParseError>;
|
||||||
}
|
}
|
||||||
|
@ -5,9 +5,7 @@ use std::default::Default;
|
|||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::str;
|
use std::str;
|
||||||
|
|
||||||
use actix_web::http::header::{
|
use actix_web::http::header::{HeaderValue, IntoHeaderValue, InvalidHeaderValue};
|
||||||
HeaderValue, IntoHeaderValue, InvalidHeaderValue,
|
|
||||||
};
|
|
||||||
use bytes::{BufMut, Bytes, BytesMut};
|
use bytes::{BufMut, Bytes, BytesMut};
|
||||||
|
|
||||||
use super::Challenge;
|
use super::Challenge;
|
||||||
@ -120,9 +118,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_plain_into_header_value() {
|
fn test_plain_into_header_value() {
|
||||||
let challenge = Basic {
|
let challenge = Basic { realm: None };
|
||||||
realm: None,
|
|
||||||
};
|
|
||||||
|
|
||||||
let value = challenge.try_into();
|
let value = challenge.try_into();
|
||||||
assert!(value.is_ok());
|
assert!(value.is_ok());
|
||||||
|
@ -2,9 +2,7 @@ use std::borrow::Cow;
|
|||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::str;
|
use std::str;
|
||||||
|
|
||||||
use actix_web::http::header::{
|
use actix_web::http::header::{HeaderValue, IntoHeaderValue, InvalidHeaderValue};
|
||||||
HeaderValue, IntoHeaderValue, InvalidHeaderValue,
|
|
||||||
};
|
|
||||||
use bytes::{BufMut, Bytes, BytesMut};
|
use bytes::{BufMut, Bytes, BytesMut};
|
||||||
|
|
||||||
use super::super::Challenge;
|
use super::super::Challenge;
|
||||||
|
@ -4,9 +4,7 @@ use super::*;
|
|||||||
fn to_bytes() {
|
fn to_bytes() {
|
||||||
let b = Bearer::build()
|
let b = Bearer::build()
|
||||||
.error(Error::InvalidToken)
|
.error(Error::InvalidToken)
|
||||||
.error_description(
|
.error_description("Subject 8740827c-2e0a-447b-9716-d73042e4039d not found")
|
||||||
"Subject 8740827c-2e0a-447b-9716-d73042e4039d not found",
|
|
||||||
)
|
|
||||||
.finish();
|
.finish();
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -7,9 +7,7 @@ pub mod basic;
|
|||||||
pub mod bearer;
|
pub mod bearer;
|
||||||
|
|
||||||
/// Authentication challenge for `WWW-Authenticate` header.
|
/// Authentication challenge for `WWW-Authenticate` header.
|
||||||
pub trait Challenge:
|
pub trait Challenge: IntoHeaderValue + Debug + Display + Clone + Send + Sync {
|
||||||
IntoHeaderValue + Debug + Display + Clone + Send + Sync
|
|
||||||
{
|
|
||||||
/// Converts the challenge into a bytes suitable for HTTP transmission.
|
/// Converts the challenge into a bytes suitable for HTTP transmission.
|
||||||
fn to_bytes(&self) -> Bytes;
|
fn to_bytes(&self) -> Bytes;
|
||||||
}
|
}
|
||||||
|
@ -124,11 +124,8 @@ where
|
|||||||
|
|
||||||
impl<S, B, T, F, O> Transform<S> for HttpAuthentication<T, F>
|
impl<S, B, T, F, O> Transform<S> for HttpAuthentication<T, F>
|
||||||
where
|
where
|
||||||
S: Service<
|
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>, Error = Error>
|
||||||
Request = ServiceRequest,
|
+ 'static,
|
||||||
Response = ServiceResponse<B>,
|
|
||||||
Error = Error,
|
|
||||||
> + 'static,
|
|
||||||
S::Future: 'static,
|
S::Future: 'static,
|
||||||
F: Fn(ServiceRequest, T) -> O + 'static,
|
F: Fn(ServiceRequest, T) -> O + 'static,
|
||||||
O: Future<Output = Result<ServiceRequest, Error>> + 'static,
|
O: Future<Output = Result<ServiceRequest, Error>> + 'static,
|
||||||
@ -162,11 +159,8 @@ where
|
|||||||
|
|
||||||
impl<S, B, F, T, O> Service for AuthenticationMiddleware<S, F, T>
|
impl<S, B, F, T, O> Service for AuthenticationMiddleware<S, F, T>
|
||||||
where
|
where
|
||||||
S: Service<
|
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>, Error = Error>
|
||||||
Request = ServiceRequest,
|
+ 'static,
|
||||||
Response = ServiceResponse<B>,
|
|
||||||
Error = Error,
|
|
||||||
> + 'static,
|
|
||||||
S::Future: 'static,
|
S::Future: 'static,
|
||||||
F: Fn(ServiceRequest, T) -> O + 'static,
|
F: Fn(ServiceRequest, T) -> O + 'static,
|
||||||
O: Future<Output = Result<ServiceRequest, Error>> + 'static,
|
O: Future<Output = Result<ServiceRequest, Error>> + 'static,
|
||||||
@ -177,13 +171,8 @@ where
|
|||||||
type Error = S::Error;
|
type Error = S::Error;
|
||||||
type Future = LocalBoxFuture<'static, Result<ServiceResponse<B>, Error>>;
|
type Future = LocalBoxFuture<'static, Result<ServiceResponse<B>, Error>>;
|
||||||
|
|
||||||
fn poll_ready(
|
fn poll_ready(&mut self, ctx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
||||||
&mut self,
|
self.service.borrow_mut().poll_ready(ctx)
|
||||||
ctx: &mut Context<'_>,
|
|
||||||
) -> Poll<Result<(), Self::Error>> {
|
|
||||||
self.service
|
|
||||||
.borrow_mut()
|
|
||||||
.poll_ready(ctx)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn call(&mut self, req: Self::Request) -> Self::Future {
|
fn call(&mut self, req: Self::Request) -> Self::Future {
|
||||||
@ -227,13 +216,9 @@ where
|
|||||||
{
|
{
|
||||||
type Output = Result<(ServiceRequest, T), Error>;
|
type Output = Result<(ServiceRequest, T), Error>;
|
||||||
|
|
||||||
fn poll(
|
fn poll(mut self: Pin<&mut Self>, ctx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||||
mut self: Pin<&mut Self>,
|
|
||||||
ctx: &mut Context<'_>,
|
|
||||||
) -> Poll<Self::Output> {
|
|
||||||
if self.f.is_none() {
|
if self.f.is_none() {
|
||||||
let req =
|
let req = self.req.as_ref().expect("Extract future was polled twice!");
|
||||||
self.req.as_ref().expect("Extract future was polled twice!");
|
|
||||||
let f = T::from_service_request(req).map_err(Into::into);
|
let f = T::from_service_request(req).map_err(Into::into);
|
||||||
self.f = Some(f.boxed_local());
|
self.f = Some(f.boxed_local());
|
||||||
}
|
}
|
||||||
@ -252,24 +237,23 @@ where
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use actix_web::test::TestRequest;
|
|
||||||
use actix_service::{into_service, Service};
|
|
||||||
use futures_util::join;
|
|
||||||
use crate::extractors::bearer::BearerAuth;
|
use crate::extractors::bearer::BearerAuth;
|
||||||
|
use actix_service::{into_service, Service};
|
||||||
use actix_web::error;
|
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
|
/// This is a test for https://github.com/actix/actix-extras/issues/10
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn test_middleware_panic() {
|
async fn test_middleware_panic() {
|
||||||
let mut middleware = AuthenticationMiddleware {
|
let mut middleware = AuthenticationMiddleware {
|
||||||
service: Rc::new(RefCell::new(into_service(|_: ServiceRequest| {
|
service: Rc::new(RefCell::new(into_service(
|
||||||
async move {
|
|_: ServiceRequest| async move {
|
||||||
actix_rt::time::delay_for(std::time::Duration::from_secs(1)).await;
|
actix_rt::time::delay_for(std::time::Duration::from_secs(1)).await;
|
||||||
Err::<ServiceResponse, _>(error::ErrorBadRequest("error"))
|
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,
|
_extractor: PhantomData,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -279,7 +263,6 @@ mod tests {
|
|||||||
|
|
||||||
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());
|
assert!(join!(f, res).0.is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -287,13 +270,13 @@ mod tests {
|
|||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn test_middleware_panic_several_orders() {
|
async fn test_middleware_panic_several_orders() {
|
||||||
let mut middleware = AuthenticationMiddleware {
|
let mut middleware = AuthenticationMiddleware {
|
||||||
service: Rc::new(RefCell::new(into_service(|_: ServiceRequest| {
|
service: Rc::new(RefCell::new(into_service(
|
||||||
async move {
|
|_: ServiceRequest| async move {
|
||||||
actix_rt::time::delay_for(std::time::Duration::from_secs(1)).await;
|
actix_rt::time::delay_for(std::time::Duration::from_secs(1)).await;
|
||||||
Err::<ServiceResponse, _>(error::ErrorBadRequest("error"))
|
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,
|
_extractor: PhantomData,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user