FRAOathMechanismFactoryTests.m revision 7c51d54f23c5581d2cf894f9eafb9798e3febd22
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"
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 {
78c07714ec1113f7f21c75b818f2bf6a7021618aDiego Colantoni identityModel = [[FRAIdentityModel alloc] initWithDatabase:nil sqlDatabase:nil];
78c07714ec1113f7f21c75b818f2bf6a7021618aDiego Colantoni factory = [[FRAOathMechanismFactory alloc] init];
caa9e77dc369fea8df9ae2c598d3c83b7214c1cfDiego Colantoni NSURL *qrUrl = [NSURL URLWithString:@"otpauth://hotp/Forgerock:demo?secret=IJQWIZ3FOIQUEYLE&issuer=Forgerock&counter=0"];
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni FRAHotpOathMechanism *mechanism = (FRAHotpOathMechanism *)[factory buildMechanism:qrUrl database:nil 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"];
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni FRATotpOathMechanism *mechanism = (FRATotpOathMechanism *)[factory buildMechanism:qrUrl database:nil 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"];
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni FRAHotpOathMechanism *mechanism = (FRAHotpOathMechanism *)[factory buildMechanism:qrUrl database:nil 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"];
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni FRATotpOathMechanism *mechanism = (FRATotpOathMechanism *)[factory buildMechanism:qrUrl database:nil 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"];
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni FRAHotpOathMechanism *mechanism = (FRAHotpOathMechanism *)[factory buildMechanism:qrUrl database:nil identityModel:identityModel handler:nil error:nil];
caa9e77dc369fea8df9ae2c598d3c83b7214c1cfDiego Colantoni NSURL *qrUrl = [NSURL URLWithString:@"otpauth://totp/ForgeRock:demo?secret=EE3PFF5BM6GHVRNZIBBQWBNRLQ======&issuer=ForgeRock&digits=8&period=30"];
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni FRATotpOathMechanism *mechanism = (FRATotpOathMechanism *)[factory buildMechanism:qrUrl database:nil identityModel:identityModel handler:nil error:nil];
caa9e77dc369fea8df9ae2c598d3c83b7214c1cfDiego Colantoni NSURL *qrUrl = [NSURL URLWithString:@"otpauth://hotp/Forgerock:demo?secret=IJQWIZ3FOIQUEYLE&issuer=Forgerock&counter=12&digits=8"];
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni FRAHotpOathMechanism *mechanism = (FRAHotpOathMechanism *)[factory buildMechanism:qrUrl database:nil identityModel:identityModel handler:nil error:nil];
caa9e77dc369fea8df9ae2c598d3c83b7214c1cfDiego Colantoni NSURL *qrUrl = [NSURL URLWithString:@"otpauth://totp/ForgeRock:demo?secret=EE3PFF5BM6GHVRNZIBBQWBNRLQ======&issuer=ForgeRock&digits=8&period=30"];
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni FRATotpOathMechanism *mechanism = (FRATotpOathMechanism *)[factory buildMechanism:qrUrl database:nil 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"];
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni FRAHotpOathMechanism *mechanism = (FRAHotpOathMechanism *)[factory buildMechanism:qrUrl database:nil 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"];
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni FRATotpOathMechanism *mechanism = (FRATotpOathMechanism *)[factory buildMechanism:qrUrl database:nil 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];
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni FRAMechanism *duplicateMechanism = [factory buildMechanism:qrUrl database:nil identityModel:identityModel handler:nil error:&error];