1
0
mirror of https://github.com/actix/actix-extras.git synced 2025-08-29 18:59:17 +02:00

chore: fix cspell config

This commit is contained in:
Rob Ede
2025-08-26 08:17:17 +01:00
parent b327ec5c71
commit 21a96a0319
16 changed files with 162 additions and 46727 deletions

View File

@@ -1,3 +1,33 @@
version: 0.2
version: "0.2"
words:
- actix
- addrs
- bytestring
- chrono
- clippy
- codegen
- cooldown
- deadpool
- deque
- docsrs
- doctests
- httpauth
- keygen
- MSRV
- nextest
- nocapture
- peekable
- pipefail
- println
- prost
- rdme
- repr
- reqwest
- RUSTDOCFLAGS
- rustls
- rustup
- serde
- smallvec
- splitn
- subsecs
- tinyvec

4
.gitignore vendored
View File

@@ -13,3 +13,7 @@ guide/build/
.DS_Store
Server.toml
# code coverage
/lcov.info
/codecov.json

View File

@@ -468,7 +468,7 @@ impl Cors {
self
}
/// Configures whether requests should be pre-emptively blocked on mismatched origin.
/// Configures whether requests should be preemptively blocked on mismatched origin.
///
/// If `true`, a 400 Bad Request is returned immediately when a request fails origin validation.
///

View File

@@ -261,7 +261,7 @@ mod tests {
#[actix_web::test]
async fn test_options_no_origin() {
// Tests case where allowed_origins is All but there are validate functions to run incase.
// Tests case where allowed_origins is All but there are validate functions to run in case.
// In this case, origins are only allowed when the DNT header is sent.
let cors = Cors::default()

View File

@@ -2,6 +2,8 @@
## Unreleased
- Fix spelling of `config::LogoutBehavior` type.
- Fix spelling of `config::IdentityMiddlewareBuilder::logout_behavior()` method.
- Update `actix-session` dependency to `0.11`.
- Minimum supported Rust version (MSRV) is now 1.80.

View File

@@ -93,7 +93,7 @@ async fn logout(user: Option<Identity>) -> impl Responder {
## Advanced configuration
By default, `actix-identity` does not automatically log out users. You can change this behaviour by customising the configuration for [`IdentityMiddleware`] via [`IdentityMiddleware::builder`].
By default, `actix-identity` does not automatically log out users. You can change this behavior by customizing the configuration for [`IdentityMiddleware`] via [`IdentityMiddleware::builder`].
In particular, you can automatically log out users who:

View File

@@ -1,4 +1,4 @@
//! Configuration options to tune the behaviour of [`IdentityMiddleware`].
//! Configuration options to tune the behavior of [`IdentityMiddleware`].
use std::time::Duration;
@@ -6,7 +6,7 @@ use crate::IdentityMiddleware;
#[derive(Debug, Clone)]
pub(crate) struct Configuration {
pub(crate) on_logout: LogoutBehaviour,
pub(crate) on_logout: LogoutBehavior,
pub(crate) login_deadline: Option<Duration>,
pub(crate) visit_deadline: Option<Duration>,
pub(crate) id_key: &'static str,
@@ -17,7 +17,7 @@ pub(crate) struct Configuration {
impl Default for Configuration {
fn default() -> Self {
Self {
on_logout: LogoutBehaviour::PurgeSession,
on_logout: LogoutBehavior::PurgeSession,
login_deadline: None,
visit_deadline: None,
id_key: "actix_identity.user_id",
@@ -27,23 +27,22 @@ impl Default for Configuration {
}
}
/// `LogoutBehaviour` controls what actions are going to be performed when [`Identity::logout`] is
/// invoked.
/// Controls what actions are going to be performed when [`Identity::logout`] is invoked.
///
/// [`Identity::logout`]: crate::Identity::logout
#[derive(Debug, Clone)]
#[non_exhaustive]
pub enum LogoutBehaviour {
pub enum LogoutBehavior {
/// When [`Identity::logout`](crate::Identity::logout) is called, purge the current session.
///
/// This behaviour might be desirable when you have stored additional information in the
/// session state that are tied to the user's identity and should not be retained after logout.
/// This behavior might be desirable when you have stored additional information in the session
/// state that are tied to the user's identity and should not be retained after logout.
PurgeSession,
/// When [`Identity::logout`](crate::Identity::logout) is called, remove the identity
/// information from the current session state. The session itself is not destroyed.
///
/// This behaviour might be desirable when you have stored information in the session state that
/// This behavior might be desirable when you have stored information in the session state that
/// is not tied to the user's identity and should be retained after logout.
DeleteIdentityKeys,
}
@@ -84,9 +83,9 @@ impl IdentityMiddlewareBuilder {
/// Determines how [`Identity::logout`](crate::Identity::logout) affects the current session.
///
/// By default, the current session is purged ([`LogoutBehaviour::PurgeSession`]).
pub fn logout_behaviour(mut self, logout_behaviour: LogoutBehaviour) -> Self {
self.configuration.on_logout = logout_behaviour;
/// By default, the current session is purged ([`LogoutBehavior::PurgeSession`]).
pub fn logout_behavior(mut self, logout_behavior: LogoutBehavior) -> Self {
self.configuration.on_logout = logout_behavior;
self
}

View File

@@ -8,7 +8,7 @@ use actix_web::{
};
use crate::{
config::LogoutBehaviour,
config::LogoutBehavior,
error::{
GetIdentityError, LoginError, LostIdentityError, MissingIdentityError, SessionExpiryError,
},
@@ -49,11 +49,11 @@ use crate::{
/// }
/// ```
///
/// # Extractor Behaviour
/// # Extractor Behavior
/// What happens if you try to extract an `Identity` out of a request that does not have a valid
/// identity attached? The API will return a `401 UNAUTHORIZED` to the caller.
///
/// If you want to customise this behaviour, consider extracting `Option<Identity>` or
/// If you want to customize this behavior, consider extracting `Option<Identity>` or
/// `Result<Identity, actix_web::Error>` instead of a bare `Identity`: you will then be fully in
/// control of the error path.
///
@@ -79,7 +79,7 @@ pub struct Identity(IdentityInner);
#[derive(Clone)]
pub(crate) struct IdentityInner {
pub(crate) session: Session,
pub(crate) logout_behaviour: LogoutBehaviour,
pub(crate) logout_behavior: LogoutBehavior,
pub(crate) is_login_deadline_enabled: bool,
pub(crate) is_visit_deadline_enabled: bool,
pub(crate) id_key: &'static str,
@@ -171,7 +171,7 @@ impl Identity {
/// After `logout` has been called, the user will no longer be able to access routes that
/// require a valid [`Identity`].
///
/// The behaviour on logout is determined by [`IdentityMiddlewareBuilder::logout_behaviour`].
/// The behavior on logout is determined by [`IdentityMiddlewareBuilder::logout_behavior`].
///
/// # Examples
/// ```
@@ -185,13 +185,13 @@ impl Identity {
/// }
/// ```
///
/// [`IdentityMiddlewareBuilder::logout_behaviour`]: crate::config::IdentityMiddlewareBuilder::logout_behaviour
/// [`IdentityMiddlewareBuilder::logout_behavior`]: crate::config::IdentityMiddlewareBuilder::logout_behavior
pub fn logout(self) {
match self.0.logout_behaviour {
LogoutBehaviour::PurgeSession => {
match self.0.logout_behavior {
LogoutBehavior::PurgeSession => {
self.0.session.purge();
}
LogoutBehaviour::DeleteIdentityKeys => {
LogoutBehavior::DeleteIdentityKeys => {
self.0.session.remove(self.0.id_key);
if self.0.is_login_deadline_enabled {
self.0.session.remove(self.0.login_unix_timestamp_key);

View File

@@ -1,98 +1,96 @@
/*!
Identity management for Actix Web.
`actix-identity` can be used to track identity of a user across multiple requests. It is built
on top of HTTP sessions, via [`actix-session`](https://docs.rs/actix-session).
# Getting started
To start using identity management in your Actix Web application you must register
[`IdentityMiddleware`] and `SessionMiddleware` as middleware on your `App`:
```no_run
# use actix_web::web;
use actix_web::{cookie::Key, App, HttpServer, HttpResponse};
use actix_identity::IdentityMiddleware;
use actix_session::{storage::RedisSessionStore, SessionMiddleware};
#[actix_web::main]
async fn main() {
// When using `Key::generate()` it is important to initialize outside of the
// `HttpServer::new` closure. When deployed the secret key should be read from a
// configuration file or environment variables.
let secret_key = Key::generate();
let redis_store = RedisSessionStore::new("redis://127.0.0.1:6379")
.await
.unwrap();
HttpServer::new(move || {
App::new()
// Install the identity framework first.
.wrap(IdentityMiddleware::default())
// The identity system is built on top of sessions. You must install the session
// middleware to leverage `actix-identity`. The session middleware must be mounted
// AFTER the identity middleware: `actix-web` invokes middleware in the OPPOSITE
// order of registration when it receives an incoming request.
.wrap(SessionMiddleware::new(
redis_store.clone(),
secret_key.clone(),
))
// Your request handlers [...]
# .default_service(web::to(|| HttpResponse::Ok()))
})
# ;
}
```
User identities can be created, accessed and destroyed using the [`Identity`] extractor in your
request handlers:
```no_run
use actix_web::{get, post, HttpResponse, Responder, HttpRequest, HttpMessage};
use actix_identity::Identity;
use actix_session::storage::RedisSessionStore;
#[get("/")]
async fn index(user: Option<Identity>) -> impl Responder {
if let Some(user) = user {
format!("Welcome! {}", user.id().unwrap())
} else {
"Welcome Anonymous!".to_owned()
}
}
#[post("/login")]
async fn login(request: HttpRequest) -> impl Responder {
// Some kind of authentication should happen here
// e.g. password-based, biometric, etc.
// [...]
// attach a verified user identity to the active session
Identity::login(&request.extensions(), "User1".into()).unwrap();
HttpResponse::Ok()
}
#[post("/logout")]
async fn logout(user: Option<Identity>) -> impl Responder {
if let Some(user) = user {
user.logout();
}
HttpResponse::Ok()
}
```
# Advanced configuration
By default, `actix-identity` does not automatically log out users. You can change this behaviour
by customising the configuration for [`IdentityMiddleware`] via [`IdentityMiddleware::builder`].
In particular, you can automatically log out users who:
- have been inactive for a while (see [`IdentityMiddlewareBuilder::visit_deadline`]);
- logged in too long ago (see [`IdentityMiddlewareBuilder::login_deadline`]).
[`IdentityMiddlewareBuilder::visit_deadline`]: config::IdentityMiddlewareBuilder::visit_deadline
[`IdentityMiddlewareBuilder::login_deadline`]: config::IdentityMiddlewareBuilder::login_deadline
*/
//! Identity management for Actix Web.
//!
//! `actix-identity` can be used to track identity of a user across multiple requests. It is built
//! on top of HTTP sessions, via [`actix-session`](https://docs.rs/actix-session).
//!
//! # Getting started
//! To start using identity management in your Actix Web application you must register
//! [`IdentityMiddleware`] and `SessionMiddleware` as middleware on your `App`:
//!
//! ```no_run
//! # use actix_web::web;
//! use actix_web::{cookie::Key, App, HttpServer, HttpResponse};
//! use actix_identity::IdentityMiddleware;
//! use actix_session::{storage::RedisSessionStore, SessionMiddleware};
//!
//! #[actix_web::main]
//! async fn main() {
//! // When using `Key::generate()` it is important to initialize outside of the
//! // `HttpServer::new` closure. When deployed the secret key should be read from a
//! // configuration file or environment variables.
//! let secret_key = Key::generate();
//!
//! let redis_store = RedisSessionStore::new("redis://127.0.0.1:6379")
//! .await
//! .unwrap();
//!
//! HttpServer::new(move || {
//! App::new()
//! // Install the identity framework first.
//! .wrap(IdentityMiddleware::default())
//! // The identity system is built on top of sessions. You must install the session
//! // middleware to leverage `actix-identity`. The session middleware must be mounted
//! // AFTER the identity middleware: `actix-web` invokes middleware in the OPPOSITE
//! // order of registration when it receives an incoming request.
//! .wrap(SessionMiddleware::new(
//! redis_store.clone(),
//! secret_key.clone(),
//! ))
//! // Your request handlers [...]
//! # .default_service(web::to(|| HttpResponse::Ok()))
//! })
//! # ;
//! }
//! ```
//!
//! User identities can be created, accessed and destroyed using the [`Identity`] extractor in your
//! request handlers:
//!
//! ```no_run
//! use actix_web::{get, post, HttpResponse, Responder, HttpRequest, HttpMessage};
//! use actix_identity::Identity;
//! use actix_session::storage::RedisSessionStore;
//!
//! #[get("/")]
//! async fn index(user: Option<Identity>) -> impl Responder {
//! if let Some(user) = user {
//! format!("Welcome! {}", user.id().unwrap())
//! } else {
//! "Welcome Anonymous!".to_owned()
//! }
//! }
//!
//! #[post("/login")]
//! async fn login(request: HttpRequest) -> impl Responder {
//! // Some kind of authentication should happen here
//! // e.g. password-based, biometric, etc.
//! // [...]
//!
//! // attach a verified user identity to the active session
//! Identity::login(&request.extensions(), "User1".into()).unwrap();
//!
//! HttpResponse::Ok()
//! }
//!
//! #[post("/logout")]
//! async fn logout(user: Option<Identity>) -> impl Responder {
//! if let Some(user) = user {
//! user.logout();
//! }
//! HttpResponse::Ok()
//! }
//! ```
//!
//! # Advanced configuration
//! By default, `actix-identity` does not automatically log out users. You can change this behavior
//! by customizing the configuration for [`IdentityMiddleware`] via [`IdentityMiddleware::builder`].
//!
//! In particular, you can automatically log out users who:
//! - have been inactive for a while (see [`IdentityMiddlewareBuilder::visit_deadline`]);
//! - logged in too long ago (see [`IdentityMiddlewareBuilder::login_deadline`]).
//!
//! [`IdentityMiddlewareBuilder::visit_deadline`]: config::IdentityMiddlewareBuilder::visit_deadline
//! [`IdentityMiddlewareBuilder::login_deadline`]: config::IdentityMiddlewareBuilder::login_deadline
#![forbid(unsafe_code)]
#![deny(missing_docs)]

View File

@@ -111,7 +111,7 @@ where
Box::pin(async move {
let identity_inner = IdentityInner {
session: req.get_session(),
logout_behaviour: configuration.on_logout.clone(),
logout_behavior: configuration.on_logout.clone(),
is_login_deadline_enabled: configuration.login_deadline.is_some(),
is_visit_deadline_enabled: configuration.visit_deadline.is_some(),
id_key: configuration.id_key,

View File

@@ -1,6 +1,6 @@
use std::time::Duration;
use actix_identity::{config::LogoutBehaviour, IdentityMiddleware};
use actix_identity::{config::LogoutBehavior, IdentityMiddleware};
use reqwest::StatusCode;
use crate::{fixtures::user_id, test_app::TestApp};
@@ -112,7 +112,7 @@ async fn logout_works() {
#[actix_web::test]
async fn logout_can_avoid_destroying_the_whole_session() {
let app = TestApp::spawn_with_config(
IdentityMiddleware::builder().logout_behaviour(LogoutBehaviour::DeleteIdentityKeys),
IdentityMiddleware::builder().logout_behavior(LogoutBehavior::DeleteIdentityKeys),
);
let user_id = user_id();

View File

@@ -1,4 +1,4 @@
//! Configuration options to tune the behaviour of [`SessionMiddleware`].
//! Configuration options to tune the behavior of [`SessionMiddleware`].
use actix_web::cookie::{time::Duration, Key, SameSite};
use derive_more::derive::From;
@@ -344,7 +344,7 @@ impl<Store: SessionStore> SessionMiddlewareBuilder<Store> {
self
}
/// Finalise the builder and return a [`SessionMiddleware`] instance.
/// Finalize the builder and return a [`SessionMiddleware`] instance.
#[must_use]
pub fn build(self) -> SessionMiddleware<Store> {
SessionMiddleware::from_parts(self.storage_backend, self.configuration)

View File

@@ -76,7 +76,7 @@ use crate::{
/// }
/// ```
///
/// If you want to customise use [`builder`](Self::builder) instead of [`new`](Self::new):
/// If you want to customize use [`builder`](Self::builder) instead of [`new`](Self::new):
///
/// ```no_run
/// use actix_web::{App, cookie::{Key, time}, Error, HttpResponse, HttpServer, web};
@@ -96,7 +96,7 @@ use crate::{
///
/// HttpServer::new(move || {
/// App::new()
/// // Customise session length!
/// // Customize session length!
/// .wrap(
/// SessionMiddleware::builder(storage.clone(), secret_key.clone())
/// .session_lifecycle(

View File

@@ -429,7 +429,7 @@ mod tests {
.await;
let req = actix_web::test::TestRequest::with_uri("/")
.append_header(("Authorization", "Basic DontCare"))
.append_header(("Authorization", "Basic DoNotCare"))
.to_request();
let resp = srv.call(req).await.unwrap();

View File

@@ -85,7 +85,7 @@ test-docs:
[group("docs")]
doc *args: && doc-set-workspace-crates
rm -f "$(cargo metadata --format-version=1 | jq -r '.target_directory')/doc/crates.js"
RUSTDOCFLAGS="--cfg=docsrs -Dwarnings" cargo +nightly doc --workspace --all-features {{ args }}
RUSTDOCFLAGS="--cfg=docsrs -D warnings" cargo +nightly doc --workspace --all-features {{ args }}
[group("docs")]
[private]

46598
lcov.info

File diff suppressed because it is too large Load Diff