Skip to content

Commit

Permalink
add flag to Security
Browse files Browse the repository at this point in the history
  • Loading branch information
matiasbzurovski committed Aug 14, 2024
1 parent 6dcef41 commit d8d603b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 12 deletions.
49 changes: 39 additions & 10 deletions src/profile/v100/app_preferences/security.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,18 @@ use crate::prelude::*;
)]
#[serde(rename_all = "camelCase")]
#[display(
"cloud? {}, dev? {}",
"cloud? {}, dev? {}, advanced lock? {}",
is_cloud_profile_sync_enabled,
is_developer_mode_enabled
is_developer_mode_enabled,
is_advanced_lock_enabled
)]
pub struct Security {
pub is_cloud_profile_sync_enabled: bool,
pub is_developer_mode_enabled: bool,

#[serde(default)]
pub is_advanced_lock_enabled: bool,

#[serde(rename = "securityStructuresOfFactorSourceIDs")]
#[serde(default)]
pub security_structures_of_factor_source_ids:
Expand All @@ -35,32 +39,49 @@ impl Security {
pub fn new(
is_cloud_profile_sync_enabled: bool,
is_developer_mode_enabled: bool,
is_advanced_lock_enabled: bool,
security_structures_of_factor_source_ids: SecurityStructuresOfFactorSourceIDs,
) -> Self {
Self {
is_cloud_profile_sync_enabled,
is_developer_mode_enabled,
is_advanced_lock_enabled,
security_structures_of_factor_source_ids,
}
}
}

impl Default for Security {
/// By default we cloud profile sync is enabled and developer mode is disabled, with an empty `structure_configuration_references` list.
/// By default cloud profile sync is enabled, while developer mode and avdanced lock is disabled, with an empty `structure_configuration_references` list.
fn default() -> Self {
Self::new(true, false, SecurityStructuresOfFactorSourceIDs::new())
Self::new(
true,
false,
false,
SecurityStructuresOfFactorSourceIDs::new(),
)
}
}

impl HasSampleValues for Security {
/// A sample used to facilitate unit tests.
fn sample() -> Self {
Self::new(true, true, SecurityStructuresOfFactorSourceIDs::new())
Self::new(
true,
true,
false,
SecurityStructuresOfFactorSourceIDs::new(),
)
}

/// A sample used to facilitate unit tests.
fn sample_other() -> Self {
Self::new(false, false, SecurityStructuresOfFactorSourceIDs::new())
Self::new(
false,
false,
true,
SecurityStructuresOfFactorSourceIDs::new(),
)
}
}

Expand All @@ -83,7 +104,7 @@ mod tests {
}

#[test]
fn default_developer_mode_is_enabled() {
fn default_is_cloud_profile_sync_enabled() {
assert!(SUT::default().is_cloud_profile_sync_enabled);
}

Expand All @@ -92,6 +113,11 @@ mod tests {
assert!(!SUT::default().is_developer_mode_enabled);
}

#[test]
fn default_is_advanced_lock_disabled() {
assert!(!SUT::default().is_advanced_lock_enabled);
}

#[test]
fn default_security_structures_of_factor_source_ids_is_empty() {
assert!(SUT::default()
Expand All @@ -108,7 +134,8 @@ mod tests {
{
"isCloudProfileSyncEnabled": true,
"securityStructuresOfFactorSourceIDs": [],
"isDeveloperModeEnabled": true
"isDeveloperModeEnabled": true,
"isAdvancedLockEnabled": false
}
"#,
)
Expand All @@ -126,6 +153,7 @@ mod tests {
{
"isCloudProfileSyncEnabled": true,
"isDeveloperModeEnabled": true,
"isAdvancedLockEnabled": false,
"securityStructuresOfFactorSourceIDs": [
{
"metadata": {
Expand Down Expand Up @@ -336,7 +364,7 @@ mod tests {
}

#[test]
fn json_deserialize_without_security_structures() {
fn json_deserialize_without_security_structures_nor_advanced_lock() {
let json = r#"
{
"isCloudProfileSyncEnabled": true,
Expand All @@ -345,6 +373,7 @@ mod tests {
"#;

let sut: SUT = serde_json::from_str(json).unwrap();
assert!(sut.security_structures_of_factor_source_ids.is_empty())
assert!(sut.security_structures_of_factor_source_ids.is_empty());
assert!(!sut.is_advanced_lock_enabled);
}
}
6 changes: 4 additions & 2 deletions src/profile/v100/profile_uniffi_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,10 @@ mod uniffi_tests {

#[test]
fn to_string_and_debug_string() {
assert_eq!(profile_to_string(&SUT::sample()).len(), 4798);
assert_eq!(profile_to_debug_string(&SUT::sample()).len(), 27619);
assert!(
profile_to_debug_string(&SUT::sample()).len()
> profile_to_string(&SUT::sample()).len()
);
assert_ne!(
profile_to_debug_string(&SUT::sample()),
profile_to_debug_string(&SUT::sample_other())
Expand Down

0 comments on commit d8d603b

Please sign in to comment.