mirror of
https://github.com/actix/actix-extras.git
synced 2025-01-22 23:05:56 +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
|
||||
<!-- What kind of change does this PR make? -->
|
||||
<!-- 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.
|
||||
- [ ] Documentation comments have been added / updated.
|
||||
- [ ] A changelog entry has been made for the appropriate packages.
|
||||
- [ ] Format code with the latest stable rustfmt
|
||||
|
||||
|
||||
## Overview
|
||||
|
18
.github/workflows/clippy.yml
vendored
18
.github/workflows/clippy.yml
vendored
@ -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
|
||||
|
@ -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 });
|
||||
|
@ -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)
|
||||
|
@ -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(),
|
||||
|
@ -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))
|
||||
|
@ -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());
|
||||
|
@ -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;
|
||||
|
@ -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>;
|
||||
}
|
||||
|
@ -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());
|
||||
|
@ -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;
|
||||
|
@ -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!(
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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,
|
||||
@ -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,
|
||||
@ -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 {
|
||||
@ -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());
|
||||
}
|
||||
@ -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::<ServiceResponse, _>(error::ErrorBadRequest("error"))
|
||||
}}))),
|
||||
process_fn: Arc::new(|req, _: BearerAuth| async {
|
||||
Ok(req) }),
|
||||
},
|
||||
))),
|
||||
process_fn: Arc::new(|req, _: BearerAuth| async { Ok(req) }),
|
||||
_extractor: PhantomData,
|
||||
};
|
||||
|
||||
@ -279,7 +263,6 @@ mod tests {
|
||||
|
||||
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::<ServiceResponse, _>(error::ErrorBadRequest("error"))
|
||||
}}))),
|
||||
process_fn: Arc::new(|req, _: BearerAuth| async {
|
||||
Ok(req) }),
|
||||
},
|
||||
))),
|
||||
process_fn: Arc::new(|req, _: BearerAuth| async { Ok(req) }),
|
||||
_extractor: PhantomData,
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user