Skip to content

Commit

Permalink
fix all tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Sajjon committed Dec 19, 2024
1 parent 1ff2f54 commit b2ca5b9
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -772,10 +772,10 @@ mod tests {
sut.remove_factor_from_confirmation(f.clone());
assert_eq!(xs, sut.get_confirmation_factors());

assert!(matches!(
sut.validate(),
Some(SecurityShieldBuilderInvalidReason::MissingAuthSigningFactor)
));
assert_eq!(
sut.validate().unwrap(),
SecurityShieldBuilderInvalidReason::MissingAuthSigningFactor
);
sut.set_authentication_signing_factor(Some(
FactorSourceID::sample_device_other(),
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ impl SecurityShieldBuilder {

pub fn set_authentication_signing_factor(
&self,
new: Option<FactorSourceID>,
new: impl Into<Option<FactorSourceID>>,
) -> &Self {
*self.authentication_signing_factor.write().unwrap() = new;
*self.authentication_signing_factor.write().unwrap() = new.into();
self
}

Expand Down Expand Up @@ -435,10 +435,21 @@ impl SecurityShieldBuilder {
if DisplayName::new(self.get_name()).is_err() {
return Some(SecurityShieldBuilderInvalidReason::ShieldNameInvalid);
}
self.get(|builder| {

if let Some(matrix_invalid_reason) = self.get(|builder| {
let r = builder.validate();
r.as_shield_validation()
})
}) {
return Some(matrix_invalid_reason);
}

if self.get_authentication_signing_factor().is_none() {
return Some(
SecurityShieldBuilderInvalidReason::MissingAuthSigningFactor,
);
}

None
}

/// Validates **just** the primary role **in isolation**.
Expand Down Expand Up @@ -578,7 +589,9 @@ mod tests {

let _ = sut
.set_name("S.H.I.E.L.D.")
.set_authentication_signing_factor(Some(FactorSourceID::sample_device()))
.set_authentication_signing_factor(Some(
FactorSourceID::sample_device(),
))
// Primary
.set_number_of_days_until_auto_confirm(42)
.add_factor_source_to_primary_threshold(
Expand Down Expand Up @@ -961,6 +974,7 @@ mod test_invalid {
#[test]
fn valid_is_none() {
let sut = SUT::new();
sut.set_authentication_signing_factor(FactorSourceID::sample_device());
sut.add_factor_source_to_primary_override(
FactorSourceID::sample_device(),
);
Expand All @@ -984,7 +998,9 @@ mod test_invalid {
sut.add_factor_source_to_confirmation_override(
FactorSourceID::sample_arculus(),
);
sut.set_authentication_signing_factor(Some(FactorSourceID::sample_device()));
sut.set_authentication_signing_factor(Some(
FactorSourceID::sample_device(),
));
sut
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ mod tests {
"createdOn": "2023-09-11T16:05:56.000Z",
"lastUpdatedOn": "2023-09-11T16:05:56.000Z"
},
"authenticationSigningFactor": {
"discriminator": "fromHash",
"fromHash": {
"kind": "device",
"body": "f1a93d324dd0f2bff89963ab81ed6e0c2ee7e18c0827dc1d3576b2d9f26bbd0a"
}
},
"matrixOfFactors": {
"primaryRole": {
"threshold": 2,
Expand Down Expand Up @@ -130,6 +137,13 @@ mod tests {
"createdOn": "2023-12-24T17:13:56.123Z",
"lastUpdatedOn": "2023-12-24T17:13:56.123Z"
},
"authenticationSigningFactor": {
"discriminator": "fromHash",
"fromHash": {
"kind": "ledgerHQHardwareWallet",
"body": "ab59987eedd181fe98e512c1ba0f5ff059f11b5c7c56f15614dcc9fe03fec58b"
}
},
"matrixOfFactors": {
"primaryRole": {
"threshold": 1,
Expand Down
14 changes: 14 additions & 0 deletions crates/sargon/src/profile/v100/app_preferences/security.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,13 @@ mod tests {
"createdOn": "2023-09-11T16:05:56.000Z",
"lastUpdatedOn": "2023-09-11T16:05:56.000Z"
},
"authenticationSigningFactor": {
"discriminator": "fromHash",
"fromHash": {
"kind": "device",
"body": "f1a93d324dd0f2bff89963ab81ed6e0c2ee7e18c0827dc1d3576b2d9f26bbd0a"
}
},
"matrixOfFactors": {
"primaryRole": {
"threshold": 2,
Expand Down Expand Up @@ -248,6 +255,13 @@ mod tests {
"createdOn": "2023-12-24T17:13:56.123Z",
"lastUpdatedOn": "2023-12-24T17:13:56.123Z"
},
"authenticationSigningFactor": {
"discriminator": "fromHash",
"fromHash": {
"kind": "ledgerHQHardwareWallet",
"body": "ab59987eedd181fe98e512c1ba0f5ff059f11b5c7c56f15614dcc9fe03fec58b"
}
},
"matrixOfFactors": {
"primaryRole": {
"threshold": 1,
Expand Down

0 comments on commit b2ca5b9

Please sign in to comment.