refactor: ntex version and some clippy warning (#7)

* refactor: ntex version and some clippy warning

* refactor(workflow): linux default MSRV version to 1.65

* bugfix(workflow): windows openssl install
This commit is contained in:
leone 2023-04-04 00:08:44 +02:00 committed by GitHub
parent 39f93ab05e
commit 7f7a9faaab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 132 additions and 143 deletions

View file

@ -8,7 +8,7 @@ jobs:
fail-fast: false fail-fast: false
matrix: matrix:
version: version:
- 1.56.0 # MSRV - 1.65.0 # MSRV
- stable - stable
- nightly - nightly

View file

@ -54,13 +54,11 @@ jobs:
run: | run: |
vcpkg integrate install vcpkg integrate install
vcpkg install openssl:x64-windows vcpkg install openssl:x64-windows
Copy-Item C:\vcpkg\installed\x64-windows\bin\libcrypto-1_1-x64.dll C:\vcpkg\installed\x64-windows\bin\libcrypto.dll
Copy-Item C:\vcpkg\installed\x64-windows\bin\libssl-1_1-x64.dll C:\vcpkg\installed\x64-windows\bin\libssl.dll
Get-ChildItem C:\vcpkg\installed\x64-windows\bin
Get-ChildItem C:\vcpkg\installed\x64-windows\lib
- name: Run tests - name: Run tests
uses: actions-rs/cargo@v1 uses: actions-rs/cargo@v1
env:
OPENSSL_ROOT_DIR: D:\vcpkg\installed\x64-windows-static-md
with: with:
command: test command: test
args: --all --all-features -- --nocapture args: --all --all-features -- --nocapture

View file

@ -16,9 +16,9 @@ name = "ntex_cors"
path = "src/lib.rs" path = "src/lib.rs"
[dependencies] [dependencies]
ntex = "0.6.0-beta.0" ntex = "0.6.5"
derive_more = "0.99" derive_more = "0.99"
futures = "0.3" futures = "0.3"
[dev-dependencies] [dev-dependencies]
ntex = { version = "0.6.0-beta.0", features=["tokio"] } ntex = { version = "0.6.5", features=["tokio"] }

View file

@ -536,7 +536,7 @@ impl Inner {
AllOrSome::Some(ref allowed_origins) => allowed_origins AllOrSome::Some(ref allowed_origins) => allowed_origins
.get(origin) .get(origin)
.map(|_| ()) .map(|_| ())
.ok_or_else(|| CorsError::OriginNotAllowed), .ok_or(CorsError::OriginNotAllowed),
}; };
} }
Err(CorsError::BadOrigin) Err(CorsError::BadOrigin)
@ -553,10 +553,8 @@ impl Inner {
AllOrSome::All => { AllOrSome::All => {
if self.send_wildcard { if self.send_wildcard {
Some(HeaderValue::from_static("*")) Some(HeaderValue::from_static("*"))
} else if let Some(origin) = headers.get(&header::ORIGIN) {
Some(origin.clone())
} else { } else {
None headers.get(&header::ORIGIN).cloned()
} }
} }
AllOrSome::Some(ref origins) => { AllOrSome::Some(ref origins) => {
@ -582,7 +580,7 @@ impl Inner {
.methods .methods
.get(&method) .get(&method)
.map(|_| ()) .map(|_| ())
.ok_or_else(|| CorsError::MethodNotAllowed); .ok_or(CorsError::MethodNotAllowed);
} }
} }
Err(CorsError::BadRequestMethod) Err(CorsError::BadRequestMethod)
@ -641,10 +639,8 @@ impl Inner {
) )
.unwrap(), .unwrap(),
) )
} else if let Some(hdr) = req.headers.get(&header::ACCESS_CONTROL_REQUEST_HEADERS) {
Some(hdr.clone())
} else { } else {
None req.headers.get(&header::ACCESS_CONTROL_REQUEST_HEADERS).cloned()
}; };
let res = HttpResponse::Ok() let res = HttpResponse::Ok()

View file

@ -18,7 +18,7 @@ name = "ntex_files"
path = "src/lib.rs" path = "src/lib.rs"
[dependencies] [dependencies]
ntex = "0.6.0-beta.0" ntex = "0.6.5"
ntex-http = "0.1.8" ntex-http = "0.1.8"
bitflags = "1.3" bitflags = "1.3"
futures = "0.3" futures = "0.3"
@ -32,4 +32,4 @@ percent-encoding = "2.1"
v_htmlescape = "0.14.1" v_htmlescape = "0.14.1"
[dev-dependencies] [dev-dependencies]
ntex = { version = "0.6.0-beta.0", features=["tokio", "openssl", "compress"] } ntex = { version = "0.6.5", features=["tokio", "openssl", "compress"] }

View file

@ -500,7 +500,7 @@ where
}; };
// full filepath // 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, Ok(path) => path,
Err(e) => return self.handle_io_error(e, req), Err(e) => return self.handle_io_error(e, req),
}; };
@ -855,13 +855,13 @@ mod tests {
DispositionType::Attachment 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"), Files::new("/", ".").mime_override(all_attachment).index_file("Cargo.toml"),
)) ))
.await; .await;
let request = TestRequest::get().uri("/").to_request(); 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); assert_eq!(response.status(), StatusCode::OK);
let content_disposition = response let content_disposition = response
@ -875,7 +875,7 @@ mod tests {
#[ntex::test] #[ntex::test]
async fn test_named_file_ranges_status_code() { 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")), App::new().service(Files::new("/test", ".").index_file("Cargo.toml")),
) )
.await; .await;
@ -885,7 +885,7 @@ mod tests {
.uri("/t%65st/Cargo.toml") .uri("/t%65st/Cargo.toml")
.header(http::header::RANGE, "bytes=10-20") .header(http::header::RANGE, "bytes=10-20")
.to_request(); .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); assert_eq!(response.status(), StatusCode::PARTIAL_CONTENT);
// Invalid range header // Invalid range header
@ -893,14 +893,14 @@ mod tests {
.uri("/t%65st/Cargo.toml") .uri("/t%65st/Cargo.toml")
.header(http::header::RANGE, "bytes=1-0") .header(http::header::RANGE, "bytes=1-0")
.to_request(); .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); assert_eq!(response.status(), StatusCode::RANGE_NOT_SATISFIABLE);
} }
#[ntex::test] #[ntex::test]
async fn test_named_file_content_range_headers() { 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")), App::new().service(Files::new("/test", ".").index_file("tests/test.binary")),
) )
.await; .await;
@ -911,7 +911,7 @@ mod tests {
.header(http::header::RANGE, "bytes=10-20") .header(http::header::RANGE, "bytes=10-20")
.to_request(); .to_request();
let response = test::call_service(&mut srv, request).await; let response = test::call_service(&srv, request).await;
let contentrange = let contentrange =
response.headers().get(http::header::CONTENT_RANGE).unwrap().to_str().unwrap(); response.headers().get(http::header::CONTENT_RANGE).unwrap().to_str().unwrap();
@ -922,7 +922,7 @@ mod tests {
.uri("/t%65st/tests/test.binary") .uri("/t%65st/tests/test.binary")
.header(http::header::RANGE, "bytes=10-5") .header(http::header::RANGE, "bytes=10-5")
.to_request(); .to_request();
let response = test::call_service(&mut srv, request).await; let response = test::call_service(&srv, request).await;
let contentrange = let contentrange =
response.headers().get(http::header::CONTENT_RANGE).unwrap().to_str().unwrap(); response.headers().get(http::header::CONTENT_RANGE).unwrap().to_str().unwrap();
@ -932,7 +932,7 @@ mod tests {
#[ntex::test] #[ntex::test]
async fn test_named_file_content_length_headers() { 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")), App::new().service(Files::new("test", ".").index_file("tests/test.binary")),
) )
.await; .await;
@ -942,7 +942,7 @@ mod tests {
.uri("/t%65st/tests/test.binary") .uri("/t%65st/tests/test.binary")
.header(http::header::RANGE, "bytes=10-20") .header(http::header::RANGE, "bytes=10-20")
.to_request(); .to_request();
let _response = test::call_service(&mut srv, request).await; let _response = test::call_service(&srv, request).await;
// let contentlength = _response // let contentlength = _response
// .headers() // .headers()
@ -957,7 +957,7 @@ mod tests {
.uri("/t%65st/tests/test.binary") .uri("/t%65st/tests/test.binary")
.header(http::header::RANGE, "bytes=10-8") .header(http::header::RANGE, "bytes=10-8")
.to_request(); .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); assert_eq!(response.status(), StatusCode::RANGE_NOT_SATISFIABLE);
// Without range header // Without range header
@ -965,7 +965,7 @@ mod tests {
.uri("/t%65st/tests/test.binary") .uri("/t%65st/tests/test.binary")
// .no_default_headers() // .no_default_headers()
.to_request(); .to_request();
let _response = test::call_service(&mut srv, request).await; let _response = test::call_service(&srv, request).await;
// let contentlength = response // let contentlength = response
// .headers() // .headers()
@ -977,7 +977,7 @@ mod tests {
// chunked // chunked
let request = TestRequest::get().uri("/t%65st/tests/test.binary").to_request(); 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 // with enabled compression
// { // {
@ -997,7 +997,7 @@ mod tests {
#[ntex::test] #[ntex::test]
async fn test_head_content_length_headers() { 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")), App::new().service(Files::new("test", ".").index_file("tests/test.binary")),
) )
.await; .await;
@ -1007,7 +1007,7 @@ mod tests {
.method(Method::HEAD) .method(Method::HEAD)
.uri("/t%65st/tests/test.binary") .uri("/t%65st/tests/test.binary")
.to_request(); .to_request();
let _response = test::call_service(&mut srv, request).await; let _response = test::call_service(&srv, request).await;
// TODO: fix check // TODO: fix check
// let contentlength = response // let contentlength = response
@ -1036,35 +1036,35 @@ mod tests {
#[ntex::test] #[ntex::test]
async fn test_files_not_allowed() { 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 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); 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 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); assert_eq!(resp.status(), StatusCode::METHOD_NOT_ALLOWED);
} }
#[ntex::test] #[ntex::test]
async fn test_files_guards() { 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())), App::new().service(Files::new("/", ".").use_guards(guard::Post())),
) )
.await; .await;
let req = TestRequest::default().uri("/Cargo.toml").method(Method::POST).to_request(); 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); assert_eq!(resp.status(), StatusCode::OK);
} }
#[ntex::test] #[ntex::test]
async fn test_named_file_content_encoding() { 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 { web::resource("/").to(|| async {
NamedFile::open("Cargo.toml") NamedFile::open("Cargo.toml")
.unwrap() .unwrap()
@ -1077,14 +1077,14 @@ mod tests {
.uri("/") .uri("/")
.header(http::header::ACCEPT_ENCODING, "gzip") .header(http::header::ACCEPT_ENCODING, "gzip")
.to_request(); .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.status(), StatusCode::OK);
assert!(!res.headers().contains_key(http::header::CONTENT_ENCODING)); assert!(!res.headers().contains_key(http::header::CONTENT_ENCODING));
} }
#[ntex::test] #[ntex::test]
async fn test_named_file_content_encoding_gzip() { 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 { web::resource("/").to(|| async {
NamedFile::open("Cargo.toml") NamedFile::open("Cargo.toml")
.unwrap() .unwrap()
@ -1097,7 +1097,7 @@ mod tests {
.uri("/") .uri("/")
.header(http::header::ACCEPT_ENCODING, "gzip") .header(http::header::ACCEPT_ENCODING, "gzip")
.to_request(); .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.status(), StatusCode::OK);
assert_eq!( assert_eq!(
res.headers().get(http::header::CONTENT_ENCODING).unwrap().to_str().unwrap(), res.headers().get(http::header::CONTENT_ENCODING).unwrap().to_str().unwrap(),
@ -1115,25 +1115,25 @@ mod tests {
#[ntex::test] #[ntex::test]
async fn test_static_files() { async fn test_static_files() {
let mut srv = let srv =
test::init_service(App::new().service(Files::new("/", ".").show_files_listing())) test::init_service(App::new().service(Files::new("/", ".").show_files_listing()))
.await; .await;
let req = TestRequest::with_uri("/missing").to_request(); 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); 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 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); assert_eq!(resp.status(), StatusCode::NOT_FOUND);
let mut srv = let srv =
test::init_service(App::new().service(Files::new("/", ".").show_files_listing())) test::init_service(App::new().service(Files::new("/", ".").show_files_listing()))
.await; .await;
let req = TestRequest::with_uri("/tests").to_request(); 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!( assert_eq!(
resp.headers().get(http::header::CONTENT_TYPE).unwrap(), resp.headers().get(http::header::CONTENT_TYPE).unwrap(),
"text/html; charset=utf-8" "text/html; charset=utf-8"
@ -1146,26 +1146,26 @@ mod tests {
#[ntex::test] #[ntex::test]
async fn test_redirect_to_slash_directory() { async fn test_redirect_to_slash_directory() {
// should not redirect if no index // 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()), App::new().service(Files::new("/", ".").redirect_to_slash_directory()),
) )
.await; .await;
let req = TestRequest::with_uri("/tests").to_request(); 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); assert_eq!(resp.status(), StatusCode::NOT_FOUND);
// should redirect if index present // 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(), Files::new("/", ".").index_file("test.png").redirect_to_slash_directory(),
)) ))
.await; .await;
let req = TestRequest::with_uri("/tests").to_request(); 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); assert_eq!(resp.status(), StatusCode::FOUND);
// should not redirect if the path is wrong // should not redirect if the path is wrong
let req = TestRequest::with_uri("/not_existing").to_request(); 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); assert_eq!(resp.status(), StatusCode::NOT_FOUND);
} }
@ -1257,7 +1257,7 @@ mod tests {
// #[ntex::test] // #[ntex::test]
// fn integration_serve_index() { // fn integration_serve_index() {
// let mut srv = test::TestServer::with_factory(|| { // let srv = test::TestServer::with_factory(|| {
// App::new().handler( // App::new().handler(
// "test", // "test",
// Files::new(".").index_file("Cargo.toml"), // Files::new(".").index_file("Cargo.toml"),
@ -1290,7 +1290,7 @@ mod tests {
// #[ntex::test] // #[ntex::test]
// fn integration_percent_encoded() { // fn integration_percent_encoded() {
// let mut srv = test::TestServer::with_factory(|| { // let srv = test::TestServer::with_factory(|| {
// App::new().handler( // App::new().handler(
// "test", // "test",
// Files::new(".").index_file("Cargo.toml"), // Files::new(".").index_file("Cargo.toml"),

View file

@ -21,7 +21,7 @@ default = ["cookie-policy"]
cookie-policy = ["cookie/secure", "ntex/cookie"] cookie-policy = ["cookie/secure", "ntex/cookie"]
[dependencies] [dependencies]
ntex = "0.6.0-beta.0" ntex = "0.6.5"
futures = "0.3" futures = "0.3"
serde = "1.0" serde = "1.0"
serde_json = "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"] } time = { version = "0.3", default-features = false, features = ["std"] }
[dev-dependencies] [dev-dependencies]
ntex = { version = "0.6.0-beta.0", features=["tokio"] } ntex = { version = "0.6.5", features=["tokio"] }

View file

@ -366,10 +366,10 @@ impl CookieIdentityInner {
let mut jar = CookieJar::new(); let mut jar = CookieJar::new();
let key = if self.legacy_supported() { &self.key } else { &self.key_v2 }; let key = if self.legacy_supported() { &self.key } else { &self.key_v2 };
if add_cookie { if add_cookie {
jar.private_mut(&key).add(cookie); jar.private_mut(key).add(cookie);
} else { } else {
jar.add_original(cookie.clone()); jar.add_original(cookie.clone());
jar.private_mut(&key).remove(cookie); jar.private_mut(key).remove(cookie);
} }
for cookie in jar.delta() { for cookie in jar.delta() {
let val = HeaderValue::from_str(&cookie.to_string()).map_err(HttpError::from)?; 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}; use ntex::{http::StatusCode, service::into_service, time};
const COOKIE_KEY_MASTER: [u8; 32] = [0; 32]; const COOKIE_KEY_MASTER: [u8; 32] = [0; 32];
const COOKIE_NAME: &'static str = "ntex_auth"; const COOKIE_NAME: &str = "ntex_auth";
const COOKIE_LOGIN: &'static str = "test"; const COOKIE_LOGIN: &str = "test";
#[ntex::test] #[ntex::test]
async fn test_identity() { async fn test_identity() {
let mut srv = test::init_service( let srv = test::init_service(
App::new() App::new()
.wrap(IdentityService::new( .wrap(IdentityService::new(
CookieIdentityPolicy::new(&COOKIE_KEY_MASTER) CookieIdentityPolicy::new(&COOKIE_KEY_MASTER)
@ -623,24 +623,22 @@ mod tests {
})), })),
) )
.await; .await;
let resp = let resp = test::call_service(&srv, TestRequest::with_uri("/index").to_request()).await;
test::call_service(&mut srv, TestRequest::with_uri("/index").to_request()).await;
assert_eq!(resp.status(), StatusCode::OK); assert_eq!(resp.status(), StatusCode::OK);
let resp = let resp = test::call_service(&srv, TestRequest::with_uri("/login").to_request()).await;
test::call_service(&mut srv, TestRequest::with_uri("/login").to_request()).await;
assert_eq!(resp.status(), StatusCode::OK); assert_eq!(resp.status(), StatusCode::OK);
let c = resp.response().cookies().next().unwrap().to_owned(); let c = resp.response().cookies().next().unwrap().to_owned();
let resp = test::call_service( let resp = test::call_service(
&mut srv, &srv,
TestRequest::with_uri("/index").cookie(c.clone()).to_request(), TestRequest::with_uri("/index").cookie(c.clone()).to_request(),
) )
.await; .await;
assert_eq!(resp.status(), StatusCode::CREATED); assert_eq!(resp.status(), StatusCode::CREATED);
let resp = test::call_service( let resp = test::call_service(
&mut srv, &srv,
TestRequest::with_uri("/logout").cookie(c.clone()).to_request(), TestRequest::with_uri("/logout").cookie(c.clone()).to_request(),
) )
.await; .await;
@ -651,7 +649,7 @@ mod tests {
#[ntex::test] #[ntex::test]
async fn test_identity_max_age_time() { async fn test_identity_max_age_time() {
let duration = Duration::days(1); let duration = Duration::days(1);
let mut srv = test::init_service( let srv = test::init_service(
App::new() App::new()
.wrap(IdentityService::new( .wrap(IdentityService::new(
CookieIdentityPolicy::new(&COOKIE_KEY_MASTER) CookieIdentityPolicy::new(&COOKIE_KEY_MASTER)
@ -667,8 +665,7 @@ mod tests {
})), })),
) )
.await; .await;
let resp = let resp = test::call_service(&srv, TestRequest::with_uri("/login").to_request()).await;
test::call_service(&mut srv, TestRequest::with_uri("/login").to_request()).await;
assert_eq!(resp.status(), StatusCode::OK); assert_eq!(resp.status(), StatusCode::OK);
assert!(resp.headers().contains_key(header::SET_COOKIE)); assert!(resp.headers().contains_key(header::SET_COOKIE));
let c = resp.response().cookies().next().unwrap().to_owned(); let c = resp.response().cookies().next().unwrap().to_owned();
@ -678,7 +675,7 @@ mod tests {
#[ntex::test] #[ntex::test]
async fn test_identity_max_age() { async fn test_identity_max_age() {
let seconds = 60; let seconds = 60;
let mut srv = test::init_service( let srv = test::init_service(
App::new() App::new()
.wrap(IdentityService::new( .wrap(IdentityService::new(
CookieIdentityPolicy::new(&COOKIE_KEY_MASTER) CookieIdentityPolicy::new(&COOKIE_KEY_MASTER)
@ -694,12 +691,11 @@ mod tests {
})), })),
) )
.await; .await;
let resp = let resp = test::call_service(&srv, TestRequest::with_uri("/login").to_request()).await;
test::call_service(&mut srv, TestRequest::with_uri("/login").to_request()).await;
assert_eq!(resp.status(), StatusCode::OK); assert_eq!(resp.status(), StatusCode::OK);
assert!(resp.headers().contains_key(header::SET_COOKIE)); assert!(resp.headers().contains_key(header::SET_COOKIE));
let c = resp.response().cookies().next().unwrap().to_owned(); 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< async fn create_identity_server<
@ -738,7 +734,7 @@ mod tests {
) -> Cookie<'static> { ) -> Cookie<'static> {
let mut jar = CookieJar::new(); let mut jar = CookieJar::new();
let key: Vec<u8> = let key: Vec<u8> =
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( jar.private_mut(&Key::derive_from(&key)).add(Cookie::new(
COOKIE_NAME, COOKIE_NAME,
serde_json::to_string(&CookieValue { serde_json::to_string(&CookieValue {
@ -768,9 +764,9 @@ mod tests {
} }
enum LoginTimestampCheck { enum LoginTimestampCheck {
NoTimestamp, Incorrect,
NewTimestamp, New,
OldTimestamp(SystemTime), Old(SystemTime),
} }
enum VisitTimeStampCheck { enum VisitTimeStampCheck {
@ -789,18 +785,18 @@ mod tests {
cookies.add(Cookie::parse(cookie.to_str().unwrap().to_string()).unwrap()); cookies.add(Cookie::parse(cookie.to_str().unwrap().to_string()).unwrap());
} }
let key: Vec<u8> = let key: Vec<u8> =
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 cookie = cookies.private(&Key::derive_from(&key)).get(COOKIE_NAME).unwrap();
let cv: CookieValue = serde_json::from_str(cookie.value()).unwrap(); let cv: CookieValue = serde_json::from_str(cookie.value()).unwrap();
assert_eq!(cv.identity, identity); assert_eq!(cv.identity, identity);
let now = SystemTime::now(); let now = SystemTime::now();
let t30sec_ago = now - Duration::seconds(30); let t30sec_ago = now - Duration::seconds(30);
match login_timestamp { match login_timestamp {
LoginTimestampCheck::NoTimestamp => assert_eq!(cv.login_timestamp, None), LoginTimestampCheck::Incorrect => assert_eq!(cv.login_timestamp, None),
LoginTimestampCheck::NewTimestamp => assert!( LoginTimestampCheck::New => assert!(
t30sec_ago <= cv.login_timestamp.unwrap() && cv.login_timestamp.unwrap() <= now 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)) assert_eq!(cv.login_timestamp, Some(old_timestamp))
} }
} }
@ -822,19 +818,18 @@ mod tests {
#[ntex::test] #[ntex::test]
async fn test_identity_legacy_cookie_is_set() { async fn test_identity_legacy_cookie_is_set() {
let mut srv = create_identity_server(|c| c).await; let srv = create_identity_server(|c| c).await;
let mut resp = let mut resp = test::call_service(&srv, TestRequest::with_uri("/").to_request()).await;
test::call_service(&mut srv, TestRequest::with_uri("/").to_request()).await;
assert_legacy_login_cookie(&mut resp, COOKIE_LOGIN); assert_legacy_login_cookie(&mut resp, COOKIE_LOGIN);
assert_logged_in(resp, None).await; assert_logged_in(resp, None).await;
} }
#[ntex::test] #[ntex::test]
async fn test_identity_legacy_cookie_works() { 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 cookie = legacy_login_cookie(COOKIE_LOGIN);
let mut resp = test::call_service( let mut resp = test::call_service(
&mut srv, &srv,
TestRequest::with_uri("/").cookie(cookie.clone()).to_request(), TestRequest::with_uri("/").cookie(cookie.clone()).to_request(),
) )
.await; .await;
@ -844,17 +839,17 @@ mod tests {
#[ntex::test] #[ntex::test]
async fn test_identity_legacy_cookie_rejected_if_visit_timestamp_needed() { 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 cookie = legacy_login_cookie(COOKIE_LOGIN);
let mut resp = test::call_service( let mut resp = test::call_service(
&mut srv, &srv,
TestRequest::with_uri("/").cookie(cookie.clone()).to_request(), TestRequest::with_uri("/").cookie(cookie.clone()).to_request(),
) )
.await; .await;
assert_login_cookie( assert_login_cookie(
&mut resp, &mut resp,
COOKIE_LOGIN, COOKIE_LOGIN,
LoginTimestampCheck::NoTimestamp, LoginTimestampCheck::Incorrect,
VisitTimeStampCheck::NewTimestamp, VisitTimeStampCheck::NewTimestamp,
); );
assert_logged_in(resp, None).await; assert_logged_in(resp, None).await;
@ -862,17 +857,17 @@ mod tests {
#[ntex::test] #[ntex::test]
async fn test_identity_legacy_cookie_rejected_if_login_timestamp_needed() { 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 cookie = legacy_login_cookie(COOKIE_LOGIN);
let mut resp = test::call_service( let mut resp = test::call_service(
&mut srv, &srv,
TestRequest::with_uri("/").cookie(cookie.clone()).to_request(), TestRequest::with_uri("/").cookie(cookie.clone()).to_request(),
) )
.await; .await;
assert_login_cookie( assert_login_cookie(
&mut resp, &mut resp,
COOKIE_LOGIN, COOKIE_LOGIN,
LoginTimestampCheck::NewTimestamp, LoginTimestampCheck::New,
VisitTimeStampCheck::NoTimestamp, VisitTimeStampCheck::NoTimestamp,
); );
assert_logged_in(resp, None).await; assert_logged_in(resp, None).await;
@ -880,17 +875,17 @@ mod tests {
#[ntex::test] #[ntex::test]
async fn test_identity_cookie_rejected_if_login_timestamp_needed() { 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 cookie = login_cookie(COOKIE_LOGIN, None, Some(SystemTime::now()));
let mut resp = test::call_service( let mut resp = test::call_service(
&mut srv, &srv,
TestRequest::with_uri("/").cookie(cookie.clone()).to_request(), TestRequest::with_uri("/").cookie(cookie.clone()).to_request(),
) )
.await; .await;
assert_login_cookie( assert_login_cookie(
&mut resp, &mut resp,
COOKIE_LOGIN, COOKIE_LOGIN,
LoginTimestampCheck::NewTimestamp, LoginTimestampCheck::New,
VisitTimeStampCheck::NoTimestamp, VisitTimeStampCheck::NoTimestamp,
); );
assert_logged_in(resp, None).await; assert_logged_in(resp, None).await;
@ -898,17 +893,17 @@ mod tests {
#[ntex::test] #[ntex::test]
async fn test_identity_cookie_rejected_if_visit_timestamp_needed() { 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 cookie = login_cookie(COOKIE_LOGIN, Some(SystemTime::now()), None);
let mut resp = test::call_service( let mut resp = test::call_service(
&mut srv, &srv,
TestRequest::with_uri("/").cookie(cookie.clone()).to_request(), TestRequest::with_uri("/").cookie(cookie.clone()).to_request(),
) )
.await; .await;
assert_login_cookie( assert_login_cookie(
&mut resp, &mut resp,
COOKIE_LOGIN, COOKIE_LOGIN,
LoginTimestampCheck::NoTimestamp, LoginTimestampCheck::Incorrect,
VisitTimeStampCheck::NewTimestamp, VisitTimeStampCheck::NewTimestamp,
); );
assert_logged_in(resp, None).await; assert_logged_in(resp, None).await;
@ -916,18 +911,18 @@ mod tests {
#[ntex::test] #[ntex::test]
async fn test_identity_cookie_rejected_if_login_timestamp_too_old() { 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 = let cookie =
login_cookie(COOKIE_LOGIN, Some(SystemTime::now() - Duration::days(180)), None); login_cookie(COOKIE_LOGIN, Some(SystemTime::now() - Duration::days(180)), None);
let mut resp = test::call_service( let mut resp = test::call_service(
&mut srv, &srv,
TestRequest::with_uri("/").cookie(cookie.clone()).to_request(), TestRequest::with_uri("/").cookie(cookie.clone()).to_request(),
) )
.await; .await;
assert_login_cookie( assert_login_cookie(
&mut resp, &mut resp,
COOKIE_LOGIN, COOKIE_LOGIN,
LoginTimestampCheck::NewTimestamp, LoginTimestampCheck::New,
VisitTimeStampCheck::NoTimestamp, VisitTimeStampCheck::NoTimestamp,
); );
assert_logged_in(resp, None).await; assert_logged_in(resp, None).await;
@ -935,18 +930,18 @@ mod tests {
#[ntex::test] #[ntex::test]
async fn test_identity_cookie_rejected_if_visit_timestamp_too_old() { 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 = let cookie =
login_cookie(COOKIE_LOGIN, None, Some(SystemTime::now() - Duration::days(180))); login_cookie(COOKIE_LOGIN, None, Some(SystemTime::now() - Duration::days(180)));
let mut resp = test::call_service( let mut resp = test::call_service(
&mut srv, &srv,
TestRequest::with_uri("/").cookie(cookie.clone()).to_request(), TestRequest::with_uri("/").cookie(cookie.clone()).to_request(),
) )
.await; .await;
assert_login_cookie( assert_login_cookie(
&mut resp, &mut resp,
COOKIE_LOGIN, COOKIE_LOGIN,
LoginTimestampCheck::NoTimestamp, LoginTimestampCheck::Incorrect,
VisitTimeStampCheck::NewTimestamp, VisitTimeStampCheck::NewTimestamp,
); );
assert_logged_in(resp, None).await; assert_logged_in(resp, None).await;
@ -954,10 +949,10 @@ mod tests {
#[ntex::test] #[ntex::test]
async fn test_identity_cookie_not_updated_on_login_deadline() { 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 cookie = login_cookie(COOKIE_LOGIN, Some(SystemTime::now()), None);
let mut resp = test::call_service( let mut resp = test::call_service(
&mut srv, &srv,
TestRequest::with_uri("/").cookie(cookie.clone()).to_request(), TestRequest::with_uri("/").cookie(cookie.clone()).to_request(),
) )
.await; .await;
@ -968,21 +963,21 @@ mod tests {
// https://github.com/actix/actix-web/issues/1263 // https://github.com/actix/actix-web/issues/1263
#[ntex::test] #[ntex::test]
async fn test_identity_cookie_updated_on_visit_deadline() { 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)) c.visit_deadline(Duration::days(90)).login_deadline(Duration::days(90))
}) })
.await; .await;
let timestamp = SystemTime::now() - Duration::days(1); let timestamp = SystemTime::now() - Duration::days(1);
let cookie = login_cookie(COOKIE_LOGIN, Some(timestamp), Some(timestamp)); let cookie = login_cookie(COOKIE_LOGIN, Some(timestamp), Some(timestamp));
let mut resp = test::call_service( let mut resp = test::call_service(
&mut srv, &srv,
TestRequest::with_uri("/").cookie(cookie.clone()).to_request(), TestRequest::with_uri("/").cookie(cookie.clone()).to_request(),
) )
.await; .await;
assert_login_cookie( assert_login_cookie(
&mut resp, &mut resp,
COOKIE_LOGIN, COOKIE_LOGIN,
LoginTimestampCheck::OldTimestamp(timestamp), LoginTimestampCheck::Old(timestamp),
VisitTimeStampCheck::NewTimestamp, VisitTimeStampCheck::NewTimestamp,
); );
assert_logged_in(resp, Some(COOKIE_LOGIN)).await; assert_logged_in(resp, Some(COOKIE_LOGIN)).await;

View file

@ -16,7 +16,7 @@ name = "ntex_multipart"
path = "src/lib.rs" path = "src/lib.rs"
[dependencies] [dependencies]
ntex = "0.6.0-beta.0" ntex = "0.6.5"
derive_more = "0.99" derive_more = "0.99"
httparse = "1.3" httparse = "1.3"
futures = "0.3" futures = "0.3"
@ -25,4 +25,4 @@ mime = "0.3"
twoway = "0.2" twoway = "0.2"
[dev-dependencies] [dev-dependencies]
ntex = { version = "0.6.0-beta.0", features=["tokio"] } ntex = { version = "0.6.5", features=["tokio"] }

View file

@ -261,10 +261,8 @@ impl InnerMultipart {
match self.state { match self.state {
// read until first boundary // read until first boundary
InnerState::FirstBoundary => { InnerState::FirstBoundary => {
match InnerMultipart::skip_until_boundary( match InnerMultipart::skip_until_boundary(&mut payload, &self.boundary)?
&mut *payload, {
&self.boundary,
)? {
Some(eof) => { Some(eof) => {
if eof { if eof {
self.state = InnerState::Eof; self.state = InnerState::Eof;
@ -278,7 +276,7 @@ impl InnerMultipart {
} }
// read boundary // read boundary
InnerState::Boundary => { InnerState::Boundary => {
match InnerMultipart::read_boundary(&mut *payload, &self.boundary)? { match InnerMultipart::read_boundary(&mut payload, &self.boundary)? {
None => return Poll::Pending, None => return Poll::Pending,
Some(eof) => { Some(eof) => {
if eof { if eof {
@ -295,7 +293,7 @@ impl InnerMultipart {
// read field headers for next field // read field headers for next field
if self.state == InnerState::Headers { 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; self.state = InnerState::Boundary;
headers headers
} else { } else {
@ -547,9 +545,9 @@ impl InnerField {
let result = if let Some(mut payload) = self.payload.as_ref().unwrap().get_mut(s) { let result = if let Some(mut payload) = self.payload.as_ref().unwrap().get_mut(s) {
if !self.eof { if !self.eof {
let res = if let Some(ref mut len) = self.length { let res = if let Some(ref mut len) = self.length {
InnerField::read_len(&mut *payload, len) InnerField::read_len(&mut payload, len)
} else { } else {
InnerField::read_stream(&mut *payload, &self.boundary) InnerField::read_stream(&mut payload, &self.boundary)
}; };
match res { match res {
@ -810,7 +808,7 @@ mod tests {
impl SlowStream { impl SlowStream {
fn new(bytes: Bytes) -> SlowStream { fn new(bytes: Bytes) -> SlowStream {
return SlowStream { bytes, pos: 0, ready: false }; SlowStream { bytes, pos: 0, ready: false }
} }
} }

View file

@ -22,7 +22,7 @@ default = ["cookie-session"]
cookie-session = ["cookie/secure", "ntex/cookie"] cookie-session = ["cookie/secure", "ntex/cookie"]
[dependencies] [dependencies]
ntex = "0.6.0-beta.0" ntex = "0.6.5"
cookie = "0.17" cookie = "0.17"
derive_more = "0.99" derive_more = "0.99"
futures = "0.3" futures = "0.3"
@ -31,4 +31,4 @@ serde_json = "1.0"
time = { version = "0.3", default-features = false, features = ["std"] } time = { version = "0.3", default-features = false, features = ["std"] }
[dev-dependencies] [dev-dependencies]
ntex = { version = "0.6.0-beta.0", features=["tokio"] } ntex = { version = "0.6.5", features=["tokio"] }

View file

@ -378,7 +378,7 @@ mod tests {
let request = test::TestRequest::get().to_request(); let request = test::TestRequest::get().to_request();
let response = app.call(request).await.unwrap(); 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] #[ntex::test]
@ -395,7 +395,7 @@ mod tests {
let request = test::TestRequest::get().to_request(); let request = test::TestRequest::get().to_request();
let response = app.call(request).await.unwrap(); 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] #[ntex::test]
@ -412,7 +412,7 @@ mod tests {
let request = test::TestRequest::get().to_request(); let request = test::TestRequest::get().to_request();
let response = app.call(request).await.unwrap(); 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] #[ntex::test]

View file

@ -89,19 +89,19 @@ pub trait UserSession {
impl UserSession for HttpRequest { impl UserSession for HttpRequest {
fn get_session(&self) -> Session { fn get_session(&self) -> Session {
Session::get_session(&mut *self.extensions_mut()) Session::get_session(&mut self.extensions_mut())
} }
} }
impl<Err> UserSession for WebRequest<Err> { impl<Err> UserSession for WebRequest<Err> {
fn get_session(&self) -> Session { fn get_session(&self) -> Session {
Session::get_session(&mut *self.extensions_mut()) Session::get_session(&mut self.extensions_mut())
} }
} }
impl UserSession for RequestHead { impl UserSession for RequestHead {
fn get_session(&self) -> Session { 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, Renewed,
Unchanged, Unchanged,
} }
/// #[default] macro can be used but will depend on specific rust version
impl Default for SessionStatus { impl Default for SessionStatus {
fn default() -> SessionStatus { fn default() -> SessionStatus {
SessionStatus::Unchanged SessionStatus::Unchanged
@ -181,7 +183,7 @@ impl Session {
data: impl Iterator<Item = (String, String)>, data: impl Iterator<Item = (String, String)>,
req: &WebRequest<Err>, req: &WebRequest<Err>,
) { ) {
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(); let mut inner = session.0.borrow_mut();
inner.state.extend(data); inner.state.extend(data);
} }
@ -190,7 +192,7 @@ impl Session {
res: &mut WebResponse, res: &mut WebResponse,
) -> (SessionStatus, Option<impl Iterator<Item = (String, String)>>) { ) -> (SessionStatus, Option<impl Iterator<Item = (String, String)>>) {
if let Some(s_impl) = res.request().extensions().get::<Rc<RefCell<SessionInner>>>() { if let Some(s_impl) = res.request().extensions().get::<Rc<RefCell<SessionInner>>>() {
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())) (s_impl.borrow().status.clone(), Some(state.into_iter()))
} else { } else {
(SessionStatus::Unchanged, None) (SessionStatus::Unchanged, None)
@ -199,7 +201,7 @@ impl Session {
fn get_session(extensions: &mut Extensions) -> Session { fn get_session(extensions: &mut Extensions) -> Session {
if let Some(s_impl) = extensions.get::<Rc<RefCell<SessionInner>>>() { if let Some(s_impl) = extensions.get::<Rc<RefCell<SessionInner>>>() {
return Session(Rc::clone(&s_impl)); return Session(Rc::clone(s_impl));
} }
let inner = Rc::new(RefCell::new(SessionInner::default())); let inner = Rc::new(RefCell::new(SessionInner::default()));
extensions.insert(inner.clone()); extensions.insert(inner.clone());
@ -230,7 +232,7 @@ impl<Err> FromRequest<Err> for Session {
#[inline] #[inline]
fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future { 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] #[test]
fn session() { fn session() {
let mut req = test::TestRequest::default().to_srv_request(); let req = test::TestRequest::default().to_srv_request();
Session::set_session( Session::set_session(
vec![("key".to_string(), "\"value\"".to_string())].into_iter(), 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::<String>("key").unwrap(); let res = session.get::<String>("key").unwrap();
assert_eq!(res, Some("value".to_string())); assert_eq!(res, Some("value".to_string()));
@ -263,11 +265,11 @@ mod tests {
#[test] #[test]
fn get_session() { fn get_session() {
let mut req = test::TestRequest::default().to_srv_request(); let req = test::TestRequest::default().to_srv_request();
Session::set_session( Session::set_session(
vec![("key".to_string(), "\"value\"".to_string())].into_iter(), vec![("key".to_string(), "\"value\"".to_string())].into_iter(),
&mut req, &req,
); );
let session = req.get_session(); let session = req.get_session();
@ -281,7 +283,7 @@ mod tests {
Session::set_session( Session::set_session(
vec![("key".to_string(), "\"value\"".to_string())].into_iter(), vec![("key".to_string(), "\"value\"".to_string())].into_iter(),
&mut req, &req,
); );
let session = req.head_mut().get_session(); let session = req.head_mut().get_session();
@ -292,7 +294,7 @@ mod tests {
#[test] #[test]
fn purge_session() { fn purge_session() {
let req = test::TestRequest::default().to_srv_request(); 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); assert_eq!(session.0.borrow().status, SessionStatus::Unchanged);
session.purge(); session.purge();
assert_eq!(session.0.borrow().status, SessionStatus::Purged); assert_eq!(session.0.borrow().status, SessionStatus::Purged);
@ -301,7 +303,7 @@ mod tests {
#[test] #[test]
fn renew_session() { fn renew_session() {
let req = test::TestRequest::default().to_srv_request(); 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); assert_eq!(session.0.borrow().status, SessionStatus::Unchanged);
session.renew(); session.renew();
assert_eq!(session.0.borrow().status, SessionStatus::Renewed); assert_eq!(session.0.borrow().status, SessionStatus::Renewed);