Skip to content

Commit

Permalink
do not remove main security structure when an invalid one is set
Browse files Browse the repository at this point in the history
  • Loading branch information
giannis-rdx committed Jan 31, 2025
1 parent 1e5dcac commit f402822
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ impl MainSecurityStructureUpdating for Security {
None => vec![*shield_id],
};

self.update_security_structure_add_flag_main(shield_id)?;

if let Some(current_main_shield) = &current_main_shield {
self.update_security_structure_remove_flag_main(
&current_main_shield.metadata.id,
)?;
}
self.update_security_structure_add_flag_main(shield_id)?;

Ok(updated_ids)
}
Expand Down
36 changes: 36 additions & 0 deletions crates/system/os/factors/src/sargon_os_security_structures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,42 @@ mod tests {
);
}

#[actix_rt::test]
async fn given_existing_main_security_structure_when_updating_with_invalid_id_then_main_is_not_removed(
) {
// ARRANGE
let os = SUT::fast_boot().await;
os.with_timeout(|x| x.debug_add_all_sample_hd_factor_sources())
.await
.unwrap();

let structure_factor_id_level =
SecurityStructureOfFactorSourceIDs::sample();
os.with_timeout(|x| {
x.add_security_structure_of_factor_source_ids(
&structure_factor_id_level,
)
})
.await
.unwrap();

// ACT
let invalid_shield_id =
SecurityStructureID::from(Uuid::from_bytes([0xab; 16]));
let _ = os.set_main_security_structure(invalid_shield_id).await;

// ASSERT
let profile = os.profile().unwrap();
let main_security_structure = profile
.app_preferences
.security
.security_structures_of_factor_source_ids
.first()
.unwrap();

assert!(main_security_structure.metadata.is_main());
}

#[actix_rt::test]
async fn set_main_flag() {
// ARRANGE
Expand Down

0 comments on commit f402822

Please sign in to comment.