78c07714ec1113f7f21c75b818f2bf6a7021618aDiego Colantoni * The contents of this file are subject to the terms of the Common Development and
78c07714ec1113f7f21c75b818f2bf6a7021618aDiego Colantoni * Distribution License (the License). You may not use this file except in compliance with the
78c07714ec1113f7f21c75b818f2bf6a7021618aDiego Colantoni * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
78c07714ec1113f7f21c75b818f2bf6a7021618aDiego Colantoni * specific language governing permission and limitations under the License.
78c07714ec1113f7f21c75b818f2bf6a7021618aDiego Colantoni * When distributing Covered Software, include this CDDL Header Notice in each file and include
78c07714ec1113f7f21c75b818f2bf6a7021618aDiego Colantoni * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
78c07714ec1113f7f21c75b818f2bf6a7021618aDiego Colantoni * Header, with the fields enclosed by brackets [] replaced by your own identifying
78c07714ec1113f7f21c75b818f2bf6a7021618aDiego Colantoni * information: "Portions copyright [year] [name of copyright owner]".
78c07714ec1113f7f21c75b818f2bf6a7021618aDiego Colantoni * Copyright 2015-2016 ForgeRock AS.
78c07714ec1113f7f21c75b818f2bf6a7021618aDiego Colantoni#import "FRAError.h"
caa9e77dc369fea8df9ae2c598d3c83b7214c1cfDiego Colantoni#import "FRAHotpOathMechanism.h"
caa9e77dc369fea8df9ae2c598d3c83b7214c1cfDiego Colantoni#import "FRAIdentity.h"
caa9e77dc369fea8df9ae2c598d3c83b7214c1cfDiego Colantoni#import "FRAIdentityDatabase.h"
6a2ae9c7fb4d2c40d75cab0edaf940f22c18224fDiego Colantoni#import "FRAIdentityDatabaseSQLiteOperations.h"
6a2ae9c7fb4d2c40d75cab0edaf940f22c18224fDiego Colantoni#import "FRAModelsFromDatabase.h"
78c07714ec1113f7f21c75b818f2bf6a7021618aDiego Colantoni#import "FRAOathMechanismFactory.h"
caa9e77dc369fea8df9ae2c598d3c83b7214c1cfDiego Colantoni#import "FRATotpOathMechanism.h"
caa9e77dc369fea8df9ae2c598d3c83b7214c1cfDiego Colantoni#import "FRAUriMechanismReader.h"
caa9e77dc369fea8df9ae2c598d3c83b7214c1cfDiego Colantonistatic NSUInteger const DEFAULT_CODE_LENGTH = 6;
78c07714ec1113f7f21c75b818f2bf6a7021618aDiego Colantoni@interface FRAOathMechanismFactoryTests : XCTestCase
78c07714ec1113f7f21c75b818f2bf6a7021618aDiego Colantoni@implementation FRAOathMechanismFactoryTests {
6a2ae9c7fb4d2c40d75cab0edaf940f22c18224fDiego Colantoni mockModelsFromDatabase = OCMClassMock([FRAModelsFromDatabase class]);
6a2ae9c7fb4d2c40d75cab0edaf940f22c18224fDiego Colantoni OCMStub([mockModelsFromDatabase allIdentitiesWithDatabase:[OCMArg any] identityDatabase:[OCMArg any] identityModel:[OCMArg any] error:[OCMArg anyObjectRef]]).andReturn(@[]);
6a2ae9c7fb4d2c40d75cab0edaf940f22c18224fDiego Colantoni mockDatabaseOperations = OCMClassMock([FRAIdentityDatabaseSQLiteOperations class]);
6a2ae9c7fb4d2c40d75cab0edaf940f22c18224fDiego Colantoni OCMStub([mockDatabaseOperations insertIdentity:[OCMArg any] error:[OCMArg anyObjectRef]]).andReturn(YES);
6a2ae9c7fb4d2c40d75cab0edaf940f22c18224fDiego Colantoni OCMStub([mockDatabaseOperations insertMechanism:[OCMArg any] error:[OCMArg anyObjectRef]]).andReturn(YES);
6a2ae9c7fb4d2c40d75cab0edaf940f22c18224fDiego Colantoni identityDatabase = [[FRAIdentityDatabase alloc] initWithSqlOperations:mockDatabaseOperations];
6a2ae9c7fb4d2c40d75cab0edaf940f22c18224fDiego Colantoni identityModel = [[FRAIdentityModel alloc] initWithDatabase:identityDatabase sqlDatabase:nil];
78c07714ec1113f7f21c75b818f2bf6a7021618aDiego Colantoni factory = [[FRAOathMechanismFactory alloc] init];
caa9e77dc369fea8df9ae2c598d3c83b7214c1cfDiego Colantoni NSURL *qrUrl = [NSURL URLWithString:@"otpauth://hotp/Forgerock:demo?secret=IJQWIZ3FOIQUEYLE&issuer=Forgerock&counter=0"];
6a2ae9c7fb4d2c40d75cab0edaf940f22c18224fDiego Colantoni FRAHotpOathMechanism *mechanism = (FRAHotpOathMechanism *)[factory buildMechanism:qrUrl database:identityDatabase identityModel:identityModel handler:nil error:nil];
caa9e77dc369fea8df9ae2c598d3c83b7214c1cfDiego Colantoni XCTAssertEqualObjects([[mechanism class] mechanismType], @"hotp");
caa9e77dc369fea8df9ae2c598d3c83b7214c1cfDiego Colantoni NSURL *qrUrl = [NSURL URLWithString:@"otpauth://totp/ForgeRock:demo?secret=EE3PFF5BM6GHVRNZIBBQWBNRLQ======&issuer=ForgeRock&digits=6&period=30"];
6a2ae9c7fb4d2c40d75cab0edaf940f22c18224fDiego Colantoni FRATotpOathMechanism *mechanism = (FRATotpOathMechanism *)[factory buildMechanism:qrUrl database:identityDatabase identityModel:identityModel handler:nil error:nil];
caa9e77dc369fea8df9ae2c598d3c83b7214c1cfDiego Colantoni XCTAssertEqualObjects([[mechanism class] mechanismType], @"totp");
caa9e77dc369fea8df9ae2c598d3c83b7214c1cfDiego Colantoni NSURL *qrUrl = [NSURL URLWithString:@"otpauth://hotp/Forgerock:demo?secret=IJQWIZ3FOIQUEYLE&issuer=Forgerock&counter=0"];
6a2ae9c7fb4d2c40d75cab0edaf940f22c18224fDiego Colantoni FRAHotpOathMechanism *mechanism = (FRAHotpOathMechanism *)[factory buildMechanism:qrUrl database:identityDatabase identityModel:identityModel handler:nil error:nil];
caa9e77dc369fea8df9ae2c598d3c83b7214c1cfDiego Colantoni XCTAssertEqual(mechanism.codeLength, DEFAULT_CODE_LENGTH);
caa9e77dc369fea8df9ae2c598d3c83b7214c1cfDiego Colantoni NSURL *qrUrl = [NSURL URLWithString:@"otpauth://totp/ForgeRock:demo?secret=EE3PFF5BM6GHVRNZIBBQWBNRLQ======&issuer=ForgeRock&period=30"];
6a2ae9c7fb4d2c40d75cab0edaf940f22c18224fDiego Colantoni FRATotpOathMechanism *mechanism = (FRATotpOathMechanism *)[factory buildMechanism:qrUrl database:identityDatabase identityModel:identityModel handler:nil error:nil];
caa9e77dc369fea8df9ae2c598d3c83b7214c1cfDiego Colantoni XCTAssertEqual(mechanism.codeLength, DEFAULT_CODE_LENGTH);
caa9e77dc369fea8df9ae2c598d3c83b7214c1cfDiego Colantoni NSURL *qrUrl = [NSURL URLWithString:@"otpauth://hotp/Forgerock:demo?secret=IJQWIZ3FOIQUEYLE&issuer=Forgerock&counter=0&digits=8"];
6a2ae9c7fb4d2c40d75cab0edaf940f22c18224fDiego Colantoni FRAHotpOathMechanism *mechanism = (FRAHotpOathMechanism *)[factory buildMechanism:qrUrl database:identityDatabase identityModel:identityModel handler:nil error:nil];
caa9e77dc369fea8df9ae2c598d3c83b7214c1cfDiego Colantoni NSURL *qrUrl = [NSURL URLWithString:@"otpauth://totp/ForgeRock:demo?secret=EE3PFF5BM6GHVRNZIBBQWBNRLQ======&issuer=ForgeRock&digits=8&period=30"];
6a2ae9c7fb4d2c40d75cab0edaf940f22c18224fDiego Colantoni FRATotpOathMechanism *mechanism = (FRATotpOathMechanism *)[factory buildMechanism:qrUrl database:identityDatabase identityModel:identityModel handler:nil error:nil];
caa9e77dc369fea8df9ae2c598d3c83b7214c1cfDiego Colantoni NSURL *qrUrl = [NSURL URLWithString:@"otpauth://hotp/Forgerock:demo?secret=IJQWIZ3FOIQUEYLE&issuer=Forgerock&counter=12&digits=8"];
6a2ae9c7fb4d2c40d75cab0edaf940f22c18224fDiego Colantoni FRAHotpOathMechanism *mechanism = (FRAHotpOathMechanism *)[factory buildMechanism:qrUrl database:identityDatabase identityModel:identityModel handler:nil error:nil];
caa9e77dc369fea8df9ae2c598d3c83b7214c1cfDiego Colantoni NSURL *qrUrl = [NSURL URLWithString:@"otpauth://totp/ForgeRock:demo?secret=EE3PFF5BM6GHVRNZIBBQWBNRLQ======&issuer=ForgeRock&digits=8&period=30"];
6a2ae9c7fb4d2c40d75cab0edaf940f22c18224fDiego Colantoni FRATotpOathMechanism *mechanism = (FRATotpOathMechanism *)[factory buildMechanism:qrUrl database:identityDatabase identityModel:identityModel handler:nil error:nil];
caa9e77dc369fea8df9ae2c598d3c83b7214c1cfDiego Colantoni- (void)testParseParentIdentityIssuerAndAccountForHotpOathMechanism {
caa9e77dc369fea8df9ae2c598d3c83b7214c1cfDiego Colantoni NSURL *qrUrl = [NSURL URLWithString:@"otpauth://hotp/Forgerock:demo?secret=IJQWIZ3FOIQUEYLE&issuer=Forgerock&counter=0"];
6a2ae9c7fb4d2c40d75cab0edaf940f22c18224fDiego Colantoni FRAHotpOathMechanism *mechanism = (FRAHotpOathMechanism *)[factory buildMechanism:qrUrl database:identityDatabase identityModel:identityModel handler:nil error:nil];
caa9e77dc369fea8df9ae2c598d3c83b7214c1cfDiego Colantoni XCTAssertEqualObjects(identity.issuer, @"Forgerock");
caa9e77dc369fea8df9ae2c598d3c83b7214c1cfDiego Colantoni XCTAssertEqualObjects(identity.accountName, @"demo");
caa9e77dc369fea8df9ae2c598d3c83b7214c1cfDiego Colantoni- (void)testParseParentIdentityIssuerAndAccountForTotpOathMechanism {
caa9e77dc369fea8df9ae2c598d3c83b7214c1cfDiego Colantoni NSURL *qrUrl = [NSURL URLWithString:@"otpauth://totp/Forgerock:demo?secret=EE3PFF5BM6GHVRNZIBBQWBNRLQ======&issuer=ForgeRock&digits=8&period=30"];
6a2ae9c7fb4d2c40d75cab0edaf940f22c18224fDiego Colantoni FRATotpOathMechanism *mechanism = (FRATotpOathMechanism *)[factory buildMechanism:qrUrl database:identityDatabase identityModel:identityModel handler:nil error:nil];
caa9e77dc369fea8df9ae2c598d3c83b7214c1cfDiego Colantoni XCTAssertEqualObjects(identity.issuer, @"Forgerock");
caa9e77dc369fea8df9ae2c598d3c83b7214c1cfDiego Colantoni XCTAssertEqualObjects(identity.accountName, @"demo");
78c07714ec1113f7f21c75b818f2bf6a7021618aDiego Colantoni- (void)testBuildMechanismReturnsNilIfDuplicate {
78c07714ec1113f7f21c75b818f2bf6a7021618aDiego Colantoni NSURL *qrUrl = [NSURL URLWithString:@"otpauth://hotp/Forgerock:demo?secret=IJQWIZ3FOIQUEYLE&issuer=Forgerock&counter=0&digits=8"];
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni [factory buildMechanism:qrUrl database:nil identityModel:identityModel handler:nil error:nil];
6a2ae9c7fb4d2c40d75cab0edaf940f22c18224fDiego Colantoni FRAMechanism *duplicateMechanism = [factory buildMechanism:qrUrl database:identityDatabase identityModel:identityModel handler:nil error:&error];
78c07714ec1113f7f21c75b818f2bf6a7021618aDiego Colantoni XCTAssertEqual(error.code, FRADuplicateMechanism);
a850458f12111fdb478ff7da50d92dfb63f7d8c4Diego Colantoni- (void)testBuildMechanismReturnsNilIfNoSecretForHotp {
6a2ae9c7fb4d2c40d75cab0edaf940f22c18224fDiego Colantoni NSURL *qrUrl = [NSURL URLWithString:@"otpauth://hotp/Forgerock:demo?secret=&issuer=Forgerock&counter=0&digits=8"];
6a2ae9c7fb4d2c40d75cab0edaf940f22c18224fDiego Colantoni FRAMechanism *mechanism = [factory buildMechanism:qrUrl database:identityDatabase identityModel:identityModel handler:nil error:&error];
6a2ae9c7fb4d2c40d75cab0edaf940f22c18224fDiego Colantoni XCTAssertEqual(error.code, FRAInvalidQRCode);
a850458f12111fdb478ff7da50d92dfb63f7d8c4Diego Colantoni- (void)testBuildMechanismReturnsNilIfNoSecretForTotp {
a850458f12111fdb478ff7da50d92dfb63f7d8c4Diego Colantoni NSURL *qrUrl = [NSURL URLWithString:@"otpauth://totp/Forgerock:demo?secret=&issuer=Forgerock&period=30&digits=8"];
6a2ae9c7fb4d2c40d75cab0edaf940f22c18224fDiego Colantoni FRAMechanism *mechanism = [factory buildMechanism:qrUrl database:identityDatabase identityModel:identityModel handler:nil error:&error];
6a2ae9c7fb4d2c40d75cab0edaf940f22c18224fDiego Colantoni XCTAssertEqual(error.code, FRAInvalidQRCode);
a850458f12111fdb478ff7da50d92dfb63f7d8c4Diego Colantoni- (void)testBuildMechanismReturnsIssuerFromParameter {
a850458f12111fdb478ff7da50d92dfb63f7d8c4Diego Colantoni NSURL *qrUrl = [NSURL URLWithString:@"otpauth://hotp/demo?secret=IJQWIZ3FOIQUEYLE&issuer=Forgerock&counter=0&digits=8"];
6a2ae9c7fb4d2c40d75cab0edaf940f22c18224fDiego Colantoni FRAMechanism *mechanism = [factory buildMechanism:qrUrl database:identityDatabase identityModel:identityModel handler:nil error:&error];
a850458f12111fdb478ff7da50d92dfb63f7d8c4Diego Colantoni XCTAssertEqualObjects(identity.issuer, @"Forgerock");
a850458f12111fdb478ff7da50d92dfb63f7d8c4Diego Colantoni XCTAssertEqualObjects(identity.accountName, @"demo");
a850458f12111fdb478ff7da50d92dfb63f7d8c4Diego Colantoni- (void)testBuildMechanismWithNoIssuerSetsIssuerToAccountName {
a850458f12111fdb478ff7da50d92dfb63f7d8c4Diego Colantoni NSURL *qrUrl = [NSURL URLWithString:@"otpauth://hotp/Forgerock?secret=IJQWIZ3FOIQUEYLE&counter=0&digits=8"];
a850458f12111fdb478ff7da50d92dfb63f7d8c4Diego Colantoni FRAMechanism *mechanism = [factory buildMechanism:qrUrl database:identityDatabase identityModel:identityModel handler:nil error:&error];
a850458f12111fdb478ff7da50d92dfb63f7d8c4Diego Colantoni XCTAssertEqualObjects(identity.issuer, @"Forgerock");
a850458f12111fdb478ff7da50d92dfb63f7d8c4Diego Colantoni XCTAssertEqualObjects(identity.accountName, @"Forgerock");
6a2ae9c7fb4d2c40d75cab0edaf940f22c18224fDiego Colantoni- (void)testBuildMechanismReturnsNilIfTypeIsMissing {
6a2ae9c7fb4d2c40d75cab0edaf940f22c18224fDiego Colantoni NSURL *qrUrl = [NSURL URLWithString:@"otpauth:///Forgerock:demo?secret=IJQWIZ3FOIQUEYLE&issuer=Forgerock&counter=0&digits=8"];
6a2ae9c7fb4d2c40d75cab0edaf940f22c18224fDiego Colantoni FRAMechanism *mechanism = [factory buildMechanism:qrUrl database:identityDatabase identityModel:identityModel handler:nil error:&error];
6a2ae9c7fb4d2c40d75cab0edaf940f22c18224fDiego Colantoni XCTAssertEqual(error.code, FRAInvalidQRCode);
a850458f12111fdb478ff7da50d92dfb63f7d8c4Diego Colantoni- (void)testBuildMechanismReturnsNilIfNoCounterForHotp {
a850458f12111fdb478ff7da50d92dfb63f7d8c4Diego Colantoni NSURL *qrUrl = [NSURL URLWithString:@"otpauth://hotp/Forgerock:demo?secret=IJQWIZ3FOIQUEYLE&issuer=Forgerock&digits=8"];
a850458f12111fdb478ff7da50d92dfb63f7d8c4Diego Colantoni FRAMechanism *mechanism = [factory buildMechanism:qrUrl database:identityDatabase identityModel:identityModel handler:nil error:&error];
a850458f12111fdb478ff7da50d92dfb63f7d8c4Diego Colantoni XCTAssertEqual(error.code, FRAInvalidQRCode);
a850458f12111fdb478ff7da50d92dfb63f7d8c4Diego Colantoni- (void)testBuildMechanismReturnsNilIfInvalidCounterForHotp {
a850458f12111fdb478ff7da50d92dfb63f7d8c4Diego Colantoni NSURL *qrUrl = [NSURL URLWithString:@"otpauth://hotp/Forgerock:demo?secret=IJQWIZ3FOIQUEYLE&issuer=Forgerock&digits=8&counter=invalid"];
a850458f12111fdb478ff7da50d92dfb63f7d8c4Diego Colantoni FRAMechanism *mechanism = [factory buildMechanism:qrUrl database:identityDatabase identityModel:identityModel handler:nil error:&error];
a850458f12111fdb478ff7da50d92dfb63f7d8c4Diego Colantoni XCTAssertEqual(error.code, FRAInvalidQRCode);
a850458f12111fdb478ff7da50d92dfb63f7d8c4Diego Colantoni- (void)testBuildMechanismReturnsNilIfInvalidPeriodForTotp {
a850458f12111fdb478ff7da50d92dfb63f7d8c4Diego Colantoni NSURL *qrUrl = [NSURL URLWithString:@"otpauth://totp/Forgerock:demo?secret=IJQWIZ3FOIQUEYLE&issuer=Forgerock&digits=8&period=invalid"];
a850458f12111fdb478ff7da50d92dfb63f7d8c4Diego Colantoni FRAMechanism *mechanism = [factory buildMechanism:qrUrl database:identityDatabase identityModel:identityModel handler:nil error:&error];
a850458f12111fdb478ff7da50d92dfb63f7d8c4Diego Colantoni XCTAssertEqual(error.code, FRAInvalidQRCode);
a850458f12111fdb478ff7da50d92dfb63f7d8c4Diego Colantoni- (void)testBuildMechanismReturnsNilIfInvalidAlgorithm {
a850458f12111fdb478ff7da50d92dfb63f7d8c4Diego Colantoni NSURL *qrUrl = [NSURL URLWithString:@"otpauth://hotp/WeightWatchers:Dave?secret=JMEZ2W7D462P3JYBDG2HV7PFBM======&issuer=WeightWatchers&digits=8&algorithm=SHA%20256&counter=0&b=FF00FF&image=http://www.utimes.pitt.edu/wp-content/uploads/2013/01/ww-logo1.jpg"];
a850458f12111fdb478ff7da50d92dfb63f7d8c4Diego Colantoni FRAMechanism *mechanism = [factory buildMechanism:qrUrl database:identityDatabase identityModel:identityModel handler:nil error:&error];
a850458f12111fdb478ff7da50d92dfb63f7d8c4Diego Colantoni XCTAssertEqual(error.code, FRAInvalidQRCode);
a850458f12111fdb478ff7da50d92dfb63f7d8c4Diego Colantoni- (void)testBuildMechanismReturnsNilIfInvalidDigits {
a850458f12111fdb478ff7da50d92dfb63f7d8c4Diego Colantoni NSURL *qrUrl = [NSURL URLWithString:@"otpauth://hotp/WeightWatchers:Dave?secret=JMEZ2W7D462P3JYBDG2HV7PFBM======&issuer=WeightWatchers&digits=9&algorithm=SHA1&period=60&b=FF00FF&image=http://www.utimes.pitt.edu/wp-content/uploads/2013/01/ww-logo1.jpg&counter=0"];
a850458f12111fdb478ff7da50d92dfb63f7d8c4Diego Colantoni FRAMechanism *mechanism = [factory buildMechanism:qrUrl database:identityDatabase identityModel:identityModel handler:nil error:&error];
a850458f12111fdb478ff7da50d92dfb63f7d8c4Diego Colantoni XCTAssertEqual(error.code, FRAInvalidQRCode);
a850458f12111fdb478ff7da50d92dfb63f7d8c4Diego Colantoni- (void)testBuildMechanismReturnsNilIfInvalidBackgroundColor {
a850458f12111fdb478ff7da50d92dfb63f7d8c4Diego Colantoni NSURL *qrUrl = [NSURL URLWithString:@"otpauth://hotp/WeightWatchers:Dave?secret=JMEZ2W7D462P3JYBDG2HV7PFBM======&issuer=WeightWatchers&digits=6&algorithm=SHA1&b=FF0Z0FF&image=http://www.utimes.pitt.edu/wp-content/uploads/2013/01/ww-logo1.jpg&counter=0"];
a850458f12111fdb478ff7da50d92dfb63f7d8c4Diego Colantoni FRAMechanism *mechanism = [factory buildMechanism:qrUrl database:identityDatabase identityModel:identityModel handler:nil error:&error];
a850458f12111fdb478ff7da50d92dfb63f7d8c4Diego Colantoni XCTAssertEqual(error.code, FRAInvalidQRCode);
6a2ae9c7fb4d2c40d75cab0edaf940f22c18224fDiego Colantoni- (void)testBuildMechanismReturnsNilIfTypeIsNotSupported {
6a2ae9c7fb4d2c40d75cab0edaf940f22c18224fDiego Colantoni NSURL *qrUrl = [NSURL URLWithString:@"otpauth://anyotp/Forgerock:demo?secret=IJQWIZ3FOIQUEYLE&issuer=Forgerock&counter=0&digits=8"];
6a2ae9c7fb4d2c40d75cab0edaf940f22c18224fDiego Colantoni FRAMechanism *mechanism = [factory buildMechanism:qrUrl database:identityDatabase identityModel:identityModel handler:nil error:&error];
6a2ae9c7fb4d2c40d75cab0edaf940f22c18224fDiego Colantoni XCTAssertEqual(error.code, FRAInvalidQRCode);
6a2ae9c7fb4d2c40d75cab0edaf940f22c18224fDiego Colantoni- (void)testBuildMechanismReturnsNilIfCantSaveIdentityInDatabase {
6a2ae9c7fb4d2c40d75cab0edaf940f22c18224fDiego Colantoni NSURL *qrUrl = [NSURL URLWithString:@"otpauth://totp/ForgeRock:demo?secret=EE3PFF5BM6GHVRNZIBBQWBNRLQ======&issuer=ForgeRock&digits=8&period=30"];
6a2ae9c7fb4d2c40d75cab0edaf940f22c18224fDiego Colantoni FRAIdentityDatabaseSQLiteOperations *databaseOperations = OCMClassMock([FRAIdentityDatabaseSQLiteOperations class]);
6a2ae9c7fb4d2c40d75cab0edaf940f22c18224fDiego Colantoni OCMStub([databaseOperations insertIdentity:[OCMArg any] error:[OCMArg anyObjectRef]]).andReturn(NO);
6a2ae9c7fb4d2c40d75cab0edaf940f22c18224fDiego Colantoni identityDatabase = [[FRAIdentityDatabase alloc] initWithSqlOperations:databaseOperations];
6a2ae9c7fb4d2c40d75cab0edaf940f22c18224fDiego Colantoni identityModel = [[FRAIdentityModel alloc] initWithDatabase:identityDatabase sqlDatabase:nil];
6a2ae9c7fb4d2c40d75cab0edaf940f22c18224fDiego Colantoni FRAMechanism *mechanism = [factory buildMechanism:qrUrl database:identityDatabase identityModel:identityModel handler:nil error:&error];
6a2ae9c7fb4d2c40d75cab0edaf940f22c18224fDiego Colantoni- (void)testBuildMechanismReturnsNilIfCantSaveMechanismInDatabase {
6a2ae9c7fb4d2c40d75cab0edaf940f22c18224fDiego Colantoni NSURL *qrUrl = [NSURL URLWithString:@"otpauth://totp/ForgeRock:demo?secret=EE3PFF5BM6GHVRNZIBBQWBNRLQ======&issuer=ForgeRock&digits=8&period=30"];
6a2ae9c7fb4d2c40d75cab0edaf940f22c18224fDiego Colantoni FRAIdentityDatabaseSQLiteOperations *databaseOperations = OCMClassMock([FRAIdentityDatabaseSQLiteOperations class]);
6a2ae9c7fb4d2c40d75cab0edaf940f22c18224fDiego Colantoni OCMStub([databaseOperations insertIdentity:[OCMArg any] error:[OCMArg anyObjectRef]]).andReturn(YES);
6a2ae9c7fb4d2c40d75cab0edaf940f22c18224fDiego Colantoni OCMStub([databaseOperations insertMechanism:[OCMArg any] error:[OCMArg anyObjectRef]]).andReturn(NO);
6a2ae9c7fb4d2c40d75cab0edaf940f22c18224fDiego Colantoni identityDatabase = [[FRAIdentityDatabase alloc] initWithSqlOperations:databaseOperations];
6a2ae9c7fb4d2c40d75cab0edaf940f22c18224fDiego Colantoni identityModel = [[FRAIdentityModel alloc] initWithDatabase:identityDatabase sqlDatabase:nil];