Skip to content

Commit 61ec0d6

Browse files
authored
chore: tiny doc and code consistency fixes (#348)
1 parent c0bb892 commit 61ec0d6

File tree

10 files changed

+57
-90
lines changed

10 files changed

+57
-90
lines changed

cot-macros/src/dbtest.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub(super) fn fn_to_dbtest(test_function_decl: ItemFn) -> syn::Result<TokenStrea
1616
}
1717

1818
let result = quote! {
19-
#[::tokio::test]
19+
#[::cot::test]
2020
#[cfg_attr(miri, ignore)] // unsupported operation: can't call foreign function `sqlite3_open_v2`
2121
async fn #sqlite_ident() {
2222
let mut database = cot::test::TestDatabase::new_sqlite().await.unwrap();
@@ -29,7 +29,7 @@ pub(super) fn fn_to_dbtest(test_function_decl: ItemFn) -> syn::Result<TokenStrea
2929
}
3030

3131
#[ignore = "Tests that use PostgreSQL are ignored by default"]
32-
#[::tokio::test]
32+
#[::cot::test]
3333
async fn #postgres_ident() {
3434
let mut database = cot::test::TestDatabase::new_postgres(stringify!(#test_fn))
3535
.await
@@ -43,7 +43,7 @@ pub(super) fn fn_to_dbtest(test_function_decl: ItemFn) -> syn::Result<TokenStrea
4343
}
4444

4545
#[ignore = "Tests that use MySQL are ignored by default"]
46-
#[::tokio::test]
46+
#[::cot::test]
4747
async fn #mysql_ident() {
4848
let mut database = cot::test::TestDatabase::new_mysql(stringify!(#test_fn))
4949
.await

cot-macros/src/lib.rs

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -195,32 +195,7 @@ pub(crate) fn cot_ident() -> proc_macro2::TokenStream {
195195
}
196196
}
197197
}
198-
/// A derive macro that automatically implements the [`FromRequestParts`] trait
199-
/// for structs.
200-
///
201-
/// This macro generates code to extract each field of the struct from HTTP
202-
/// request parts, making it easy to create composite extractors that combine
203-
/// multiple data sources from an incoming request.
204-
///
205-
/// The macro works by calling [`FromRequestParts::from_request_parts`] on each
206-
/// field's type, allowing you to compose extractors seamlessly. All fields must
207-
/// implement the [`FromRequestParts`] trait for the derivation to work.
208-
///
209-
/// # Examples
210-
///
211-
/// ## Named Fields
212-
///
213-
/// ```no_run
214-
/// use cot::request::extractors::{Path, StaticFiles, UrlQuery};
215-
/// use cot::router::Urls;
216-
/// use cot_macros::FromRequestParts;
217-
///
218-
/// #[derive(Debug, FromRequestParts)]
219-
/// pub struct BaseContext {
220-
/// urls: Urls,
221-
/// static_files: StaticFiles,
222-
/// }
223-
/// ```
198+
224199
#[proc_macro_derive(FromRequestParts)]
225200
pub fn derive_from_request_parts(input: TokenStream) -> TokenStream {
226201
let ast = parse_macro_input!(input as syn::DeriveInput);

cot/src/admin.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,6 @@ use cot::request::extractors::StaticFiles;
1818
/// [`Form`] traits. These can also be derived using the `#[model]` and
1919
/// `#[derive(Form)]` attributes.
2020
pub use cot_macros::AdminModel;
21-
/// Implements the [`FromRequestParts`] trait for a struct.
22-
///
23-
/// This derive macro allows a struct to be used as a request part extractor.
24-
/// All fields must implement
25-
/// [`FromRequestParts`](crate::request::extractors::FromRequestParts), and only
26-
/// structs are supported (not enums or unions).
2721
use derive_more::Debug;
2822
use http::request::Parts;
2923
use serde::Deserialize;

cot/src/auth.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,9 @@ pub type Result<T> = std::result::Result<T, AuthError>;
7777
///
7878
/// This trait is used to represent a user object that can be authenticated and
7979
/// is a core of the authentication system. A `User` object is returned by
80-
/// [`AuthRequestExt::user()`] and is used to check if a user is authenticated
81-
/// and to access user data. If there is no active user session, the `User`
82-
/// object returned by [`AuthRequestExt::user()`] is an [`AnonymousUser`]
83-
/// object.
80+
/// [`Auth::user()`] and is used to check if a user is authenticated and to
81+
/// access user data. If there is no active user session, the `User` object
82+
/// returned by [`Auth::user()`] is an [`AnonymousUser`] object.
8483
///
8584
/// A concrete instance of a `User` object is returned by a backend that
8685
/// implements the [`AuthBackend`] trait. The default backend is the
@@ -312,8 +311,7 @@ impl Debug for UserWrapper {
312311
/// An anonymous, unauthenticated user.
313312
///
314313
/// This is used to represent a user that is not authenticated. It is returned
315-
/// by the [`AuthRequestExt::user()`] method when there is no active user
316-
/// session.
314+
/// by the [`Auth::user()`] method when there is no active user session.
317315
#[derive(Debug, Copy, Clone, Default)]
318316
pub struct AnonymousUser;
319317

cot/src/auth/db.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -425,9 +425,8 @@ impl Display for DatabaseUser {
425425
/// This struct is used to authenticate a user stored in the database. It
426426
/// contains the username and password of the user.
427427
///
428-
/// Can be passed to
429-
/// [`AuthRequestExt::authenticate`](crate::auth::AuthRequestExt::authenticate)
430-
/// to authenticate a user when using the [`DatabaseUserBackend`].
428+
/// Can be passed to [`Auth::authenticate`](crate::auth::Auth::authenticate) to
429+
/// authenticate a user when using the [`DatabaseUserBackend`].
431430
#[derive(Debug, Clone)]
432431
pub struct DatabaseUserCredentials {
433432
username: String,

cot/src/common_types.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const MAX_EMAIL_LENGTH: u32 = 254;
2929
/// the password value.
3030
///
3131
/// For persisting passwords in the database, and verifying passwords against
32-
/// the hash, use [`PasswordHash`].
32+
/// the hash, use [`PasswordHash`](crate::auth::PasswordHash).
3333
///
3434
/// # Security
3535
///
@@ -40,10 +40,12 @@ const MAX_EMAIL_LENGTH: u32 = 254;
4040
///
4141
/// When comparing passwords, there are two recommended approaches:
4242
///
43-
/// 1. The most secure approach is to use [`PasswordHash::from_password`] to
44-
/// create a hash from one password, and then use [`PasswordHash::verify`] to
45-
/// compare it with the other password. This method uses constant-time
46-
/// equality comparison, which protects against timing attacks.
43+
/// 1. The most secure approach is to use
44+
/// [`PasswordHash::from_password`](crate::auth::PasswordHash::from_password)
45+
/// to create a hash from one password, and then use
46+
/// [`PasswordHash::verify`](crate::auth::PasswordHash::verify) to compare it
47+
/// with the other password. This method uses constant-time equality
48+
/// comparison, which protects against timing attacks.
4749
///
4850
/// 2. An alternative is to use the [`Password::as_str`] method and compare the
4951
/// strings directly. This approach uses non-constant-time comparison, which
@@ -135,9 +137,8 @@ impl From<String> for Password {
135137

136138
/// A validated email address.
137139
///
138-
/// This is a newtype wrapper around
139-
/// [`EmailAddress`](email_address::EmailAddress) that provides validation and
140-
/// integration with Cot's database system. It ensures email addresses
140+
/// This is a newtype wrapper around [`EmailAddress`] that provides validation
141+
/// and integration with Cot's database system. It ensures email addresses
141142
/// comply with RFC 5321/5322 standards.
142143
///
143144
/// # Examples

cot/src/middleware.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ mod tests {
671671
use crate::session::Session;
672672
use crate::test::TestRequestBuilder;
673673

674-
#[tokio::test]
674+
#[cot::test]
675675
async fn session_middleware_adds_session() {
676676
let svc = tower::service_fn(|req: Request<Body>| async move {
677677
assert!(req.extensions().get::<Session>().is_some());
@@ -685,7 +685,7 @@ mod tests {
685685
svc.ready().await.unwrap().call(request).await.unwrap();
686686
}
687687

688-
#[tokio::test]
688+
#[cot::test]
689689
async fn session_middleware_adds_cookie() {
690690
let svc = tower::service_fn(|req: Request<Body>| async move {
691691
let session = req.extensions().get::<Session>().unwrap();
@@ -713,7 +713,7 @@ mod tests {
713713
assert!(cookie_value.contains("Path=/"));
714714
}
715715

716-
#[tokio::test]
716+
#[cot::test]
717717
async fn session_middleware_adds_cookie_not_secure() {
718718
let svc = tower::service_fn(|req: Request<Body>| async move {
719719
let session = req.extensions().get::<Session>().unwrap();
@@ -736,7 +736,7 @@ mod tests {
736736
assert!(!cookie_value.contains("Secure;"));
737737
}
738738

739-
#[tokio::test]
739+
#[cot::test]
740740
async fn auth_middleware_adds_auth() {
741741
let svc = tower::service_fn(|req: Request<Body>| async move {
742742
let auth = req
@@ -756,7 +756,7 @@ mod tests {
756756
svc.ready().await.unwrap().call(request).await.unwrap();
757757
}
758758

759-
#[tokio::test]
759+
#[cot::test]
760760
#[should_panic(
761761
expected = "Session extension missing. Did you forget to add the SessionMiddleware?"
762762
)]
@@ -773,7 +773,7 @@ mod tests {
773773
let _result = svc.ready().await.unwrap().call(request).await;
774774
}
775775

776-
#[tokio::test]
776+
#[cot::test]
777777
async fn auth_service_cloning() {
778778
let counter = Arc::new(std::sync::atomic::AtomicUsize::new(0));
779779
let counter_clone = counter.clone();

cot/src/request.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ mod tests {
771771
assert!(request.expect_content_type("application/json").is_err());
772772
}
773773

774-
#[tokio::test]
774+
#[cot::test]
775775
async fn request_ext_extract_parts() {
776776
async fn handler(mut request: Request) -> Result<Response> {
777777
let Path(id): Path<String> = request.extract_parts().await?;
@@ -839,7 +839,7 @@ mod tests {
839839
);
840840
}
841841

842-
#[tokio::test]
842+
#[cot::test]
843843
async fn parts_extract_parts() {
844844
let (mut parts, _) = Request::new(Body::empty()).into_parts();
845845

0 commit comments

Comments
 (0)