Skip to content

Commit

Permalink
fix swift test
Browse files Browse the repository at this point in the history
  • Loading branch information
CyonAlexRDX committed Dec 20, 2024
1 parent 4f6de0c commit f2e85f6
Showing 1 changed file with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ struct ShieldTests {
builder.addFactorSourceToPrimaryThreshold(factorSourceId: .sampleDevice)
builder.addFactorSourceToPrimaryThreshold(factorSourceId: .sampleDevice) // did not get added, duplicates are not allowed
#expect(builder.primaryRoleThresholdFactors == [.sampleDevice])
builder.addFactorSourceToPrimaryThreshold(factorSourceId: .sampleDeviceOther)
builder.addFactorSourceToPrimaryThreshold(factorSourceId: .sampleDeviceOther) // actually this is added
#expect(builder.validate() == .PrimaryCannotHaveMultipleDevices)
builder.removeFactorFromPrimary(factorSourceId: .sampleDeviceOther)

#expect(builder.validate() == .RecoveryRoleMustHaveAtLeastOneFactor)
builder.removeFactorFromPrimary(factorSourceId: .sampleDeviceOther)
Expand Down Expand Up @@ -139,22 +141,26 @@ struct ShieldTests {
#expect(builder.confirmationRoleFactors.isEmpty)
}

@Test("Primary can only contain one DeviceFactorSource")
@Test("Primary can contain two DeviceFactorSource while building - but is never valid")
func primaryCanOnlyContainOneDeviceFactorSourceThreshold() throws {
let builder = SecurityShieldBuilder()
let factor = FactorSourceId.sampleDevice
let other = FactorSourceId.sampleDeviceOther
builder.addFactorSourceToPrimaryThreshold(factorSourceId: factor)
builder.addFactorSourceToPrimaryOverride(factorSourceId: other)
#expect(builder.primaryRoleThresholdFactors == [factor])
#expect(builder.primaryRoleOverrideFactors == [])
#expect(builder.primaryRoleOverrideFactors == [other])

builder.removeFactorFromPrimary(factorSourceId: factor)

builder.addFactorSourceToPrimaryOverride(factorSourceId: factor)
builder.addFactorSourceToPrimaryThreshold(factorSourceId: other)
#expect(builder.primaryRoleThresholdFactors == [])
#expect(builder.primaryRoleOverrideFactors == [factor])
#expect(builder.primaryRoleThresholdFactors == [other])
#expect(builder.primaryRoleOverrideFactors == [other, factor])

// But when validated/built is err
#expect(builder.validate() != nil)
#expect((try? builder.build()) == nil)
}

@Test("Primary password never alone")
Expand All @@ -164,7 +170,8 @@ struct ShieldTests {
#expect(builder.primaryRoleOverrideFactors.isEmpty)

builder.addFactorSourceToPrimaryThreshold(factorSourceId: .samplePassword)
#expect(builder.validate() == .PrimaryRoleWithThresholdFactorsCannotHaveAThresholdValueOfZero)
#expect(builder.validate() == .PrimaryRoleWithPasswordInThresholdListMustHaveAnotherFactor)

builder.threshold = 0
#expect(builder.validate() == .PrimaryRoleWithThresholdFactorsCannotHaveAThresholdValueOfZero)
builder.threshold = 1
Expand Down

0 comments on commit f2e85f6

Please sign in to comment.