Skip to content
This repository was archived by the owner on Sep 10, 2024. It is now read-only.

Commit a0f5f3c

Browse files
committed
Enable clippy lints on a workspace level
This enables a lot more lints than before in some crates, so this fixed a lot of warnings as well.
1 parent df3ca5a commit a0f5f3c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+567
-236
lines changed

Cargo.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ package.edition = "2021"
1212
package.homepage = "https://matrix-org.github.io/matrix-authentication-service/"
1313
package.repository = "https://github.com/matrix-org/matrix-authentication-service/"
1414

15+
[workspace.lints.rust]
16+
unsafe_code = "forbid"
17+
18+
[workspace.lints.clippy]
19+
all = "deny"
20+
pedantic = "warn"
21+
22+
str_to_string = "deny"
23+
24+
[workspace.lints.rustdoc]
25+
broken_intra_doc_links = "deny"
26+
1527
[workspace.dependencies]
1628

1729
# High-level error handling

crates/axum-utils/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ license.workspace = true
77
homepage.workspace = true
88
repository.workspace = true
99

10+
[lints]
11+
workspace = true
12+
1013
[dependencies]
1114
async-trait = "0.1.74"
1215
axum = { version = "0.6.20", features = ["headers"] }

crates/axum-utils/src/client_authorization.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ impl Credentials {
8484
}
8585
}
8686

87+
/// Fetch the client from the database
88+
///
89+
/// # Errors
90+
///
91+
/// Returns an error if the client could not be found or if the underlying
92+
/// repository errored.
8793
pub async fn fetch<E>(
8894
&self,
8995
repo: &mut impl RepositoryAccess<Error = E>,
@@ -98,6 +104,11 @@ impl Credentials {
98104
repo.oauth2_client().find_by_client_id(client_id).await
99105
}
100106

107+
/// Verify credentials presented by the client for authentication
108+
///
109+
/// # Errors
110+
///
111+
/// Returns an error if the credentials are invalid.
101112
#[tracing::instrument(skip_all, err)]
102113
pub async fn verify(
103114
&self,

crates/axum-utils/src/cookies.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,13 @@ impl CookieJar {
146146
self
147147
}
148148

149+
/// Load and deserialize a cookie from the jar
150+
///
151+
/// Returns `None` if the cookie is not present
152+
///
153+
/// # Errors
154+
///
155+
/// Returns an error if the cookie cannot be deserialized
149156
pub fn load<T: DeserializeOwned>(&self, key: &str) -> Result<Option<T>, CookieDecodeError> {
150157
let Some(cookie) = self.inner.get(key) else {
151158
return Ok(None);

crates/axum-utils/src/csrf.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ impl CsrfToken {
8080
}
8181

8282
/// Verifies that the value got from an HTML form matches this token
83+
///
84+
/// # Errors
85+
///
86+
/// Returns an error if the value in the form does not match this token
8387
pub fn verify_form_value(&self, form_value: &str) -> Result<(), CsrfError> {
8488
let form_value = BASE64URL_NOPAD.decode(form_value.as_bytes())?;
8589
if self.token[..] == form_value {
@@ -108,10 +112,20 @@ pub struct ProtectedForm<T> {
108112
}
109113

110114
pub trait CsrfExt {
115+
/// Get the current CSRF token out of the cookie jar, generating a new one
116+
/// if necessary
111117
fn csrf_token<C, R>(self, clock: &C, rng: R) -> (CsrfToken, Self)
112118
where
113119
R: RngCore,
114120
C: Clock;
121+
122+
/// Verify that the given CSRF-protected form is valid, returning the inner
123+
/// value
124+
///
125+
/// # Errors
126+
///
127+
/// Returns an error if the CSRF cookie is missing or if the value in the
128+
/// form is invalid
115129
fn verify_form<C, T>(&self, clock: &C, form: ProtectedForm<T>) -> Result<T, CsrfError>
116130
where
117131
C: Clock;

crates/axum-utils/src/http_client_factory.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ pub struct HttpClientFactory {
2929
}
3030

3131
impl HttpClientFactory {
32+
/// Constructs a new HTTP client factory
33+
///
34+
/// # Errors
35+
///
36+
/// Returns an error if the client factory failed to initialise, which can
37+
/// happen when it fails to load the system's CA certificates.
3238
pub async fn new() -> Result<Self, ClientInitError> {
3339
Ok(Self {
3440
traced_connector: make_traced_connector().await?,
@@ -37,10 +43,6 @@ impl HttpClientFactory {
3743
}
3844

3945
/// Constructs a new HTTP client
40-
///
41-
/// # Errors
42-
///
43-
/// Returns an error if the client failed to initialise
4446
pub fn client<B>(&self, category: &'static str) -> ClientService<TracedClient<B>>
4547
where
4648
B: axum::body::HttpBody + Send,
@@ -54,10 +56,6 @@ impl HttpClientFactory {
5456
}
5557

5658
/// Constructs a new [`HttpService`], suitable for `mas-oidc-client`
57-
///
58-
/// # Errors
59-
///
60-
/// Returns an error if the client failed to initialise
6159
pub fn http_service(&self, category: &'static str) -> HttpService {
6260
let client = self.client(category);
6361
let client = (

crates/axum-utils/src/lib.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#![forbid(unsafe_code)]
16-
#![deny(
17-
clippy::all,
18-
clippy::str_to_string,
19-
rustdoc::broken_intra_doc_links,
20-
clippy::future_not_send
21-
)]
22-
#![warn(clippy::pedantic)]
23-
#![allow(clippy::module_name_repetitions, clippy::missing_errors_doc)]
15+
#![deny(clippy::future_not_send)]
16+
#![allow(clippy::module_name_repetitions)]
2417

2518
pub mod client_authorization;
2619
pub mod cookies;

crates/axum-utils/src/session.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ impl SessionInfo {
4242
}
4343

4444
/// Load the [`BrowserSession`] from database
45+
///
46+
/// # Errors
47+
///
48+
/// Returns an error if the session is not found or if the session is not
49+
/// active anymore
4550
pub async fn load_session<E>(
4651
&self,
4752
repo: &mut impl RepositoryAccess<Error = E>,

crates/axum-utils/src/user_authorization.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ pub struct UserAuthorization<F = ()> {
8484

8585
impl<F: Send> UserAuthorization<F> {
8686
// TODO: take scopes to validate as parameter
87+
/// Verify a user authorization and return the session and the protected
88+
/// form value
89+
///
90+
/// # Errors
91+
///
92+
/// Returns an error if the token is invalid, if the user session ended or
93+
/// if the form is missing
8794
pub async fn protected_form<E>(
8895
self,
8996
repo: &mut impl RepositoryAccess<Error = E>,
@@ -103,6 +110,11 @@ impl<F: Send> UserAuthorization<F> {
103110
}
104111

105112
// TODO: take scopes to validate as parameter
113+
/// Verify a user authorization and return the session
114+
///
115+
/// # Errors
116+
///
117+
/// Returns an error if the token is invalid or if the user session ended
106118
pub async fn protected<E>(
107119
self,
108120
repo: &mut impl RepositoryAccess<Error = E>,

crates/cli/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ license.workspace = true
77
homepage.workspace = true
88
repository.workspace = true
99

10+
[lints]
11+
workspace = true
12+
1013
[dependencies]
1114
anyhow.workspace = true
1215
axum = "0.6.20"

0 commit comments

Comments
 (0)