/*
* The contents of this file are subject to the terms of the Common Development and
* Distribution License (the License). You may not use this file except in compliance with the
* License.
*
* You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
* specific language governing permission and limitations under the License.
*
* When distributing Covered Software, include this CDDL Header Notice in each file and include
* the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
* Header, with the fields enclosed by brackets [] replaced by your own identifying
* information: "Portions copyright [year] [name of copyright owner]".
*
* Copyright 2016 ForgeRock AS.
*/
#import <OCMock/OCMock.h>
#import <XCTest/XCTest.h>
#import "FRAHotpOathMechanism.h"
#import "FRAIdentityDatabase.h"
#import "FRAIdentityDatabaseSQLiteOperations.h"
#import "FRAIdentityModel.h"
#import "FRAModelsFromDatabase.h"
#import "FRAOathCode.h"
#import "FRAOathMechanismFactory.h"
#import "FRAFMDatabaseConnectionHelper.h"
#import "FRAUriMechanismReader.h"
@interface FRAHotpOathMechanismTests : XCTestCase
@end
}
- (void)setUp {
[super setUp];
OCMStub([mockModelsFromDatabase allIdentitiesWithDatabase:[OCMArg any] identityDatabase:[OCMArg any] identityModel:[OCMArg any] error:[OCMArg anyObjectRef]]).andReturn(@[]);
OCMStub([mockSqlOperations insertIdentity:[OCMArg any] error:[OCMArg anyObjectRef]]).andReturn(YES);
OCMStub([mockSqlOperations insertMechanism:[OCMArg any] error:[OCMArg anyObjectRef]]).andReturn(YES);
OCMStub([mockSqlOperations updateMechanism:[OCMArg any] error:[OCMArg anyObjectRef]]).andReturn(YES);
// Factory used for parsing OATH URLs
}
- (void)tearDown {
[super tearDown];
}
- (void)testShouldGenerateNextCodeSequence {
// Given
NSString *qrString = @"otpauth://hotp/Forgerock:demo?secret=IJQWIZ3FOIQUEYLE&issuer=Forgerock&counter=0";
FRAHotpOathMechanism *mechanism = (FRAHotpOathMechanism *)[reader parseFromString:qrString handler:nil error:nil];
// When
// Then
}
- (void)testGenerateDifferentCodeSequence {
// Given
NSString *qrString = @"otpauth://hotp/Forgerock:demo?secret=IJQWIZ3FOI======&issuer=Forgerock&counter=0";
FRAHotpOathMechanism *mechanism = (FRAHotpOathMechanism *)[reader parseFromString:qrString handler:nil error:nil];
// When
// Then
}
// Given
NSString *qrString = @"otpauth://hotp/Forgerock:demo?secret=IJQWIZ3FOIQUEYLE&issuer=Forgerock&counter=0";
FRAHotpOathMechanism *mechanism = (FRAHotpOathMechanism *)[reader parseFromString:qrString handler:nil error:nil];
OCMStub([(FRAIdentityDatabaseSQLiteOperations *)mockSqlOperations insertMechanism:mechanism error:nil]).andReturn(YES);
// When
// Then
OCMVerify([(FRAIdentityDatabaseSQLiteOperations*)mockSqlOperations updateMechanism:mechanism error:nil]);
}
- (void)testBroadcastsOneChangeNotificationWhenHotpOathMechanismUpdateIsAutomaticallySavedToDatabase {
// Given
NSString *qrString = @"otpauth://hotp/Forgerock:demo?secret=IJQWIZ3FOIQUEYLE&issuer=Forgerock&counter=0";
FRAHotpOathMechanism *mechanism = (FRAHotpOathMechanism *)[reader parseFromString:qrString handler:nil error:nil];
OCMStub([(FRAIdentityDatabaseSQLiteOperations *)mockSqlOperations insertMechanism:mechanism error:nil]).andReturn(YES);
OCMStub([(FRAIdentityDatabaseSQLiteOperations *)mockSqlOperations updateMechanism:mechanism error:nil]).andReturn(YES);
[[NSNotificationCenter defaultCenter] addMockObserver:databaseObserverMock name:FRAIdentityDatabaseChangedNotification object:database];
[[databaseObserverMock expect] notificationWithName:FRAIdentityDatabaseChangedNotification object:database userInfo:[OCMArg any]];
// When
// Then
}
// Given
FRAIdentityDatabaseSQLiteOperations *sqlOperations = OCMClassMock([FRAIdentityDatabaseSQLiteOperations class]);
NSString *qrString = @"otpauth://hotp/Forgerock:demo?secret=IJQWIZ3FOI======&issuer=Forgerock&counter=0";
FRAHotpOathMechanism *mechanism = (FRAHotpOathMechanism *)[reader parseFromString:qrString handler:nil error:nil];
// When
// Then
}
@end