From 1e71a78c39c0f7268f65cfd56eb01af9a951517e Mon Sep 17 00:00:00 2001 From: leon3s Date: Mon, 3 Apr 2023 20:06:33 +0200 Subject: [PATCH] refactor: ntex version and some clippy warning --- ntex-cors/Cargo.toml | 4 +- ntex-cors/src/lib.rs | 12 ++-- ntex-files/Cargo.toml | 4 +- ntex-files/src/lib.rs | 78 +++++++++++++------------- ntex-identity/Cargo.toml | 4 +- ntex-identity/src/lib.rs | 103 +++++++++++++++++------------------ ntex-multipart/Cargo.toml | 4 +- ntex-multipart/src/server.rs | 16 +++--- ntex-session/Cargo.toml | 4 +- ntex-session/src/cookie.rs | 6 +- ntex-session/src/lib.rs | 32 ++++++----- 11 files changed, 129 insertions(+), 138 deletions(-) diff --git a/ntex-cors/Cargo.toml b/ntex-cors/Cargo.toml index 96173faf..169d31f0 100644 --- a/ntex-cors/Cargo.toml +++ b/ntex-cors/Cargo.toml @@ -16,9 +16,9 @@ name = "ntex_cors" path = "src/lib.rs" [dependencies] -ntex = "0.6.0-beta.0" +ntex = "0.6.5" derive_more = "0.99" futures = "0.3" [dev-dependencies] -ntex = { version = "0.6.0-beta.0", features=["tokio"] } +ntex = { version = "0.6.5", features=["tokio"] } diff --git a/ntex-cors/src/lib.rs b/ntex-cors/src/lib.rs index 67f03517..1035c73f 100644 --- a/ntex-cors/src/lib.rs +++ b/ntex-cors/src/lib.rs @@ -536,7 +536,7 @@ impl Inner { AllOrSome::Some(ref allowed_origins) => allowed_origins .get(origin) .map(|_| ()) - .ok_or_else(|| CorsError::OriginNotAllowed), + .ok_or(CorsError::OriginNotAllowed), }; } Err(CorsError::BadOrigin) @@ -553,10 +553,8 @@ impl Inner { AllOrSome::All => { if self.send_wildcard { Some(HeaderValue::from_static("*")) - } else if let Some(origin) = headers.get(&header::ORIGIN) { - Some(origin.clone()) } else { - None + headers.get(&header::ORIGIN).cloned() } } AllOrSome::Some(ref origins) => { @@ -582,7 +580,7 @@ impl Inner { .methods .get(&method) .map(|_| ()) - .ok_or_else(|| CorsError::MethodNotAllowed); + .ok_or(CorsError::MethodNotAllowed); } } Err(CorsError::BadRequestMethod) @@ -641,10 +639,8 @@ impl Inner { ) .unwrap(), ) - } else if let Some(hdr) = req.headers.get(&header::ACCESS_CONTROL_REQUEST_HEADERS) { - Some(hdr.clone()) } else { - None + req.headers.get(&header::ACCESS_CONTROL_REQUEST_HEADERS).cloned() }; let res = HttpResponse::Ok() diff --git a/ntex-files/Cargo.toml b/ntex-files/Cargo.toml index a5f1c7df..0e16513b 100644 --- a/ntex-files/Cargo.toml +++ b/ntex-files/Cargo.toml @@ -18,7 +18,7 @@ name = "ntex_files" path = "src/lib.rs" [dependencies] -ntex = "0.6.0-beta.0" +ntex = "0.6.5" ntex-http = "0.1.8" bitflags = "1.3" futures = "0.3" @@ -32,4 +32,4 @@ percent-encoding = "2.1" v_htmlescape = "0.14.1" [dev-dependencies] -ntex = { version = "0.6.0-beta.0", features=["tokio", "openssl", "compress"] } +ntex = { version = "0.6.5", features=["tokio", "openssl", "compress"] } diff --git a/ntex-files/src/lib.rs b/ntex-files/src/lib.rs index 09f58947..8b492c6d 100644 --- a/ntex-files/src/lib.rs +++ b/ntex-files/src/lib.rs @@ -500,7 +500,7 @@ where }; // full filepath - let path = match self.directory.join(&real_path.0).canonicalize() { + let path = match self.directory.join(real_path.0).canonicalize() { Ok(path) => path, Err(e) => return self.handle_io_error(e, req), }; @@ -855,13 +855,13 @@ mod tests { DispositionType::Attachment } - let mut srv = test::init_service(App::new().service( + let srv = test::init_service(App::new().service( Files::new("/", ".").mime_override(all_attachment).index_file("Cargo.toml"), )) .await; let request = TestRequest::get().uri("/").to_request(); - let response = test::call_service(&mut srv, request).await; + let response = test::call_service(&srv, request).await; assert_eq!(response.status(), StatusCode::OK); let content_disposition = response @@ -875,7 +875,7 @@ mod tests { #[ntex::test] async fn test_named_file_ranges_status_code() { - let mut srv = test::init_service( + let srv = test::init_service( App::new().service(Files::new("/test", ".").index_file("Cargo.toml")), ) .await; @@ -885,7 +885,7 @@ mod tests { .uri("/t%65st/Cargo.toml") .header(http::header::RANGE, "bytes=10-20") .to_request(); - let response = test::call_service(&mut srv, request).await; + let response = test::call_service(&srv, request).await; assert_eq!(response.status(), StatusCode::PARTIAL_CONTENT); // Invalid range header @@ -893,14 +893,14 @@ mod tests { .uri("/t%65st/Cargo.toml") .header(http::header::RANGE, "bytes=1-0") .to_request(); - let response = test::call_service(&mut srv, request).await; + let response = test::call_service(&srv, request).await; assert_eq!(response.status(), StatusCode::RANGE_NOT_SATISFIABLE); } #[ntex::test] async fn test_named_file_content_range_headers() { - let mut srv = test::init_service( + let srv = test::init_service( App::new().service(Files::new("/test", ".").index_file("tests/test.binary")), ) .await; @@ -911,7 +911,7 @@ mod tests { .header(http::header::RANGE, "bytes=10-20") .to_request(); - let response = test::call_service(&mut srv, request).await; + let response = test::call_service(&srv, request).await; let contentrange = response.headers().get(http::header::CONTENT_RANGE).unwrap().to_str().unwrap(); @@ -922,7 +922,7 @@ mod tests { .uri("/t%65st/tests/test.binary") .header(http::header::RANGE, "bytes=10-5") .to_request(); - let response = test::call_service(&mut srv, request).await; + let response = test::call_service(&srv, request).await; let contentrange = response.headers().get(http::header::CONTENT_RANGE).unwrap().to_str().unwrap(); @@ -932,7 +932,7 @@ mod tests { #[ntex::test] async fn test_named_file_content_length_headers() { - let mut srv = test::init_service( + let srv = test::init_service( App::new().service(Files::new("test", ".").index_file("tests/test.binary")), ) .await; @@ -942,7 +942,7 @@ mod tests { .uri("/t%65st/tests/test.binary") .header(http::header::RANGE, "bytes=10-20") .to_request(); - let _response = test::call_service(&mut srv, request).await; + let _response = test::call_service(&srv, request).await; // let contentlength = _response // .headers() @@ -957,7 +957,7 @@ mod tests { .uri("/t%65st/tests/test.binary") .header(http::header::RANGE, "bytes=10-8") .to_request(); - let response = test::call_service(&mut srv, request).await; + let response = test::call_service(&srv, request).await; assert_eq!(response.status(), StatusCode::RANGE_NOT_SATISFIABLE); // Without range header @@ -965,7 +965,7 @@ mod tests { .uri("/t%65st/tests/test.binary") // .no_default_headers() .to_request(); - let _response = test::call_service(&mut srv, request).await; + let _response = test::call_service(&srv, request).await; // let contentlength = response // .headers() @@ -977,7 +977,7 @@ mod tests { // chunked let request = TestRequest::get().uri("/t%65st/tests/test.binary").to_request(); - let response = test::call_service(&mut srv, request).await; + let response = test::call_service(&srv, request).await; // with enabled compression // { @@ -997,7 +997,7 @@ mod tests { #[ntex::test] async fn test_head_content_length_headers() { - let mut srv = test::init_service( + let srv = test::init_service( App::new().service(Files::new("test", ".").index_file("tests/test.binary")), ) .await; @@ -1007,7 +1007,7 @@ mod tests { .method(Method::HEAD) .uri("/t%65st/tests/test.binary") .to_request(); - let _response = test::call_service(&mut srv, request).await; + let _response = test::call_service(&srv, request).await; // TODO: fix check // let contentlength = response @@ -1036,35 +1036,35 @@ mod tests { #[ntex::test] async fn test_files_not_allowed() { - let mut srv = test::init_service(App::new().service(Files::new("/", "."))).await; + let srv = test::init_service(App::new().service(Files::new("/", "."))).await; let req = TestRequest::default().uri("/Cargo.toml").method(Method::POST).to_request(); - let resp = test::call_service(&mut srv, req).await; + let resp = test::call_service(&srv, req).await; assert_eq!(resp.status(), StatusCode::METHOD_NOT_ALLOWED); - let mut srv = test::init_service(App::new().service(Files::new("/", "."))).await; + let srv = test::init_service(App::new().service(Files::new("/", "."))).await; let req = TestRequest::default().method(Method::PUT).uri("/Cargo.toml").to_request(); - let resp = test::call_service(&mut srv, req).await; + let resp = test::call_service(&srv, req).await; assert_eq!(resp.status(), StatusCode::METHOD_NOT_ALLOWED); } #[ntex::test] async fn test_files_guards() { - let mut srv = test::init_service( + let srv = test::init_service( App::new().service(Files::new("/", ".").use_guards(guard::Post())), ) .await; let req = TestRequest::default().uri("/Cargo.toml").method(Method::POST).to_request(); - let resp = test::call_service(&mut srv, req).await; + let resp = test::call_service(&srv, req).await; assert_eq!(resp.status(), StatusCode::OK); } #[ntex::test] async fn test_named_file_content_encoding() { - let mut srv = test::init_service(App::new().wrap(Compress::default()).service( + let srv = test::init_service(App::new().wrap(Compress::default()).service( web::resource("/").to(|| async { NamedFile::open("Cargo.toml") .unwrap() @@ -1077,14 +1077,14 @@ mod tests { .uri("/") .header(http::header::ACCEPT_ENCODING, "gzip") .to_request(); - let res = test::call_service(&mut srv, request).await; + let res = test::call_service(&srv, request).await; assert_eq!(res.status(), StatusCode::OK); assert!(!res.headers().contains_key(http::header::CONTENT_ENCODING)); } #[ntex::test] async fn test_named_file_content_encoding_gzip() { - let mut srv = test::init_service(App::new().wrap(Compress::default()).service( + let srv = test::init_service(App::new().wrap(Compress::default()).service( web::resource("/").to(|| async { NamedFile::open("Cargo.toml") .unwrap() @@ -1097,7 +1097,7 @@ mod tests { .uri("/") .header(http::header::ACCEPT_ENCODING, "gzip") .to_request(); - let res = test::call_service(&mut srv, request).await; + let res = test::call_service(&srv, request).await; assert_eq!(res.status(), StatusCode::OK); assert_eq!( res.headers().get(http::header::CONTENT_ENCODING).unwrap().to_str().unwrap(), @@ -1115,25 +1115,25 @@ mod tests { #[ntex::test] async fn test_static_files() { - let mut srv = + let srv = test::init_service(App::new().service(Files::new("/", ".").show_files_listing())) .await; let req = TestRequest::with_uri("/missing").to_request(); - let resp = test::call_service(&mut srv, req).await; + let resp = test::call_service(&srv, req).await; assert_eq!(resp.status(), StatusCode::NOT_FOUND); - let mut srv = test::init_service(App::new().service(Files::new("/", "."))).await; + let srv = test::init_service(App::new().service(Files::new("/", "."))).await; let req = TestRequest::default().to_request(); - let resp = test::call_service(&mut srv, req).await; + let resp = test::call_service(&srv, req).await; assert_eq!(resp.status(), StatusCode::NOT_FOUND); - let mut srv = + let srv = test::init_service(App::new().service(Files::new("/", ".").show_files_listing())) .await; let req = TestRequest::with_uri("/tests").to_request(); - let resp = test::call_service(&mut srv, req).await; + let resp = test::call_service(&srv, req).await; assert_eq!( resp.headers().get(http::header::CONTENT_TYPE).unwrap(), "text/html; charset=utf-8" @@ -1146,26 +1146,26 @@ mod tests { #[ntex::test] async fn test_redirect_to_slash_directory() { // should not redirect if no index - let mut srv = test::init_service( + let srv = test::init_service( App::new().service(Files::new("/", ".").redirect_to_slash_directory()), ) .await; let req = TestRequest::with_uri("/tests").to_request(); - let resp = test::call_service(&mut srv, req).await; + let resp = test::call_service(&srv, req).await; assert_eq!(resp.status(), StatusCode::NOT_FOUND); // should redirect if index present - let mut srv = test::init_service(App::new().service( + let srv = test::init_service(App::new().service( Files::new("/", ".").index_file("test.png").redirect_to_slash_directory(), )) .await; let req = TestRequest::with_uri("/tests").to_request(); - let resp = test::call_service(&mut srv, req).await; + let resp = test::call_service(&srv, req).await; assert_eq!(resp.status(), StatusCode::FOUND); // should not redirect if the path is wrong let req = TestRequest::with_uri("/not_existing").to_request(); - let resp = test::call_service(&mut srv, req).await; + let resp = test::call_service(&srv, req).await; assert_eq!(resp.status(), StatusCode::NOT_FOUND); } @@ -1257,7 +1257,7 @@ mod tests { // #[ntex::test] // fn integration_serve_index() { - // let mut srv = test::TestServer::with_factory(|| { + // let srv = test::TestServer::with_factory(|| { // App::new().handler( // "test", // Files::new(".").index_file("Cargo.toml"), @@ -1290,7 +1290,7 @@ mod tests { // #[ntex::test] // fn integration_percent_encoded() { - // let mut srv = test::TestServer::with_factory(|| { + // let srv = test::TestServer::with_factory(|| { // App::new().handler( // "test", // Files::new(".").index_file("Cargo.toml"), diff --git a/ntex-identity/Cargo.toml b/ntex-identity/Cargo.toml index bf403a23..22a3afa3 100644 --- a/ntex-identity/Cargo.toml +++ b/ntex-identity/Cargo.toml @@ -21,7 +21,7 @@ default = ["cookie-policy"] cookie-policy = ["cookie/secure", "ntex/cookie"] [dependencies] -ntex = "0.6.0-beta.0" +ntex = "0.6.5" futures = "0.3" serde = "1.0" serde_json = "1.0" @@ -30,4 +30,4 @@ cookie = { version = "0.17", features = ["private"] } time = { version = "0.3", default-features = false, features = ["std"] } [dev-dependencies] -ntex = { version = "0.6.0-beta.0", features=["tokio"] } +ntex = { version = "0.6.5", features=["tokio"] } diff --git a/ntex-identity/src/lib.rs b/ntex-identity/src/lib.rs index 26dd0b0e..93f4dea5 100644 --- a/ntex-identity/src/lib.rs +++ b/ntex-identity/src/lib.rs @@ -366,10 +366,10 @@ impl CookieIdentityInner { let mut jar = CookieJar::new(); let key = if self.legacy_supported() { &self.key } else { &self.key_v2 }; if add_cookie { - jar.private_mut(&key).add(cookie); + jar.private_mut(key).add(cookie); } else { jar.add_original(cookie.clone()); - jar.private_mut(&key).remove(cookie); + jar.private_mut(key).remove(cookie); } for cookie in jar.delta() { let val = HeaderValue::from_str(&cookie.to_string()).map_err(HttpError::from)?; @@ -588,12 +588,12 @@ mod tests { use ntex::{http::StatusCode, service::into_service, time}; const COOKIE_KEY_MASTER: [u8; 32] = [0; 32]; - const COOKIE_NAME: &'static str = "ntex_auth"; - const COOKIE_LOGIN: &'static str = "test"; + const COOKIE_NAME: &str = "ntex_auth"; + const COOKIE_LOGIN: &str = "test"; #[ntex::test] async fn test_identity() { - let mut srv = test::init_service( + let srv = test::init_service( App::new() .wrap(IdentityService::new( CookieIdentityPolicy::new(&COOKIE_KEY_MASTER) @@ -623,24 +623,22 @@ mod tests { })), ) .await; - let resp = - test::call_service(&mut srv, TestRequest::with_uri("/index").to_request()).await; + let resp = test::call_service(&srv, TestRequest::with_uri("/index").to_request()).await; assert_eq!(resp.status(), StatusCode::OK); - let resp = - test::call_service(&mut srv, TestRequest::with_uri("/login").to_request()).await; + let resp = test::call_service(&srv, TestRequest::with_uri("/login").to_request()).await; assert_eq!(resp.status(), StatusCode::OK); let c = resp.response().cookies().next().unwrap().to_owned(); let resp = test::call_service( - &mut srv, + &srv, TestRequest::with_uri("/index").cookie(c.clone()).to_request(), ) .await; assert_eq!(resp.status(), StatusCode::CREATED); let resp = test::call_service( - &mut srv, + &srv, TestRequest::with_uri("/logout").cookie(c.clone()).to_request(), ) .await; @@ -651,7 +649,7 @@ mod tests { #[ntex::test] async fn test_identity_max_age_time() { let duration = Duration::days(1); - let mut srv = test::init_service( + let srv = test::init_service( App::new() .wrap(IdentityService::new( CookieIdentityPolicy::new(&COOKIE_KEY_MASTER) @@ -667,8 +665,7 @@ mod tests { })), ) .await; - let resp = - test::call_service(&mut srv, TestRequest::with_uri("/login").to_request()).await; + let resp = test::call_service(&srv, TestRequest::with_uri("/login").to_request()).await; assert_eq!(resp.status(), StatusCode::OK); assert!(resp.headers().contains_key(header::SET_COOKIE)); let c = resp.response().cookies().next().unwrap().to_owned(); @@ -678,7 +675,7 @@ mod tests { #[ntex::test] async fn test_identity_max_age() { let seconds = 60; - let mut srv = test::init_service( + let srv = test::init_service( App::new() .wrap(IdentityService::new( CookieIdentityPolicy::new(&COOKIE_KEY_MASTER) @@ -694,12 +691,11 @@ mod tests { })), ) .await; - let resp = - test::call_service(&mut srv, TestRequest::with_uri("/login").to_request()).await; + let resp = test::call_service(&srv, TestRequest::with_uri("/login").to_request()).await; assert_eq!(resp.status(), StatusCode::OK); assert!(resp.headers().contains_key(header::SET_COOKIE)); let c = resp.response().cookies().next().unwrap().to_owned(); - assert_eq!(Duration::seconds(seconds as i64), c.max_age().unwrap()); + assert_eq!(Duration::seconds(seconds), c.max_age().unwrap()); } async fn create_identity_server< @@ -738,7 +734,7 @@ mod tests { ) -> Cookie<'static> { let mut jar = CookieJar::new(); let key: Vec = - COOKIE_KEY_MASTER.iter().chain([1, 0, 0, 0].iter()).map(|e| *e).collect(); + COOKIE_KEY_MASTER.iter().chain([1, 0, 0, 0].iter()).copied().collect(); jar.private_mut(&Key::derive_from(&key)).add(Cookie::new( COOKIE_NAME, serde_json::to_string(&CookieValue { @@ -768,9 +764,9 @@ mod tests { } enum LoginTimestampCheck { - NoTimestamp, - NewTimestamp, - OldTimestamp(SystemTime), + Incorrect, + New, + Old(SystemTime), } enum VisitTimeStampCheck { @@ -789,18 +785,18 @@ mod tests { cookies.add(Cookie::parse(cookie.to_str().unwrap().to_string()).unwrap()); } let key: Vec = - COOKIE_KEY_MASTER.iter().chain([1, 0, 0, 0].iter()).map(|e| *e).collect(); + COOKIE_KEY_MASTER.iter().chain([1, 0, 0, 0].iter()).copied().collect(); let cookie = cookies.private(&Key::derive_from(&key)).get(COOKIE_NAME).unwrap(); let cv: CookieValue = serde_json::from_str(cookie.value()).unwrap(); assert_eq!(cv.identity, identity); let now = SystemTime::now(); let t30sec_ago = now - Duration::seconds(30); match login_timestamp { - LoginTimestampCheck::NoTimestamp => assert_eq!(cv.login_timestamp, None), - LoginTimestampCheck::NewTimestamp => assert!( + LoginTimestampCheck::Incorrect => assert_eq!(cv.login_timestamp, None), + LoginTimestampCheck::New => assert!( t30sec_ago <= cv.login_timestamp.unwrap() && cv.login_timestamp.unwrap() <= now ), - LoginTimestampCheck::OldTimestamp(old_timestamp) => { + LoginTimestampCheck::Old(old_timestamp) => { assert_eq!(cv.login_timestamp, Some(old_timestamp)) } } @@ -822,19 +818,18 @@ mod tests { #[ntex::test] async fn test_identity_legacy_cookie_is_set() { - let mut srv = create_identity_server(|c| c).await; - let mut resp = - test::call_service(&mut srv, TestRequest::with_uri("/").to_request()).await; + let srv = create_identity_server(|c| c).await; + let mut resp = test::call_service(&srv, TestRequest::with_uri("/").to_request()).await; assert_legacy_login_cookie(&mut resp, COOKIE_LOGIN); assert_logged_in(resp, None).await; } #[ntex::test] async fn test_identity_legacy_cookie_works() { - let mut srv = create_identity_server(|c| c).await; + let srv = create_identity_server(|c| c).await; let cookie = legacy_login_cookie(COOKIE_LOGIN); let mut resp = test::call_service( - &mut srv, + &srv, TestRequest::with_uri("/").cookie(cookie.clone()).to_request(), ) .await; @@ -844,17 +839,17 @@ mod tests { #[ntex::test] async fn test_identity_legacy_cookie_rejected_if_visit_timestamp_needed() { - let mut srv = create_identity_server(|c| c.visit_deadline(Duration::days(90))).await; + let srv = create_identity_server(|c| c.visit_deadline(Duration::days(90))).await; let cookie = legacy_login_cookie(COOKIE_LOGIN); let mut resp = test::call_service( - &mut srv, + &srv, TestRequest::with_uri("/").cookie(cookie.clone()).to_request(), ) .await; assert_login_cookie( &mut resp, COOKIE_LOGIN, - LoginTimestampCheck::NoTimestamp, + LoginTimestampCheck::Incorrect, VisitTimeStampCheck::NewTimestamp, ); assert_logged_in(resp, None).await; @@ -862,17 +857,17 @@ mod tests { #[ntex::test] async fn test_identity_legacy_cookie_rejected_if_login_timestamp_needed() { - let mut srv = create_identity_server(|c| c.login_deadline(Duration::days(90))).await; + let srv = create_identity_server(|c| c.login_deadline(Duration::days(90))).await; let cookie = legacy_login_cookie(COOKIE_LOGIN); let mut resp = test::call_service( - &mut srv, + &srv, TestRequest::with_uri("/").cookie(cookie.clone()).to_request(), ) .await; assert_login_cookie( &mut resp, COOKIE_LOGIN, - LoginTimestampCheck::NewTimestamp, + LoginTimestampCheck::New, VisitTimeStampCheck::NoTimestamp, ); assert_logged_in(resp, None).await; @@ -880,17 +875,17 @@ mod tests { #[ntex::test] async fn test_identity_cookie_rejected_if_login_timestamp_needed() { - let mut srv = create_identity_server(|c| c.login_deadline(Duration::days(90))).await; + let srv = create_identity_server(|c| c.login_deadline(Duration::days(90))).await; let cookie = login_cookie(COOKIE_LOGIN, None, Some(SystemTime::now())); let mut resp = test::call_service( - &mut srv, + &srv, TestRequest::with_uri("/").cookie(cookie.clone()).to_request(), ) .await; assert_login_cookie( &mut resp, COOKIE_LOGIN, - LoginTimestampCheck::NewTimestamp, + LoginTimestampCheck::New, VisitTimeStampCheck::NoTimestamp, ); assert_logged_in(resp, None).await; @@ -898,17 +893,17 @@ mod tests { #[ntex::test] async fn test_identity_cookie_rejected_if_visit_timestamp_needed() { - let mut srv = create_identity_server(|c| c.visit_deadline(Duration::days(90))).await; + let srv = create_identity_server(|c| c.visit_deadline(Duration::days(90))).await; let cookie = login_cookie(COOKIE_LOGIN, Some(SystemTime::now()), None); let mut resp = test::call_service( - &mut srv, + &srv, TestRequest::with_uri("/").cookie(cookie.clone()).to_request(), ) .await; assert_login_cookie( &mut resp, COOKIE_LOGIN, - LoginTimestampCheck::NoTimestamp, + LoginTimestampCheck::Incorrect, VisitTimeStampCheck::NewTimestamp, ); assert_logged_in(resp, None).await; @@ -916,18 +911,18 @@ mod tests { #[ntex::test] async fn test_identity_cookie_rejected_if_login_timestamp_too_old() { - let mut srv = create_identity_server(|c| c.login_deadline(Duration::days(90))).await; + let srv = create_identity_server(|c| c.login_deadline(Duration::days(90))).await; let cookie = login_cookie(COOKIE_LOGIN, Some(SystemTime::now() - Duration::days(180)), None); let mut resp = test::call_service( - &mut srv, + &srv, TestRequest::with_uri("/").cookie(cookie.clone()).to_request(), ) .await; assert_login_cookie( &mut resp, COOKIE_LOGIN, - LoginTimestampCheck::NewTimestamp, + LoginTimestampCheck::New, VisitTimeStampCheck::NoTimestamp, ); assert_logged_in(resp, None).await; @@ -935,18 +930,18 @@ mod tests { #[ntex::test] async fn test_identity_cookie_rejected_if_visit_timestamp_too_old() { - let mut srv = create_identity_server(|c| c.visit_deadline(Duration::days(90))).await; + let srv = create_identity_server(|c| c.visit_deadline(Duration::days(90))).await; let cookie = login_cookie(COOKIE_LOGIN, None, Some(SystemTime::now() - Duration::days(180))); let mut resp = test::call_service( - &mut srv, + &srv, TestRequest::with_uri("/").cookie(cookie.clone()).to_request(), ) .await; assert_login_cookie( &mut resp, COOKIE_LOGIN, - LoginTimestampCheck::NoTimestamp, + LoginTimestampCheck::Incorrect, VisitTimeStampCheck::NewTimestamp, ); assert_logged_in(resp, None).await; @@ -954,10 +949,10 @@ mod tests { #[ntex::test] async fn test_identity_cookie_not_updated_on_login_deadline() { - let mut srv = create_identity_server(|c| c.login_deadline(Duration::days(90))).await; + let srv = create_identity_server(|c| c.login_deadline(Duration::days(90))).await; let cookie = login_cookie(COOKIE_LOGIN, Some(SystemTime::now()), None); let mut resp = test::call_service( - &mut srv, + &srv, TestRequest::with_uri("/").cookie(cookie.clone()).to_request(), ) .await; @@ -968,21 +963,21 @@ mod tests { // https://github.com/actix/actix-web/issues/1263 #[ntex::test] async fn test_identity_cookie_updated_on_visit_deadline() { - let mut srv = create_identity_server(|c| { + let srv = create_identity_server(|c| { c.visit_deadline(Duration::days(90)).login_deadline(Duration::days(90)) }) .await; let timestamp = SystemTime::now() - Duration::days(1); let cookie = login_cookie(COOKIE_LOGIN, Some(timestamp), Some(timestamp)); let mut resp = test::call_service( - &mut srv, + &srv, TestRequest::with_uri("/").cookie(cookie.clone()).to_request(), ) .await; assert_login_cookie( &mut resp, COOKIE_LOGIN, - LoginTimestampCheck::OldTimestamp(timestamp), + LoginTimestampCheck::Old(timestamp), VisitTimeStampCheck::NewTimestamp, ); assert_logged_in(resp, Some(COOKIE_LOGIN)).await; diff --git a/ntex-multipart/Cargo.toml b/ntex-multipart/Cargo.toml index 384d11eb..c3fde52f 100644 --- a/ntex-multipart/Cargo.toml +++ b/ntex-multipart/Cargo.toml @@ -16,7 +16,7 @@ name = "ntex_multipart" path = "src/lib.rs" [dependencies] -ntex = "0.6.0-beta.0" +ntex = "0.6.5" derive_more = "0.99" httparse = "1.3" futures = "0.3" @@ -25,4 +25,4 @@ mime = "0.3" twoway = "0.2" [dev-dependencies] -ntex = { version = "0.6.0-beta.0", features=["tokio"] } +ntex = { version = "0.6.5", features=["tokio"] } diff --git a/ntex-multipart/src/server.rs b/ntex-multipart/src/server.rs index bb7e494c..1dfe4fbb 100644 --- a/ntex-multipart/src/server.rs +++ b/ntex-multipart/src/server.rs @@ -261,10 +261,8 @@ impl InnerMultipart { match self.state { // read until first boundary InnerState::FirstBoundary => { - match InnerMultipart::skip_until_boundary( - &mut *payload, - &self.boundary, - )? { + match InnerMultipart::skip_until_boundary(&mut payload, &self.boundary)? + { Some(eof) => { if eof { self.state = InnerState::Eof; @@ -278,7 +276,7 @@ impl InnerMultipart { } // read boundary InnerState::Boundary => { - match InnerMultipart::read_boundary(&mut *payload, &self.boundary)? { + match InnerMultipart::read_boundary(&mut payload, &self.boundary)? { None => return Poll::Pending, Some(eof) => { if eof { @@ -295,7 +293,7 @@ impl InnerMultipart { // read field headers for next field if self.state == InnerState::Headers { - if let Some(headers) = InnerMultipart::read_headers(&mut *payload)? { + if let Some(headers) = InnerMultipart::read_headers(&mut payload)? { self.state = InnerState::Boundary; headers } else { @@ -547,9 +545,9 @@ impl InnerField { let result = if let Some(mut payload) = self.payload.as_ref().unwrap().get_mut(s) { if !self.eof { let res = if let Some(ref mut len) = self.length { - InnerField::read_len(&mut *payload, len) + InnerField::read_len(&mut payload, len) } else { - InnerField::read_stream(&mut *payload, &self.boundary) + InnerField::read_stream(&mut payload, &self.boundary) }; match res { @@ -810,7 +808,7 @@ mod tests { impl SlowStream { fn new(bytes: Bytes) -> SlowStream { - return SlowStream { bytes, pos: 0, ready: false }; + SlowStream { bytes, pos: 0, ready: false } } } diff --git a/ntex-session/Cargo.toml b/ntex-session/Cargo.toml index 5532b01f..74a38344 100644 --- a/ntex-session/Cargo.toml +++ b/ntex-session/Cargo.toml @@ -22,7 +22,7 @@ default = ["cookie-session"] cookie-session = ["cookie/secure", "ntex/cookie"] [dependencies] -ntex = "0.6.0-beta.0" +ntex = "0.6.5" cookie = "0.17" derive_more = "0.99" futures = "0.3" @@ -31,4 +31,4 @@ serde_json = "1.0" time = { version = "0.3", default-features = false, features = ["std"] } [dev-dependencies] -ntex = { version = "0.6.0-beta.0", features=["tokio"] } +ntex = { version = "0.6.5", features=["tokio"] } diff --git a/ntex-session/src/cookie.rs b/ntex-session/src/cookie.rs index b3c15cd0..b8329931 100644 --- a/ntex-session/src/cookie.rs +++ b/ntex-session/src/cookie.rs @@ -378,7 +378,7 @@ mod tests { let request = test::TestRequest::get().to_request(); let response = app.call(request).await.unwrap(); - assert!(response.response().cookies().find(|c| c.name() == "ntex-session").is_some()); + assert!(response.response().cookies().any(|c| c.name() == "ntex-session")); } #[ntex::test] @@ -395,7 +395,7 @@ mod tests { let request = test::TestRequest::get().to_request(); let response = app.call(request).await.unwrap(); - assert!(response.response().cookies().find(|c| c.name() == "ntex-session").is_some()); + assert!(response.response().cookies().any(|c| c.name() == "ntex-session")); } #[ntex::test] @@ -412,7 +412,7 @@ mod tests { let request = test::TestRequest::get().to_request(); let response = app.call(request).await.unwrap(); - assert!(response.response().cookies().find(|c| c.name() == "ntex-session").is_some()); + assert!(response.response().cookies().any(|c| c.name() == "ntex-session")); } #[ntex::test] diff --git a/ntex-session/src/lib.rs b/ntex-session/src/lib.rs index 998ea28c..776bd02d 100644 --- a/ntex-session/src/lib.rs +++ b/ntex-session/src/lib.rs @@ -89,19 +89,19 @@ pub trait UserSession { impl UserSession for HttpRequest { fn get_session(&self) -> Session { - Session::get_session(&mut *self.extensions_mut()) + Session::get_session(&mut self.extensions_mut()) } } impl UserSession for WebRequest { fn get_session(&self) -> Session { - Session::get_session(&mut *self.extensions_mut()) + Session::get_session(&mut self.extensions_mut()) } } impl UserSession for RequestHead { fn get_session(&self) -> Session { - Session::get_session(&mut *self.extensions_mut()) + Session::get_session(&mut self.extensions_mut()) } } @@ -112,6 +112,8 @@ pub enum SessionStatus { Renewed, Unchanged, } + +/// #[default] macro can be used but will depend on specific rust version impl Default for SessionStatus { fn default() -> SessionStatus { SessionStatus::Unchanged @@ -181,7 +183,7 @@ impl Session { data: impl Iterator, req: &WebRequest, ) { - let session = Session::get_session(&mut *req.extensions_mut()); + let session = Session::get_session(&mut req.extensions_mut()); let mut inner = session.0.borrow_mut(); inner.state.extend(data); } @@ -190,7 +192,7 @@ impl Session { res: &mut WebResponse, ) -> (SessionStatus, Option>) { if let Some(s_impl) = res.request().extensions().get::>>() { - let state = std::mem::replace(&mut s_impl.borrow_mut().state, HashMap::new()); + let state = std::mem::take(&mut s_impl.borrow_mut().state); (s_impl.borrow().status.clone(), Some(state.into_iter())) } else { (SessionStatus::Unchanged, None) @@ -199,7 +201,7 @@ impl Session { fn get_session(extensions: &mut Extensions) -> Session { if let Some(s_impl) = extensions.get::>>() { - return Session(Rc::clone(&s_impl)); + return Session(Rc::clone(s_impl)); } let inner = Rc::new(RefCell::new(SessionInner::default())); extensions.insert(inner.clone()); @@ -230,7 +232,7 @@ impl FromRequest for Session { #[inline] fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future { - ok(Session::get_session(&mut *req.extensions_mut())) + ok(Session::get_session(&mut req.extensions_mut())) } } @@ -242,13 +244,13 @@ mod tests { #[test] fn session() { - let mut req = test::TestRequest::default().to_srv_request(); + let req = test::TestRequest::default().to_srv_request(); Session::set_session( vec![("key".to_string(), "\"value\"".to_string())].into_iter(), - &mut req, + &req, ); - let session = Session::get_session(&mut *req.extensions_mut()); + let session = Session::get_session(&mut req.extensions_mut()); let res = session.get::("key").unwrap(); assert_eq!(res, Some("value".to_string())); @@ -263,11 +265,11 @@ mod tests { #[test] fn get_session() { - let mut req = test::TestRequest::default().to_srv_request(); + let req = test::TestRequest::default().to_srv_request(); Session::set_session( vec![("key".to_string(), "\"value\"".to_string())].into_iter(), - &mut req, + &req, ); let session = req.get_session(); @@ -281,7 +283,7 @@ mod tests { Session::set_session( vec![("key".to_string(), "\"value\"".to_string())].into_iter(), - &mut req, + &req, ); let session = req.head_mut().get_session(); @@ -292,7 +294,7 @@ mod tests { #[test] fn purge_session() { let req = test::TestRequest::default().to_srv_request(); - let session = Session::get_session(&mut *req.extensions_mut()); + let session = Session::get_session(&mut req.extensions_mut()); assert_eq!(session.0.borrow().status, SessionStatus::Unchanged); session.purge(); assert_eq!(session.0.borrow().status, SessionStatus::Purged); @@ -301,7 +303,7 @@ mod tests { #[test] fn renew_session() { let req = test::TestRequest::default().to_srv_request(); - let session = Session::get_session(&mut *req.extensions_mut()); + let session = Session::get_session(&mut req.extensions_mut()); assert_eq!(session.0.borrow().status, SessionStatus::Unchanged); session.renew(); assert_eq!(session.0.borrow().status, SessionStatus::Renewed);