Skip to content

Commit 0cf2993

Browse files
committed
Addressed comments
Signed-off-by: Hugues de Valon <[email protected]>
1 parent 55c1a54 commit 0cf2993

File tree

3 files changed

+23
-45
lines changed

3 files changed

+23
-45
lines changed

src/auth.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,18 @@ impl TryFrom<&Authentication> for RequestAuth {
5757
let client = JWTClient::new(
5858
&env::var("SPIFFE_ENDPOINT_SOCKET").map_err(|e| {
5959
error!(
60-
"Can not read the SPIFFE_ENDPOINT_SOCKET environment variable ({}).",
60+
"Cannot read the SPIFFE_ENDPOINT_SOCKET environment variable ({}).",
6161
e
6262
);
63-
Error::Client(ClientErrorKind::Spiffe)
63+
Error::Client(ClientErrorKind::NoAuthenticator)
6464
})?,
6565
None,
6666
);
6767
let audience = String::from("parsec");
6868

6969
let result = client.fetch(audience, None).map_err(|e| {
7070
error!("Error while fetching the JWT-SVID ({}).", e);
71-
Error::Client(ClientErrorKind::Spiffe)
71+
Error::Client(ClientErrorKind::Spiffe(e))
7272
})?;
7373
Ok(RequestAuth::new(result.svid().as_bytes().into()))
7474
}
@@ -84,6 +84,7 @@ impl PartialEq for Authentication {
8484
(Authentication::Direct(app_name), Authentication::Direct(other_app_name)) => {
8585
app_name == other_app_name
8686
}
87+
(Authentication::JwtSvid, Authentication::JwtSvid) => true,
8788
_ => false,
8889
}
8990
}

src/core/testing/core_tests.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,10 @@ fn core_provider_for_crypto_test() {
179179
.psa_destroy_key(String::from("random key"))
180180
.expect_err("Expected a failure!!");
181181

182-
assert_eq!(res, Error::Client(ClientErrorKind::InvalidProvider));
182+
assert!(matches!(
183+
res,
184+
Error::Client(ClientErrorKind::InvalidProvider)
185+
));
183186
}
184187

185188
#[test]
@@ -694,10 +697,10 @@ fn different_response_type_test() {
694697
.psa_destroy_key(key_name)
695698
.expect_err("Error was expected");
696699

697-
assert_eq!(
700+
assert!(matches!(
698701
err,
699702
Error::Client(ClientErrorKind::InvalidServiceResponseType)
700-
);
703+
));
701704
}
702705

703706
#[test]
@@ -711,7 +714,10 @@ fn response_status_test() {
711714
client.set_mock_read(&stream.pop_bytes_written());
712715
let err = client.ping().expect_err("Error was expected");
713716

714-
assert_eq!(err, Error::Service(status));
717+
assert!(matches!(
718+
err,
719+
Error::Service(ResponseStatus::PsaErrorDataCorrupt)
720+
));
715721
}
716722

717723
#[test]
@@ -720,10 +726,10 @@ fn malformed_response_test() {
720726
client.set_mock_read(&[0xcb_u8; 130]);
721727
let err = client.ping().expect_err("Error was expected");
722728

723-
assert_eq!(
729+
assert!(matches!(
724730
err,
725731
Error::Client(ClientErrorKind::Interface(ResponseStatus::InvalidHeader))
726-
);
732+
));
727733
}
728734

729735
#[test]
@@ -788,10 +794,10 @@ fn failing_ipc_test() {
788794
))));
789795

790796
let err = client.ping().expect_err("Expected to fail");
791-
assert_eq!(
797+
assert!(matches!(
792798
err,
793799
Error::Client(ClientErrorKind::Interface(ResponseStatus::ConnectionError))
794-
);
800+
));
795801
}
796802

797803
#[test]
@@ -866,10 +872,10 @@ fn set_default_auth_direct() {
866872
}),
867873
));
868874

869-
assert_eq!(
875+
assert!(matches!(
870876
client.set_default_auth(None).unwrap_err(),
871877
Error::Client(ClientErrorKind::MissingParam)
872-
);
878+
));
873879

874880
client.set_mock_read(&get_response_bytes_from_result(
875881
NativeResult::ListAuthenticators(operations::list_authenticators::Result {

src/error.rs

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::error;
66
use std::fmt;
77

88
/// Enum used to denote errors returned to the library user
9-
#[derive(Debug, PartialEq)]
9+
#[derive(Debug)]
1010
pub enum Error {
1111
/// Errors originating in the service
1212
Service(ResponseStatus),
@@ -43,7 +43,7 @@ pub enum ClientErrorKind {
4343
/// Required parameter was not provided
4444
MissingParam,
4545
/// Error while using the SPIFFE Workload API
46-
Spiffe,
46+
Spiffe(spiffe::workload::Error),
4747
}
4848

4949
impl From<ClientErrorKind> for Error {
@@ -52,35 +52,6 @@ impl From<ClientErrorKind> for Error {
5252
}
5353
}
5454

55-
impl PartialEq for ClientErrorKind {
56-
fn eq(&self, other: &Self) -> bool {
57-
match self {
58-
ClientErrorKind::Interface(status) => {
59-
if let ClientErrorKind::Interface(other_status) = other {
60-
other_status == status
61-
} else {
62-
false
63-
}
64-
}
65-
ClientErrorKind::Ipc(error) => {
66-
if let ClientErrorKind::Ipc(other_error) = other {
67-
other_error.kind() == error.kind()
68-
} else {
69-
false
70-
}
71-
}
72-
ClientErrorKind::InvalidServiceResponseType => {
73-
matches!(other, ClientErrorKind::InvalidServiceResponseType)
74-
}
75-
ClientErrorKind::InvalidProvider => matches!(other, ClientErrorKind::InvalidProvider),
76-
ClientErrorKind::NoProvider => matches!(other, ClientErrorKind::NoProvider),
77-
ClientErrorKind::NoAuthenticator => matches!(other, ClientErrorKind::NoAuthenticator),
78-
ClientErrorKind::MissingParam => matches!(other, ClientErrorKind::MissingParam),
79-
ClientErrorKind::Spiffe => matches!(other, ClientErrorKind::Spiffe),
80-
}
81-
}
82-
}
83-
8455
impl fmt::Display for ClientErrorKind {
8556
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8657
match self {
@@ -96,7 +67,7 @@ impl fmt::Display for ClientErrorKind {
9667
ClientErrorKind::NoProvider => write!(f, "client is missing an implicit provider"),
9768
ClientErrorKind::NoAuthenticator => write!(f, "service is not reporting any authenticators or none of the reported ones are supported by the client"),
9869
ClientErrorKind::MissingParam => write!(f, "one of the `Option` parameters was required but was not provided"),
99-
ClientErrorKind::Spiffe => write!(f, "error using the SPIFFE Workload API"),
70+
ClientErrorKind::Spiffe(error) => error.fmt(f),
10071
}
10172
}
10273
}

0 commit comments

Comments
 (0)