/*
* 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 "FRAerror.h"
#import "FRAHotpOathMechanism.h"
#import "FRAIdentity.h"
#import "FRAIdentityDatabase.h"
#import "FRAIdentityDatabaseSQLiteOperations.h"
#import "FRAIdentityModel.h"
#import "FRAMechanism.h"
#import "FRAModelsFromDatabase.h"
#import "FRAPushMechanism.h"
@interface FRAIdentityTests : XCTestCase
@end
}
- (void)setUp {
[super setUp];
OCMStub([mockModelsFromDatabase allIdentitiesWithDatabase:[OCMArg any] identityDatabase:[OCMArg any] identityModel:[OCMArg any] error:[OCMArg anyObjectRef]]).andReturn(@[]);
issuer = @"ForgeRock";
accountName = @"joe.bloggs";
identity = [FRAIdentity identityWithDatabase:database identityModel:identityModel accountName:accountName issuer:issuer image:image backgroundColor:nil];
}
- (void)tearDown {
[super tearDown];
}
- (void)testCanInitIdentityWithLabelIssuerImage {
}
- (void)testCanAddMechanism {
// Given
FRAPushMechanism *pushMechanism = [[FRAPushMechanism alloc] initWithDatabase:database identityModel:identityModel];
// When
// Then
}
// Given
FRAPushMechanism *pushMechanism = [[FRAPushMechanism alloc] initWithDatabase:database identityModel:identityModel];
// When
// Then
OCMVerify([(FRAIdentityDatabaseSQLiteOperations*)mockSqlOperations insertMechanism:pushMechanism error:nil]);
}
// Given
FRAPushMechanism *pushMechanism = [[FRAPushMechanism alloc] initWithDatabase:database identityModel:identityModel];
[[NSNotificationCenter defaultCenter] addMockObserver:databaseObserverMock name:FRAIdentityDatabaseChangedNotification object:database];
[[databaseObserverMock expect] notificationWithName:FRAIdentityDatabaseChangedNotification object:database userInfo:[OCMArg any]];
// When
// Then
}
- (void)testCanRemoveMechanism {
// Given
FRAPushMechanism *pushMechanism = [[FRAPushMechanism alloc] initWithDatabase:database identityModel:identityModel];
OCMStub([(FRAIdentityDatabaseSQLiteOperations*)mockSqlOperations insertMechanism:pushMechanism error:nil]).andReturn(YES);
OCMStub([(FRAIdentityDatabaseSQLiteOperations*)mockSqlOperations deleteMechanism:pushMechanism error:nil]).andReturn(YES);
OCMStub([(FRAIdentityDatabaseSQLiteOperations*)mockSqlOperations deleteIdentity:identity error:nil]).andReturn(YES);
// When
// Then
}
// Given
OCMStub([(FRAIdentityDatabaseSQLiteOperations*)mockSqlOperations insertIdentity:identity error:nil]).andReturn(YES);
FRAPushMechanism *pushMechanism = [[FRAPushMechanism alloc] initWithDatabase:database identityModel:identityModel];
OCMStub([(FRAIdentityDatabaseSQLiteOperations*)mockSqlOperations insertMechanism:pushMechanism error:nil]).andReturn(YES);
OCMStub([(FRAIdentityDatabaseSQLiteOperations*)mockSqlOperations deleteMechanism:pushMechanism error:nil]).andReturn(YES);
OCMStub([(FRAIdentityDatabaseSQLiteOperations*)mockSqlOperations deleteIdentity:identity error:nil]).andReturn(YES);
// When
// Then
OCMVerify([(FRAIdentityDatabaseSQLiteOperations*)mockSqlOperations deleteMechanism:pushMechanism error:nil]);
}
// Given
OCMStub([(FRAIdentityDatabaseSQLiteOperations*)mockSqlOperations insertIdentity:identity error:nil]).andReturn(YES);
FRAPushMechanism *pushMechanism = [[FRAPushMechanism alloc] initWithDatabase:database identityModel:identityModel];
OCMStub([(FRAIdentityDatabaseSQLiteOperations*)mockSqlOperations insertMechanism:pushMechanism error:nil]).andReturn(YES);
[[NSNotificationCenter defaultCenter] addMockObserver:databaseObserverMock name:FRAIdentityDatabaseChangedNotification object:database];
[[databaseObserverMock expect] notificationWithName:FRAIdentityDatabaseChangedNotification object:database userInfo:[OCMArg any]];
OCMStub([(FRAIdentityDatabaseSQLiteOperations*)mockSqlOperations deleteMechanism:pushMechanism error:nil]).andReturn(YES);
OCMStub([(FRAIdentityDatabaseSQLiteOperations*)mockSqlOperations deleteIdentity:identity error:nil]).andReturn(YES);
// When
// Then
}
// Given
FRAPushMechanism *pushMechanism = [[FRAPushMechanism alloc] initWithDatabase:database identityModel:identityModel];
OCMStub([(FRAIdentityDatabaseSQLiteOperations*)mockSqlOperations insertMechanism:pushMechanism error:nil]).andReturn(YES);
OCMStub([(FRAIdentityDatabaseSQLiteOperations*)mockSqlOperations deleteMechanism:pushMechanism error:nil]).andReturn(YES);
// When
// Then
}
// Given
OCMStub([(FRAIdentityDatabaseSQLiteOperations*)mockSqlOperations insertIdentity:identity error:nil]).andReturn(YES);
FRAPushMechanism *pushMechanism = [[FRAPushMechanism alloc] initWithDatabase:database identityModel:identityModel];
OCMReject([(FRAIdentityDatabaseSQLiteOperations*)mockSqlOperations deleteMechanism:pushMechanism error:[OCMArg anyObjectRef]]);
// When
// Then
}
- (void)testCanQueryForMechanismByType {
// Given
FRAHotpOathMechanism *oathMechanism = [[FRAHotpOathMechanism alloc] initWithDatabase:database identityModel:identityModel];
FRAPushMechanism *pushMechanism = [[FRAPushMechanism alloc] initWithDatabase:database identityModel:identityModel];
// When
// Then
}
// Given
FRAPushMechanism *mechanism = [[FRAPushMechanism alloc] initWithDatabase:database identityModel:nil];
OCMStub([(FRAIdentityDatabaseSQLiteOperations*)mockSqlOperations insertMechanism:mechanism error:nil]).andReturn(YES);
FRAPushMechanism *duplicateMechanism = [[FRAPushMechanism alloc] initWithDatabase:database identityModel:nil];
OCMStub([(FRAIdentityDatabaseSQLiteOperations*)mockSqlOperations insertMechanism:duplicateMechanism error:nil]).andReturn(YES);
// When
// Then
}
// Given
FRAHotpOathMechanism *mechanism = [[FRAHotpOathMechanism alloc] initWithDatabase:database identityModel:nil];
OCMStub([(FRAIdentityDatabaseSQLiteOperations*)mockSqlOperations insertMechanism:mechanism error:nil]).andReturn(YES);
FRAPushMechanism *differentMechanism = [[FRAPushMechanism alloc] initWithDatabase:database identityModel:nil];
OCMStub([(FRAIdentityDatabaseSQLiteOperations*)mockSqlOperations insertMechanism:differentMechanism error:nil]).andReturn(YES);
// When
// Then
}
@end