/*
* 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 2015-2016 ForgeRock AS.
*/
#import <XCTest/XCTest.h>
#import <OCMock/OCMock.h>
#import "FRAError.h"
#import "FRAHotpOathMechanism.h"
#import "FRAIdentity.h"
#import "FRAIdentityDatabase.h"
#import "FRAIdentityDatabaseSQLiteOperations.h"
#import "FRAModelsFromDatabase.h"
#import "FRAOathMechanismFactory.h"
#import "FRATotpOathMechanism.h"
#import "FRAUriMechanismReader.h"
@interface FRAOathMechanismFactoryTests : XCTestCase
@end
}
- (void)setUp {
[super setUp];
OCMStub([mockModelsFromDatabase allIdentitiesWithDatabase:[OCMArg any] identityDatabase:[OCMArg any] identityModel:[OCMArg any] error:[OCMArg anyObjectRef]]).andReturn(@[]);
OCMStub([mockDatabaseOperations insertIdentity:[OCMArg any] error:[OCMArg anyObjectRef]]).andReturn(YES);
OCMStub([mockDatabaseOperations insertMechanism:[OCMArg any] error:[OCMArg anyObjectRef]]).andReturn(YES);
}
- (void)tearDown {
[super tearDown];
}
- (void)testParseHotpOathType {
// Given
NSURL *qrUrl = [NSURL URLWithString:@"otpauth://hotp/Forgerock:demo?secret=IJQWIZ3FOIQUEYLE&issuer=Forgerock&counter=0"];
// When
FRAHotpOathMechanism *mechanism = (FRAHotpOathMechanism *)[factory buildMechanism:qrUrl database:identityDatabase identityModel:identityModel handler:nil error:nil];
// Then
}
- (void)testParseTotpOathType {
// Given
NSURL *qrUrl = [NSURL URLWithString:@"otpauth://totp/ForgeRock:demo?secret=EE3PFF5BM6GHVRNZIBBQWBNRLQ======&issuer=ForgeRock&digits=6&period=30"];
// When
FRATotpOathMechanism *mechanism = (FRATotpOathMechanism *)[factory buildMechanism:qrUrl database:identityDatabase identityModel:identityModel handler:nil error:nil];
// Then
}
- (void)testParseHotpOathDefaultCodeLength {
// Given
NSURL *qrUrl = [NSURL URLWithString:@"otpauth://hotp/Forgerock:demo?secret=IJQWIZ3FOIQUEYLE&issuer=Forgerock&counter=0"];
// When
FRAHotpOathMechanism *mechanism = (FRAHotpOathMechanism *)[factory buildMechanism:qrUrl database:identityDatabase identityModel:identityModel handler:nil error:nil];
// Then
}
- (void)testParseTotpOathDefaultCodeLength {
// Given
NSURL *qrUrl = [NSURL URLWithString:@"otpauth://totp/ForgeRock:demo?secret=EE3PFF5BM6GHVRNZIBBQWBNRLQ======&issuer=ForgeRock&period=30"];
// When
FRATotpOathMechanism *mechanism = (FRATotpOathMechanism *)[factory buildMechanism:qrUrl database:identityDatabase identityModel:identityModel handler:nil error:nil];
// Then
}
- (void)testParseHotpOathCodeLength {
// Given
NSURL *qrUrl = [NSURL URLWithString:@"otpauth://hotp/Forgerock:demo?secret=IJQWIZ3FOIQUEYLE&issuer=Forgerock&counter=0&digits=8"];
// When
FRAHotpOathMechanism *mechanism = (FRAHotpOathMechanism *)[factory buildMechanism:qrUrl database:identityDatabase identityModel:identityModel handler:nil error:nil];
// Then
}
- (void)testParseTotpOathCodeLength {
// Given
NSURL *qrUrl = [NSURL URLWithString:@"otpauth://totp/ForgeRock:demo?secret=EE3PFF5BM6GHVRNZIBBQWBNRLQ======&issuer=ForgeRock&digits=8&period=30"];
// When
FRATotpOathMechanism *mechanism = (FRATotpOathMechanism *)[factory buildMechanism:qrUrl database:identityDatabase identityModel:identityModel handler:nil error:nil];
// Then
}
- (void)testParseHotpOathCounter {
// Given
NSURL *qrUrl = [NSURL URLWithString:@"otpauth://hotp/Forgerock:demo?secret=IJQWIZ3FOIQUEYLE&issuer=Forgerock&counter=12&digits=8"];
// When
FRAHotpOathMechanism *mechanism = (FRAHotpOathMechanism *)[factory buildMechanism:qrUrl database:identityDatabase identityModel:identityModel handler:nil error:nil];
// Then
}
- (void)testParseTotpOathPeriod {
// Given
NSURL *qrUrl = [NSURL URLWithString:@"otpauth://totp/ForgeRock:demo?secret=EE3PFF5BM6GHVRNZIBBQWBNRLQ======&issuer=ForgeRock&digits=8&period=30"];
// When
FRATotpOathMechanism *mechanism = (FRATotpOathMechanism *)[factory buildMechanism:qrUrl database:identityDatabase identityModel:identityModel handler:nil error:nil];
// Then
}
// Given
NSURL *qrUrl = [NSURL URLWithString:@"otpauth://hotp/Forgerock:demo?secret=IJQWIZ3FOIQUEYLE&issuer=Forgerock&counter=0"];
// When
FRAHotpOathMechanism *mechanism = (FRAHotpOathMechanism *)[factory buildMechanism:qrUrl database:identityDatabase identityModel:identityModel handler:nil error:nil];
// Then
}
// Given
NSURL *qrUrl = [NSURL URLWithString:@"otpauth://totp/Forgerock:demo?secret=EE3PFF5BM6GHVRNZIBBQWBNRLQ======&issuer=ForgeRock&digits=8&period=30"];
// When
FRATotpOathMechanism *mechanism = (FRATotpOathMechanism *)[factory buildMechanism:qrUrl database:identityDatabase identityModel:identityModel handler:nil error:nil];
// Then
}
- (void)testBuildMechanismReturnsNilIfDuplicate {
// Given
NSURL *qrUrl = [NSURL URLWithString:@"otpauth://hotp/Forgerock:demo?secret=IJQWIZ3FOIQUEYLE&issuer=Forgerock&counter=0&digits=8"];
// When
FRAMechanism *duplicateMechanism = [factory buildMechanism:qrUrl database:identityDatabase identityModel:identityModel handler:nil error:&error];
// Then
}
// Given
NSURL *qrUrl = [NSURL URLWithString:@"otpauth://hotp/Forgerock:demo?secret=&issuer=Forgerock&counter=0&digits=8"];
// When
FRAMechanism *mechanism = [factory buildMechanism:qrUrl database:identityDatabase identityModel:identityModel handler:nil error:&error];
}
// Given
NSURL *qrUrl = [NSURL URLWithString:@"otpauth://totp/Forgerock:demo?secret=&issuer=Forgerock&period=30&digits=8"];
// When
FRAMechanism *mechanism = [factory buildMechanism:qrUrl database:identityDatabase identityModel:identityModel handler:nil error:&error];
}
// Given
NSURL *qrUrl = [NSURL URLWithString:@"otpauth://hotp/demo?secret=IJQWIZ3FOIQUEYLE&issuer=Forgerock&counter=0&digits=8"];
// When
FRAMechanism *mechanism = [factory buildMechanism:qrUrl database:identityDatabase identityModel:identityModel handler:nil error:&error];
}
// Given
NSURL *qrUrl = [NSURL URLWithString:@"otpauth://hotp/Forgerock?secret=IJQWIZ3FOIQUEYLE&counter=0&digits=8"];
// When
FRAMechanism *mechanism = [factory buildMechanism:qrUrl database:identityDatabase identityModel:identityModel handler:nil error:&error];
}
// Given
NSURL *qrUrl = [NSURL URLWithString:@"otpauth:///Forgerock:demo?secret=IJQWIZ3FOIQUEYLE&issuer=Forgerock&counter=0&digits=8"];
// When
FRAMechanism *mechanism = [factory buildMechanism:qrUrl database:identityDatabase identityModel:identityModel handler:nil error:&error];
}
// Given
NSURL *qrUrl = [NSURL URLWithString:@"otpauth://hotp/Forgerock:demo?secret=IJQWIZ3FOIQUEYLE&issuer=Forgerock&digits=8"];
// When
FRAMechanism *mechanism = [factory buildMechanism:qrUrl database:identityDatabase identityModel:identityModel handler:nil error:&error];
}
// Given
NSURL *qrUrl = [NSURL URLWithString:@"otpauth://hotp/Forgerock:demo?secret=IJQWIZ3FOIQUEYLE&issuer=Forgerock&digits=8&counter=invalid"];
// When
FRAMechanism *mechanism = [factory buildMechanism:qrUrl database:identityDatabase identityModel:identityModel handler:nil error:&error];
}
// Given
NSURL *qrUrl = [NSURL URLWithString:@"otpauth://totp/Forgerock:demo?secret=IJQWIZ3FOIQUEYLE&issuer=Forgerock&digits=8&period=invalid"];
// When
FRAMechanism *mechanism = [factory buildMechanism:qrUrl database:identityDatabase identityModel:identityModel handler:nil error:&error];
}
// Given
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"];
// When
FRAMechanism *mechanism = [factory buildMechanism:qrUrl database:identityDatabase identityModel:identityModel handler:nil error:&error];
}
// Given
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"];
// When
FRAMechanism *mechanism = [factory buildMechanism:qrUrl database:identityDatabase identityModel:identityModel handler:nil error:&error];
}
// Given
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"];
// When
FRAMechanism *mechanism = [factory buildMechanism:qrUrl database:identityDatabase identityModel:identityModel handler:nil error:&error];
}
// Given
NSURL *qrUrl = [NSURL URLWithString:@"otpauth://anyotp/Forgerock:demo?secret=IJQWIZ3FOIQUEYLE&issuer=Forgerock&counter=0&digits=8"];
// When
FRAMechanism *mechanism = [factory buildMechanism:qrUrl database:identityDatabase identityModel:identityModel handler:nil error:&error];
}
// Given
NSURL *qrUrl = [NSURL URLWithString:@"otpauth://totp/ForgeRock:demo?secret=EE3PFF5BM6GHVRNZIBBQWBNRLQ======&issuer=ForgeRock&digits=8&period=30"];
FRAIdentityDatabaseSQLiteOperations *databaseOperations = OCMClassMock([FRAIdentityDatabaseSQLiteOperations class]);
OCMStub([databaseOperations insertIdentity:[OCMArg any] error:[OCMArg anyObjectRef]]).andReturn(NO);
// When
FRAMechanism *mechanism = [factory buildMechanism:qrUrl database:identityDatabase identityModel:identityModel handler:nil error:&error];
}
// Given
NSURL *qrUrl = [NSURL URLWithString:@"otpauth://totp/ForgeRock:demo?secret=EE3PFF5BM6GHVRNZIBBQWBNRLQ======&issuer=ForgeRock&digits=8&period=30"];
FRAIdentityDatabaseSQLiteOperations *databaseOperations = OCMClassMock([FRAIdentityDatabaseSQLiteOperations class]);
OCMStub([databaseOperations insertIdentity:[OCMArg any] error:[OCMArg anyObjectRef]]).andReturn(YES);
OCMStub([databaseOperations insertMechanism:[OCMArg any] error:[OCMArg anyObjectRef]]).andReturn(NO);
// When
FRAMechanism *mechanism = [factory buildMechanism:qrUrl database:identityDatabase identityModel:identityModel handler:nil error:&error];
}
@end