Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix clippy warnings #73

Merged
merged 1 commit into from
Jul 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
71 changes: 31 additions & 40 deletions actix-identity/src/lib.rs
Expand Up @@ -46,6 +46,9 @@
//! .service(web::resource("/logout.html").to(logout));
//! }
//! ```

#![allow(clippy::needless_doctest_main)]

use std::cell::RefCell;
use std::future::Future;
use std::rc::Rc;
Expand Down Expand Up @@ -200,14 +203,12 @@ pub trait IdentityPolicy: Sized + 'static {
/// use actix_web::App;
/// use actix_identity::{CookieIdentityPolicy, IdentityService};
///
/// fn main() {
/// let app = App::new().wrap(IdentityService::new(
/// // <- create identity middleware
/// CookieIdentityPolicy::new(&[0; 32]) // <- create cookie session backend
/// .name("auth-cookie")
/// .secure(false),
/// ));
/// }
/// let app = App::new().wrap(IdentityService::new(
/// // <- create identity middleware
/// CookieIdentityPolicy::new(&[0; 32]) // <- create cookie session backend
/// .name("auth-cookie")
/// .secure(false),
/// ));
/// ```
pub struct IdentityService<T> {
backend: Rc<T>,
Expand Down Expand Up @@ -427,16 +428,12 @@ impl CookieIdentityInner {
let value: CookieValue = serde_json::from_str(cookie.value()).ok()?;
let now = SystemTime::now();
if let Some(visit_deadline) = self.visit_deadline {
if now.duration_since(value.visit_timestamp?).ok()?
> visit_deadline
{
if now.duration_since(value.visit_timestamp?).ok()? > visit_deadline {
return None;
}
}
if let Some(login_deadline) = self.login_deadline {
if now.duration_since(value.login_timestamp?).ok()?
> login_deadline
{
if now.duration_since(value.login_timestamp?).ok()? > login_deadline {
return None;
}
}
Expand Down Expand Up @@ -469,16 +466,14 @@ impl CookieIdentityInner {
/// use actix_web::App;
/// use actix_identity::{CookieIdentityPolicy, IdentityService};
///
/// fn main() {
/// let app = App::new().wrap(IdentityService::new(
/// // <- create identity middleware
/// CookieIdentityPolicy::new(&[0; 32]) // <- construct cookie policy
/// .domain("www.rust-lang.org")
/// .name("actix_auth")
/// .path("/")
/// .secure(true),
/// ));
/// }
/// let app = App::new().wrap(IdentityService::new(
/// // <- create identity middleware
/// CookieIdentityPolicy::new(&[0; 32]) // <- construct cookie policy
/// .domain("www.rust-lang.org")
/// .name("actix_auth")
/// .path("/")
/// .secure(true),
/// ));
/// ```
pub struct CookieIdentityPolicy(Rc<CookieIdentityInner>);

Expand Down Expand Up @@ -557,11 +552,7 @@ 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 Expand Up @@ -761,14 +752,12 @@ mod tests {
)
.secure(false)
.name(COOKIE_NAME))))
.service(web::resource("/").to(|id: Identity| {
async move {
let identity = id.identity();
if identity.is_none() {
id.remember(COOKIE_LOGIN.to_string())
}
web::Json(identity)
.service(web::resource("/").to(|id: Identity| async move {
let identity = id.identity();
if identity.is_none() {
id.remember(COOKIE_LOGIN.to_string())
}
web::Json(identity)
})),
)
.await
Expand Down Expand Up @@ -822,12 +811,14 @@ mod tests {
assert_eq!(cookie.value(), identity);
}

#[allow(clippy::enum_variant_names)]
enum LoginTimestampCheck {
NoTimestamp,
NewTimestamp,
OldTimestamp(SystemTime),
}

#[allow(clippy::enum_variant_names)]
enum VisitTimeStampCheck {
NoTimestamp,
NewTimestamp,
Expand Down Expand Up @@ -1108,12 +1099,12 @@ mod tests {

let mut srv = IdentityServiceMiddleware {
backend: Rc::new(Ident),
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(100)).await;
Err::<ServiceResponse, _>(error::ErrorBadRequest("error"))
}
}))),
},
))),
};

let mut srv2 = srv.clone();
Expand Down
6 changes: 3 additions & 3 deletions actix-protobuf/src/lib.rs
Expand Up @@ -144,10 +144,10 @@ impl<T: Message + Default> Responder for ProtoBuf<T> {
self.0
.encode(&mut buf)
.map_err(|e| Error::from(ProtoBufPayloadError::Serialize(e)))
.and_then(|()| {
Ok(HttpResponse::Ok()
.map(|()| {
HttpResponse::Ok()
.content_type("application/protobuf")
.body(buf))
.body(buf)
}),
)
}
Expand Down
27 changes: 10 additions & 17 deletions actix-session/src/cookie.rs
Expand Up @@ -203,15 +203,13 @@ impl CookieSessionInner {
/// use actix_session::CookieSession;
/// use actix_web::{web, App, HttpResponse, HttpServer};
///
/// fn main() {
/// let app = App::new().wrap(
/// CookieSession::signed(&[0; 32])
/// .domain("www.rust-lang.org")
/// .name("actix_session")
/// .path("/")
/// .secure(true))
/// .service(web::resource("/").to(|| HttpResponse::Ok()));
/// }
/// let app = App::new().wrap(
/// CookieSession::signed(&[0; 32])
/// .domain("www.rust-lang.org")
/// .name("actix_session")
/// .path("/")
/// .secure(true))
/// .service(web::resource("/").to(|| HttpResponse::Ok()));
/// ```
pub struct CookieSession(Rc<CookieSessionInner>);

Expand Down Expand Up @@ -256,7 +254,7 @@ impl CookieSession {

/// When true, prevents adding session cookies to responses until
/// the session contains data. Default is `false`.
///
///
/// Useful when trying to comply with laws that require consent for setting cookies.
pub fn lazy(mut self, value: bool) -> CookieSession {
Rc::get_mut(&mut self.0).unwrap().lazy = value;
Expand Down Expand Up @@ -451,18 +449,13 @@ mod tests {
let _ = ses.set("counter", 100);
"counting"
}))
.service(web::resource("/").to(|_ses: Session| async move {
"test"
})),
.service(web::resource("/").to(|_ses: Session| async move { "test" })),
)
.await;

let request = test::TestRequest::get().to_request();
let response = app.call(request).await.unwrap();
assert!(response
.response()
.cookies()
.count() == 0);
assert!(response.response().cookies().count() == 0);

let request = test::TestRequest::with_uri("/count").to_request();
let response = app.call(request).await.unwrap();
Expand Down
3 changes: 2 additions & 1 deletion actix-session/src/lib.rs
Expand Up @@ -276,7 +276,8 @@ mod tests {
let mut req = test::TestRequest::default().to_srv_request();

Session::set_session(
vec![("key".to_string(), serde_json::to_string("value").unwrap())].into_iter(),
vec![("key".to_string(), serde_json::to_string("value").unwrap())]
.into_iter(),
&mut req,
);
let session = Session::get_session(&mut *req.extensions_mut());
Expand Down