ff2edace1e77f0e80bc2f5da30344d21c3274885Craig McDonnell/*
ff2edace1e77f0e80bc2f5da30344d21c3274885Craig McDonnell * The contents of this file are subject to the terms of the Common Development and
ff2edace1e77f0e80bc2f5da30344d21c3274885Craig McDonnell * Distribution License (the License). You may not use this file except in compliance with the
ff2edace1e77f0e80bc2f5da30344d21c3274885Craig McDonnell * License.
ff2edace1e77f0e80bc2f5da30344d21c3274885Craig McDonnell *
ff2edace1e77f0e80bc2f5da30344d21c3274885Craig McDonnell * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
ff2edace1e77f0e80bc2f5da30344d21c3274885Craig McDonnell * specific language governing permission and limitations under the License.
ff2edace1e77f0e80bc2f5da30344d21c3274885Craig McDonnell *
ff2edace1e77f0e80bc2f5da30344d21c3274885Craig McDonnell * When distributing Covered Software, include this CDDL Header Notice in each file and include
ff2edace1e77f0e80bc2f5da30344d21c3274885Craig McDonnell * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
ff2edace1e77f0e80bc2f5da30344d21c3274885Craig McDonnell * Header, with the fields enclosed by brackets [] replaced by your own identifying
ff2edace1e77f0e80bc2f5da30344d21c3274885Craig McDonnell * information: "Portions copyright [year] [name of copyright owner]".
ff2edace1e77f0e80bc2f5da30344d21c3274885Craig McDonnell *
ff2edace1e77f0e80bc2f5da30344d21c3274885Craig McDonnell * Copyright 2016 ForgeRock AS.
ff2edace1e77f0e80bc2f5da30344d21c3274885Craig McDonnell */
ff2edace1e77f0e80bc2f5da30344d21c3274885Craig McDonnell
6a2ae9c7fb4d2c40d75cab0edaf940f22c18224fDiego Colantoni#import <OCMock/OCMock.h>
6a2ae9c7fb4d2c40d75cab0edaf940f22c18224fDiego Colantoni
ff2edace1e77f0e80bc2f5da30344d21c3274885Craig McDonnell#import "FRAHotpOathMechanism.h"
6a2ae9c7fb4d2c40d75cab0edaf940f22c18224fDiego Colantoni#import "FRAIdentityDatabase.h"
6a2ae9c7fb4d2c40d75cab0edaf940f22c18224fDiego Colantoni#import "FRAIdentityDatabaseSQLiteOperations.h"
6a2ae9c7fb4d2c40d75cab0edaf940f22c18224fDiego Colantoni#import "FRAIdentityModel.h"
ff2edace1e77f0e80bc2f5da30344d21c3274885Craig McDonnell#import "FRAModelUtils.h"
ff2edace1e77f0e80bc2f5da30344d21c3274885Craig McDonnell#import "FRAOathMechanismFactory.h"
ff2edace1e77f0e80bc2f5da30344d21c3274885Craig McDonnell#import "FRAUriMechanismReader.h"
ff2edace1e77f0e80bc2f5da30344d21c3274885Craig McDonnell
ff2edace1e77f0e80bc2f5da30344d21c3274885Craig McDonnell@implementation FRAModelUtils {
ff2edace1e77f0e80bc2f5da30344d21c3274885Craig McDonnell FRAUriMechanismReader *reader;
ff2edace1e77f0e80bc2f5da30344d21c3274885Craig McDonnell}
ff2edace1e77f0e80bc2f5da30344d21c3274885Craig McDonnell
ff2edace1e77f0e80bc2f5da30344d21c3274885Craig McDonnell- (instancetype)init {
ff2edace1e77f0e80bc2f5da30344d21c3274885Craig McDonnell self = [super init];
ff2edace1e77f0e80bc2f5da30344d21c3274885Craig McDonnell if (self) {
6a2ae9c7fb4d2c40d75cab0edaf940f22c18224fDiego Colantoni id 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 FRAIdentityDatabase *identityDatabase = [[FRAIdentityDatabase alloc] initWithSqlOperations:mockDatabaseOperations];
6a2ae9c7fb4d2c40d75cab0edaf940f22c18224fDiego Colantoni FRAIdentityModel *identityModel = [[FRAIdentityModel alloc] initWithDatabase:identityDatabase sqlDatabase:nil];
6a2ae9c7fb4d2c40d75cab0edaf940f22c18224fDiego Colantoni reader = [[FRAUriMechanismReader alloc] initWithDatabase:identityDatabase identityModel:identityModel];
ff2edace1e77f0e80bc2f5da30344d21c3274885Craig McDonnell [reader addMechanismFactory:[[FRAOathMechanismFactory alloc] init]];
ff2edace1e77f0e80bc2f5da30344d21c3274885Craig McDonnell }
ff2edace1e77f0e80bc2f5da30344d21c3274885Craig McDonnell return self;
ff2edace1e77f0e80bc2f5da30344d21c3274885Craig McDonnell}
ff2edace1e77f0e80bc2f5da30344d21c3274885Craig McDonnell
ff2edace1e77f0e80bc2f5da30344d21c3274885Craig McDonnell- (FRAHotpOathMechanism *)demoOathMechanism {
ff2edace1e77f0e80bc2f5da30344d21c3274885Craig McDonnell NSString *qrString = @"otpauth://hotp/Forgerock:demo?secret=IJQWIZ3FOIQUEYLE&issuer=Forgerock&counter=0";
8b25768d928719c0be765c8d31f7073721be550aDiego Colantoni return (FRAHotpOathMechanism *)[reader parseFromString:qrString handler:nil error:nil];
ff2edace1e77f0e80bc2f5da30344d21c3274885Craig McDonnell}
ff2edace1e77f0e80bc2f5da30344d21c3274885Craig McDonnell
ff2edace1e77f0e80bc2f5da30344d21c3274885Craig McDonnell@end