From 203353c2d023e6d9b89447a86fad5b4a64dd82ab Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Mon, 16 Dec 2024 00:43:02 +0100 Subject: [PATCH 1/6] added PartialEq to Cors --- actix-cors/src/builder.rs | 20 ++++++++++++++++++++ actix-cors/src/inner.rs | 8 +++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/actix-cors/src/builder.rs b/actix-cors/src/builder.rs index 7aec5cea8..ab8381144 100644 --- a/actix-cors/src/builder.rs +++ b/actix-cors/src/builder.rs @@ -608,6 +608,19 @@ where .unwrap() } +impl PartialEq for Cors { + fn eq(&self, other: &Self) -> bool { + self.inner == other.inner + // Because of the cors-function, checking if the content is equal implies that the errors are equal + // + // Proof by contradiction: + // Lets assume that the inner values are equal, but the error values are not. + // This means there had been an error, which has been fixed. + // This cannot happen as the first call to set the invalid value means that further usages of the cors-function will reject other input. + // => inner has to be in a different state + } +} + #[cfg(test)] mod test { use std::convert::Infallible; @@ -679,4 +692,11 @@ mod test { Cors::default().new_transform(srv).await.unwrap(); } + + #[test] + fn impl_eq() { + assert_eq!(Cors::default().send_wildcard(), Cors::default()); + assert_ne!(Cors::default().send_wildcard(), Cors::default()); + assert_ne!(Cors::default(), Cors::permissive()); + } } diff --git a/actix-cors/src/inner.rs b/actix-cors/src/inner.rs index 93ab7c77d..0ac83e110 100644 --- a/actix-cors/src/inner.rs +++ b/actix-cors/src/inner.rs @@ -27,6 +27,12 @@ impl Default for OriginFn { } } +impl PartialEq for OriginFn { + fn eq(&self, other: &Self) -> bool { + Rc::ptr_eq(&self.boxed_fn, &other.boxed_fn) + } +} + impl fmt::Debug for OriginFn { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str("origin_fn") @@ -40,7 +46,7 @@ pub(crate) fn header_value_try_into_method(hdr: &HeaderValue) -> Option .and_then(|meth| Method::try_from(meth).ok()) } -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq)] pub(crate) struct Inner { pub(crate) allowed_origins: AllOrSome>, pub(crate) allowed_origins_fns: SmallVec<[OriginFn; 4]>, From 202a80fb31b7bb2427126e3bb4241393b65e2947 Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Mon, 16 Dec 2024 00:49:19 +0100 Subject: [PATCH 2/6] added a changelog entry --- actix-cors/CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/actix-cors/CHANGES.md b/actix-cors/CHANGES.md index f950c315f..03a134cc6 100644 --- a/actix-cors/CHANGES.md +++ b/actix-cors/CHANGES.md @@ -2,6 +2,8 @@ ## Unreleased +- Implement `PartialEq` for `Cors` allowing for better testing. [#486] + ## 0.7.0 - `Cors` is now marked `#[must_use]`. From 7983727be35545eb97b2cb07813055ee487ebbee Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Mon, 16 Dec 2024 00:50:06 +0100 Subject: [PATCH 3/6] re-ran rustfmt --- actix-cors/src/builder.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actix-cors/src/builder.rs b/actix-cors/src/builder.rs index ab8381144..50787fb17 100644 --- a/actix-cors/src/builder.rs +++ b/actix-cors/src/builder.rs @@ -692,7 +692,7 @@ mod test { Cors::default().new_transform(srv).await.unwrap(); } - + #[test] fn impl_eq() { assert_eq!(Cors::default().send_wildcard(), Cors::default()); From 54b12a641ac873216c10ac826a9468acfd113ca8 Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Mon, 16 Dec 2024 00:57:30 +0100 Subject: [PATCH 4/6] removed a subtle bug in the new testcase --- actix-cors/src/builder.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actix-cors/src/builder.rs b/actix-cors/src/builder.rs index 50787fb17..3e0ba9136 100644 --- a/actix-cors/src/builder.rs +++ b/actix-cors/src/builder.rs @@ -695,8 +695,8 @@ mod test { #[test] fn impl_eq() { + assert_ne!(Cors::default(), Cors::default()); assert_eq!(Cors::default().send_wildcard(), Cors::default()); - assert_ne!(Cors::default().send_wildcard(), Cors::default()); assert_ne!(Cors::default(), Cors::permissive()); } } From 2a22d8a78e870bada6a6bc54ebc4263b07a654b5 Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Mon, 16 Dec 2024 00:59:36 +0100 Subject: [PATCH 5/6] removed a not so subtle bug in the new testcase --- actix-cors/src/builder.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/actix-cors/src/builder.rs b/actix-cors/src/builder.rs index 3e0ba9136..e8b7d40bd 100644 --- a/actix-cors/src/builder.rs +++ b/actix-cors/src/builder.rs @@ -695,8 +695,8 @@ mod test { #[test] fn impl_eq() { - assert_ne!(Cors::default(), Cors::default()); - assert_eq!(Cors::default().send_wildcard(), Cors::default()); + assert_eq!(Cors::default(), Cors::default()); + assert_ne!(Cors::default().send_wildcard(), Cors::default()); assert_ne!(Cors::default(), Cors::permissive()); } } From aee2a072b0e518a7a7a8d35c81c5bb70d3c54b2d Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Sun, 29 Dec 2024 16:33:27 +0000 Subject: [PATCH 6/6] ci: rm public-api-diff job --- .github/workflows/lint.yml | 29 ----------------------------- 1 file changed, 29 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 524f9e32a..58a66d5b5 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -46,32 +46,3 @@ jobs: clippy_flags: >- --workspace --all-features --tests --examples --bins -- -A unknown_lints -D clippy::todo -D clippy::dbg_macro - - public-api-diff: - runs-on: ubuntu-latest - steps: - - name: checkout ${{ github.base_ref }} - uses: actions/checkout@v4 - with: - ref: ${{ github.base_ref }} - - - name: checkout ${{ github.head_ref }} - uses: actions/checkout@v4 - - - name: Install Rust (${{ vars.RUST_VERSION_API_DIFF }}) - uses: actions-rust-lang/setup-rust-toolchain@v1.10.1 - with: - toolchain: ${{ vars.RUST_VERSION_API_DIFF }} - - - name: Install cargo-public-api - uses: taiki-e/cache-cargo-install-action@v2.0.1 - with: - tool: cargo-public-api - - - name: generate API diff - run: | - for f in $(find -mindepth 2 -maxdepth 2 -name Cargo.toml); do - - cargo public-api --manifest-path "$f" --all-features diff ${{ github.event.pull_request.base.sha }}..${{ github.sha }} >> /tmp/diff.txt - done - cat /tmp/diff.txt