Skip to content

Commit

Permalink
add Sample values for 'RoleWithFactorSourceIds'
Browse files Browse the repository at this point in the history
  • Loading branch information
CyonAlexRDX committed Nov 26, 2024
1 parent 40c173e commit 654995a
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 4 deletions.
6 changes: 3 additions & 3 deletions crates/rules/src/roles/abstract_role_builder_or_built.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize};
use crate::prelude::*;

#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct AbstractRoleBuilderOrBuilt<F, T> {
pub(crate) struct AbstractRoleBuilderOrBuilt<F, T> {
#[serde(skip)]
#[doc(hidden)]
built: PhantomData<T>,
Expand All @@ -15,8 +15,8 @@ pub struct AbstractRoleBuilderOrBuilt<F, T> {
override_factors: Vec<F>,
}

pub type AbstractBuiltRoleWithFactor<F> = AbstractRoleBuilderOrBuilt<F, ()>;
pub type RoleBuilder = AbstractRoleBuilderOrBuilt<FactorSourceID, RoleWithFactorSourceIds>;
pub(crate) type AbstractBuiltRoleWithFactor<F> = AbstractRoleBuilderOrBuilt<F, ()>;
pub(crate) type RoleBuilder = AbstractRoleBuilderOrBuilt<FactorSourceID, RoleWithFactorSourceIds>;

impl<F, T> AbstractRoleBuilderOrBuilt<F, T> {
pub(crate) fn with_factors(
Expand Down
2 changes: 1 addition & 1 deletion crates/rules/src/roles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ mod abstract_role_builder_or_built;
mod builder;
mod roles_with_factor_ids;

pub use abstract_role_builder_or_built::*;
pub(crate) use abstract_role_builder_or_built::*;
pub use builder::*;
pub use roles_with_factor_ids::*;
61 changes: 61 additions & 0 deletions crates/rules/src/roles/roles_with_factor_ids.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,64 @@
use sargon::HasSampleValues;

use crate::prelude::*;

pub type RoleWithFactorSourceIds = AbstractBuiltRoleWithFactor<FactorSourceID>;

impl RoleWithFactorSourceIds {
/// Config MFA 1.1
pub fn sample_primary() -> Self {
let mut builder = RoleBuilder::primary();
builder
.add_factor_source_to_list(FactorSourceID::sample_device(), FactorListKind::Threshold)
.unwrap();

builder
.add_factor_source_to_list(FactorSourceID::sample_ledger(), FactorListKind::Threshold)
.unwrap();
builder.set_threshold(2).unwrap();
builder.build().unwrap()
}

/// Config MFA 1.1
pub fn sample_recovery() -> Self {
let mut builder = RoleBuilder::recovery();
builder
.add_factor_source_to_list(FactorSourceID::sample_device(), FactorListKind::Override)
.unwrap();

builder
.add_factor_source_to_list(FactorSourceID::sample_ledger(), FactorListKind::Override)
.unwrap();
builder.build().unwrap()
}
}

impl HasSampleValues for RoleWithFactorSourceIds {
fn sample() -> Self {
Self::sample_primary()
}

fn sample_other() -> Self {
Self::sample_recovery()
}
}

#[cfg(test)]
mod tests {

use super::*;

#[allow(clippy::upper_case_acronyms)]
type SUT = RoleWithFactorSourceIds;

#[test]
fn equality() {
assert_eq!(SUT::sample(), SUT::sample());
assert_eq!(SUT::sample_other(), SUT::sample_other());
}

#[test]
fn inequality() {
assert_ne!(SUT::sample(), SUT::sample_other());
}
}

0 comments on commit 654995a

Please sign in to comment.