mirror of https://github.com/fafhrd91/actix-web
Merge branch 'master' into docs-fix
This commit is contained in:
commit
c0b780613f
|
@ -1,5 +1,11 @@
|
||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
|
## [2.0.NEXT] - 2020-01-xx
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
* Use `sha-1` crate instead of unmaintained `sha1` crate
|
||||||
|
|
||||||
## [2.0.0] - 2019-12-25
|
## [2.0.0] - 2019-12-25
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
|
@ -60,9 +60,9 @@ rustls = ["actix-tls/rustls", "awc/rustls", "rust-tls"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-codec = "0.2.0"
|
actix-codec = "0.2.0"
|
||||||
actix-service = "1.0.1"
|
actix-service = "1.0.2"
|
||||||
actix-utils = "1.0.4"
|
actix-utils = "1.0.6"
|
||||||
actix-router = "0.2.1"
|
actix-router = "0.2.4"
|
||||||
actix-rt = "1.0.0"
|
actix-rt = "1.0.0"
|
||||||
actix-server = "1.0.0"
|
actix-server = "1.0.0"
|
||||||
actix-testing = "1.0.0"
|
actix-testing = "1.0.0"
|
||||||
|
|
|
@ -74,7 +74,7 @@ rand = "0.7"
|
||||||
regex = "1.3"
|
regex = "1.3"
|
||||||
serde = "1.0"
|
serde = "1.0"
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
sha1 = "0.6"
|
sha-1 = "0.8"
|
||||||
slab = "0.4"
|
slab = "0.4"
|
||||||
serde_urlencoded = "0.6.1"
|
serde_urlencoded = "0.6.1"
|
||||||
time = "0.1.42"
|
time = "0.1.42"
|
||||||
|
|
|
@ -6,27 +6,21 @@ use actix_service::Service;
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
/// Service that allows to turn non-clone service to a service with `Clone` impl
|
/// Service that allows to turn non-clone service to a service with `Clone` impl
|
||||||
pub(crate) struct CloneableService<T>(Rc<UnsafeCell<T>>);
|
pub(crate) struct CloneableService<T: Service>(Rc<UnsafeCell<T>>);
|
||||||
|
|
||||||
impl<T> CloneableService<T> {
|
impl<T: Service> CloneableService<T> {
|
||||||
pub(crate) fn new(service: T) -> Self
|
pub(crate) fn new(service: T) -> Self {
|
||||||
where
|
|
||||||
T: Service,
|
|
||||||
{
|
|
||||||
Self(Rc::new(UnsafeCell::new(service)))
|
Self(Rc::new(UnsafeCell::new(service)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Clone for CloneableService<T> {
|
impl<T: Service> Clone for CloneableService<T> {
|
||||||
fn clone(&self) -> Self {
|
fn clone(&self) -> Self {
|
||||||
Self(self.0.clone())
|
Self(self.0.clone())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Service for CloneableService<T>
|
impl<T: Service> Service for CloneableService<T> {
|
||||||
where
|
|
||||||
T: Service,
|
|
||||||
{
|
|
||||||
type Request = T::Request;
|
type Request = T::Request;
|
||||||
type Response = T::Response;
|
type Response = T::Response;
|
||||||
type Error = T::Error;
|
type Error = T::Error;
|
||||||
|
|
|
@ -364,7 +364,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
/// `Service` implementation for HTTP1 transport
|
/// `Service` implementation for HTTP1 transport
|
||||||
pub struct H1ServiceHandler<T, S, B, X, U> {
|
pub struct H1ServiceHandler<T, S: Service, B, X: Service, U: Service> {
|
||||||
srv: CloneableService<S>,
|
srv: CloneableService<S>,
|
||||||
expect: CloneableService<X>,
|
expect: CloneableService<X>,
|
||||||
upgrade: Option<CloneableService<U>>,
|
upgrade: Option<CloneableService<U>>,
|
||||||
|
|
|
@ -246,7 +246,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
/// `Service` implementation for http/2 transport
|
/// `Service` implementation for http/2 transport
|
||||||
pub struct H2ServiceHandler<T, S, B> {
|
pub struct H2ServiceHandler<T, S: Service, B> {
|
||||||
srv: CloneableService<S>,
|
srv: CloneableService<S>,
|
||||||
cfg: ServiceConfig,
|
cfg: ServiceConfig,
|
||||||
on_connect: Option<rc::Rc<dyn Fn(&T) -> Box<dyn DataFactory>>>,
|
on_connect: Option<rc::Rc<dyn Fn(&T) -> Box<dyn DataFactory>>>,
|
||||||
|
|
|
@ -443,7 +443,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
/// `Service` implementation for http transport
|
/// `Service` implementation for http transport
|
||||||
pub struct HttpServiceHandler<T, S, B, X, U> {
|
pub struct HttpServiceHandler<T, S: Service, B, X: Service, U: Service> {
|
||||||
srv: CloneableService<S>,
|
srv: CloneableService<S>,
|
||||||
expect: CloneableService<X>,
|
expect: CloneableService<X>,
|
||||||
upgrade: Option<CloneableService<U>>,
|
upgrade: Option<CloneableService<U>>,
|
||||||
|
|
|
@ -207,12 +207,13 @@ static WS_GUID: &str = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
|
||||||
|
|
||||||
// TODO: hash is always same size, we dont need String
|
// TODO: hash is always same size, we dont need String
|
||||||
pub fn hash_key(key: &[u8]) -> String {
|
pub fn hash_key(key: &[u8]) -> String {
|
||||||
|
use sha1::Digest;
|
||||||
let mut hasher = sha1::Sha1::new();
|
let mut hasher = sha1::Sha1::new();
|
||||||
|
|
||||||
hasher.update(key);
|
hasher.input(key);
|
||||||
hasher.update(WS_GUID.as_bytes());
|
hasher.input(WS_GUID.as_bytes());
|
||||||
|
|
||||||
base64::encode(&hasher.digest().bytes())
|
base64::encode(hasher.result().as_ref())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -277,6 +278,12 @@ mod test {
|
||||||
assert_eq!(format!("{}", OpCode::Bad), "BAD");
|
assert_eq!(format!("{}", OpCode::Bad), "BAD");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_hash_key() {
|
||||||
|
let hash = hash_key(b"hello actix-web");
|
||||||
|
assert_eq!(&hash, "cR1dlyUUJKp0s/Bel25u5TgvC3E=");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn closecode_from_u16() {
|
fn closecode_from_u16() {
|
||||||
assert_eq!(CloseCode::from(1000u16), CloseCode::Normal);
|
assert_eq!(CloseCode::from(1000u16), CloseCode::Normal);
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
|
## [0.2.1] - 2020-01-10
|
||||||
|
|
||||||
|
* Fix panic with already borrowed: BorrowMutError #1263
|
||||||
|
|
||||||
## [0.2.0] - 2019-12-20
|
## [0.2.0] - 2019-12-20
|
||||||
|
|
||||||
* Use actix-web 2.0
|
* Use actix-web 2.0
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "actix-identity"
|
name = "actix-identity"
|
||||||
version = "0.2.0"
|
version = "0.2.1"
|
||||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
||||||
description = "Identity service for actix web framework."
|
description = "Identity service for actix web framework."
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
|
@ -10,15 +10,14 @@ repository = "https://github.com/actix/actix-web.git"
|
||||||
documentation = "https://docs.rs/actix-identity/"
|
documentation = "https://docs.rs/actix-identity/"
|
||||||
license = "MIT/Apache-2.0"
|
license = "MIT/Apache-2.0"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
workspace = ".."
|
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
name = "actix_identity"
|
name = "actix_identity"
|
||||||
path = "src/lib.rs"
|
path = "src/lib.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-web = { version = "2.0.0-rc", default-features = false, features = ["secure-cookies"] }
|
actix-web = { version = "2.0.0", default-features = false, features = ["secure-cookies"] }
|
||||||
actix-service = "1.0.1"
|
actix-service = "1.0.2"
|
||||||
futures = "0.3.1"
|
futures = "0.3.1"
|
||||||
serde = "1.0"
|
serde = "1.0"
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
|
|
|
@ -251,6 +251,15 @@ pub struct IdentityServiceMiddleware<S, T> {
|
||||||
service: Rc<RefCell<S>>,
|
service: Rc<RefCell<S>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<S, T> Clone for IdentityServiceMiddleware<S, T> {
|
||||||
|
fn clone(&self) -> Self {
|
||||||
|
Self {
|
||||||
|
backend: self.backend.clone(),
|
||||||
|
service: self.service.clone(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<S, T, B> Service for IdentityServiceMiddleware<S, T>
|
impl<S, T, B> Service for IdentityServiceMiddleware<S, T>
|
||||||
where
|
where
|
||||||
B: 'static,
|
B: 'static,
|
||||||
|
@ -279,7 +288,9 @@ where
|
||||||
req.extensions_mut()
|
req.extensions_mut()
|
||||||
.insert(IdentityItem { id, changed: false });
|
.insert(IdentityItem { id, changed: false });
|
||||||
|
|
||||||
let mut res = srv.borrow_mut().call(req).await?;
|
// https://github.com/actix/actix-web/issues/1263
|
||||||
|
let fut = { srv.borrow_mut().call(req) };
|
||||||
|
let mut res = fut.await?;
|
||||||
let id = res.request().extensions_mut().remove::<IdentityItem>();
|
let id = res.request().extensions_mut().remove::<IdentityItem>();
|
||||||
|
|
||||||
if let Some(id) = id {
|
if let Some(id) = id {
|
||||||
|
@ -606,9 +617,10 @@ mod tests {
|
||||||
use std::borrow::Borrow;
|
use std::borrow::Borrow;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use actix_service::into_service;
|
||||||
use actix_web::http::StatusCode;
|
use actix_web::http::StatusCode;
|
||||||
use actix_web::test::{self, TestRequest};
|
use actix_web::test::{self, TestRequest};
|
||||||
use actix_web::{web, App, Error, HttpResponse};
|
use actix_web::{error, web, App, Error, HttpResponse};
|
||||||
|
|
||||||
const COOKIE_KEY_MASTER: [u8; 32] = [0; 32];
|
const COOKIE_KEY_MASTER: [u8; 32] = [0; 32];
|
||||||
const COOKIE_NAME: &'static str = "actix_auth";
|
const COOKIE_NAME: &'static str = "actix_auth";
|
||||||
|
@ -1045,6 +1057,7 @@ mod tests {
|
||||||
assert_logged_in(resp, Some(COOKIE_LOGIN)).await;
|
assert_logged_in(resp, Some(COOKIE_LOGIN)).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://github.com/actix/actix-web/issues/1263
|
||||||
#[actix_rt::test]
|
#[actix_rt::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 mut srv = create_identity_server(|c| {
|
||||||
|
@ -1069,4 +1082,47 @@ mod tests {
|
||||||
);
|
);
|
||||||
assert_logged_in(resp, Some(COOKIE_LOGIN)).await;
|
assert_logged_in(resp, Some(COOKIE_LOGIN)).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[actix_rt::test]
|
||||||
|
async fn test_borrowed_mut_error() {
|
||||||
|
use futures::future::{lazy, ok, Ready};
|
||||||
|
|
||||||
|
struct Ident;
|
||||||
|
impl IdentityPolicy for Ident {
|
||||||
|
type Future = Ready<Result<Option<String>, Error>>;
|
||||||
|
type ResponseFuture = Ready<Result<(), Error>>;
|
||||||
|
|
||||||
|
fn from_request(&self, _: &mut ServiceRequest) -> Self::Future {
|
||||||
|
ok(Some("test".to_string()))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn to_response<B>(
|
||||||
|
&self,
|
||||||
|
_: Option<String>,
|
||||||
|
_: bool,
|
||||||
|
_: &mut ServiceResponse<B>,
|
||||||
|
) -> Self::ResponseFuture {
|
||||||
|
ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut srv = IdentityServiceMiddleware {
|
||||||
|
backend: Rc::new(Ident),
|
||||||
|
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();
|
||||||
|
let req = TestRequest::default().to_srv_request();
|
||||||
|
actix_rt::spawn(async move {
|
||||||
|
let _ = srv2.call(req).await;
|
||||||
|
});
|
||||||
|
actix_rt::time::delay_for(std::time::Duration::from_millis(50)).await;
|
||||||
|
|
||||||
|
let _ = lazy(|cx| srv.poll_ready(cx)).await;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue