Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

impl Challenge for &'static str #248

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

mcronce
Copy link
Contributor

@mcronce mcronce commented May 24, 2022

PR Type

Feature

PR Checklist

  • Tests for the changes have been added / updated.
  • Documentation comments have been added / updated.
  • A changelog entry has been made for the appropriate packages.
  • Format code with the nightly rustfmt (cargo +nightly fmt).

Overview

As it stands, using actix-web-httpauth::middleware::HttpAuthentication requires creating a type that impls Challenge in order to return an AuthenticationError. This makes it possible to simply (e.g.) return Err(AuthenticationError::new("Authentication required").into()) from your auth check function.

@mcronce
Copy link
Contributor Author

mcronce commented May 24, 2022

I don't know how useful the test really is, but it allowed me to check the box ;)

@robjtede robjtede requested a review from a team May 24, 2022 14:10
@mcronce mcronce changed the title actix-web-httpauth: impl Challenge for &str actix-web-httpauth: impl Challenge for &'static str May 24, 2022
@@ -1,6 +1,7 @@
# Changes

## Unreleased - 2021-xx-xx
- impl Challenge for &str
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- impl Challenge for &str
- impl `Challenge` for `&str`

use super::*;

#[proptest]
fn roundtrip_static_str(input: Box<str>) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if that conversion really needs to use such expensive testing, isn't it enough to add a basic test? We should be cautious to add an additional test framework just for one test.

#[proptest]
fn roundtrip_static_str(input: Box<str>) {
// This will leak, but it's probably fine in the context of a test. Fixable by adding:
// unsafe { Box::from_raw(s as *const str as *mut str); }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unleaking is UB, especially through a shared reference. This should use Box::into_raw and Box::from_raw if memory is to be cleaned up.

@JohnTitor
Copy link
Member

JohnTitor commented May 24, 2022

(The CI failure seems unrelated to this PR it's related but we don't have to run tests on MSRV, I'm going to take a look at the config later today™)

@robjtede robjtede changed the title actix-web-httpauth: impl Challenge for &'static str impl Challenge for &'static str May 24, 2022
@JohnTitor JohnTitor mentioned this pull request May 25, 2022
4 tasks
@robjtede robjtede added A-httpauth Project: actix-web-httpauth B-semver-minor labels Jul 19, 2022
@robjtede robjtede marked this pull request as draft July 22, 2022 23:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-httpauth Project: actix-web-httpauth B-semver-minor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants