1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-27 17:22:57 +01:00

Merge pull request #58 from adamchalmers/patch-1

Bugfix: AuthenticationError should set status_code
This commit is contained in:
Yuki Okushi 2020-05-20 11:01:31 +09:00 committed by GitHub
commit 61d5586052
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 0 deletions

View File

@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [unreleased]
- Update the `base64` dependency to 0.12
- AuthenticationError's status code is preserved when converting to a ResponseError
## [0.4.1] - 2020-02-19
- Move repository to actix-extras

View File

@ -57,4 +57,26 @@ impl<C: 'static + Challenge> ResponseError for AuthenticationError<C> {
.set(WwwAuthenticate(self.challenge.clone()))
.finish()
}
fn status_code(&self) -> StatusCode {
self.status_code
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::headers::www_authenticate::basic::Basic;
use actix_web::Error;
#[test]
fn test_status_code_is_preserved_across_error_conversions() {
let ae: AuthenticationError<Basic> = AuthenticationError::new(Basic::default());
let expected = ae.status_code;
// Converting the AuthenticationError into a ResponseError should preserve the status code.
let e = Error::from(ae);
let re = e.as_response_error();
assert_eq!(expected, re.status_code());
}
}