Browse Source

Fix tests for engine Release_2.1.27

test_fixes_for_engine_Release_2.1.27
Dirk Zimmermann 1 year ago
parent
commit
f2e5a25200
5 changed files with 105 additions and 12 deletions
  1. +6
    -0
      pEpObjCAdapter.xcodeproj/project.pbxproj
  2. +27
    -12
      pEpObjCTests/PEPInternalSessionTest.m
  3. +11
    -0
      pEpObjCTests/PEPSessionTest.m
  4. +22
    -0
      pEpObjCTests/TestUtils/PEPInternalSession+SetIdentity.h
  5. +39
    -0
      pEpObjCTests/TestUtils/PEPInternalSession+SetIdentity.m

+ 6
- 0
pEpObjCAdapter.xcodeproj/project.pbxproj View File

@ -181,6 +181,7 @@
432FA2D81C884FF500DDF874 /* meATdontcare_E3BFBCA9248FC681_sec.asc in Resources */ = {isa = PBXBuildFile; fileRef = 432FA2D61C884FF500DDF874 /* meATdontcare_E3BFBCA9248FC681_sec.asc */; };
4331CE94229C2AAF00DDDC65 /* PEPSizeTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 4331CE93229C2AAF00DDDC65 /* PEPSizeTest.m */; };
4336853F203D5CE60069A451 /* PEPTestUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 15D3D77C2010DDC500A0DA20 /* PEPTestUtils.m */; };
433A03FA2627268700758B57 /* PEPInternalSession+SetIdentity.m in Sources */ = {isa = PBXBuildFile; fileRef = 433A03F92627268700758B57 /* PEPInternalSession+SetIdentity.m */; };
434226811D4F60000083ED79 /* PepTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 434226801D4F60000083ED79 /* PepTests.m */; };
434707F924C30E9700E05485 /* PEPSessionTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 434707F824C30E9700E05485 /* PEPSessionTest.m */; };
4349CD7924ADDB8800A22A13 /* PEPPassphraseCache+Reset.m in Sources */ = {isa = PBXBuildFile; fileRef = 4349CD7824ADDB8800A22A13 /* PEPPassphraseCache+Reset.m */; };
@ -396,6 +397,8 @@
432FA2D51C884FF500DDF874 /* meATdontcare_E3BFBCA9248FC681_pub.asc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = meATdontcare_E3BFBCA9248FC681_pub.asc; sourceTree = "<group>"; };
432FA2D61C884FF500DDF874 /* meATdontcare_E3BFBCA9248FC681_sec.asc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = meATdontcare_E3BFBCA9248FC681_sec.asc; sourceTree = "<group>"; };
4331CE93229C2AAF00DDDC65 /* PEPSizeTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PEPSizeTest.m; sourceTree = "<group>"; };
433A03F72627268600758B57 /* PEPInternalSession+SetIdentity.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "PEPInternalSession+SetIdentity.h"; sourceTree = "<group>"; };
433A03F92627268700758B57 /* PEPInternalSession+SetIdentity.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "PEPInternalSession+SetIdentity.m"; sourceTree = "<group>"; };
433DFBAA24A5E04000AB373B /* PEPPassphraseCacheEntry.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PEPPassphraseCacheEntry.h; sourceTree = "<group>"; };
433DFBAB24A5E04000AB373B /* PEPPassphraseCacheEntry.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PEPPassphraseCacheEntry.m; sourceTree = "<group>"; };
433DFBAE24A5ED0D00AB373B /* PEPPassphraseCacheInternal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PEPPassphraseCacheInternal.h; sourceTree = "<group>"; };
@ -649,6 +652,8 @@
436E917624B71E12000296FF /* PEPPassphraseProviderMock.m */,
43062BAB24EEC59800489258 /* PEPIdentity+isPEPUser.h */,
43062BAC24EEC83400489258 /* PEPIdentity+isPEPUser.m */,
433A03F72627268600758B57 /* PEPInternalSession+SetIdentity.h */,
433A03F92627268700758B57 /* PEPInternalSession+SetIdentity.m */,
);
path = TestUtils;
sourceTree = "<group>";
@ -1364,6 +1369,7 @@
4396CECB2187220200FDD398 /* PEPInternalSessionTestSendMessageDelegate.m in Sources */,
434707F924C30E9700E05485 /* PEPSessionTest.m in Sources */,
152A9C472010F50400F962ED /* PEPInternalSessionTest.m in Sources */,
433A03FA2627268700758B57 /* PEPInternalSession+SetIdentity.m in Sources */,
434226811D4F60000083ED79 /* PepTests.m in Sources */,
4336853F203D5CE60069A451 /* PEPTestUtils.m in Sources */,
4349CD7924ADDB8800A22A13 /* PEPPassphraseCache+Reset.m in Sources */,


+ 27
- 12
pEpObjCTests/PEPInternalSessionTest.m View File

@ -26,6 +26,7 @@
#import "PEPSessionProvider.h"
#import "PEPInternalSession.h"
#import "PEPIdentity+isPEPUser.h"
#import "PEPInternalSession+SetIdentity.h"
@interface PEPInternalSessionTest : XCTestCase
@ -414,8 +415,9 @@
XCTAssertNil(error);
identBob.fingerPrint = nil;
XCTAssertTrue([session updateIdentity:identBob error:&error]);
XCTAssertNil(error);
XCTAssertFalse([session updateIdentity:identBob error:&error]);
XCTAssertNotNil(error);
XCTAssertEqual(error.code, PEP_KEY_UNSUITABLE);
XCTAssertNil(identBob.fingerPrint);
// Gray == PEPRatingUnencrypted
@ -464,25 +466,25 @@
// Now let see with bob's pubkey already known
// pEp Test Bob (test key, don't use) <pep.test.bob@pep-project.org>
// BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39
XCTAssertTrue([PEPTestUtils importBundledKey:@"0xC9C2EE39.asc" session:session]);
PEPIdentity *identBob = [[PEPIdentity alloc]
initWithAddress:@"pep.test.bob@pep-project.org"
userID:@"42" userName:@"pEp Test Bob"
isOwn:NO
fingerPrint:@"BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39"];
PEPIdentity *identBob = [self checkImportingKeyFilePath:@"0xC9C2EE39.asc"
address:@"pep.test.bob@pep-project.org"
userID:@"42"
fingerPrint:@"BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39"
session:session];
XCTAssertNotNil(identBob);
XCTAssertTrue([session updateIdentity:identBob error:&error]);
XCTAssertNil(error);
// Should be yellow, since no handshake happened.
// No key election, outgoing messages are unencrypted (after setIdentity)
numRating = [self testOutgoingRatingForMessage:msg session:session error:&error];
XCTAssertNotNil(numRating);
XCTAssertNil(error);
XCTAssertEqual(numRating.pEpRating, PEPRatingReliable);
XCTAssertEqual(numRating.pEpRating, PEPRatingUnencrypted);
// No key election, there is no key (after setIdentity)
rating = [self ratingForIdentity:identBob session:session];
XCTAssertEqual(rating, PEPRatingReliable);
XCTAssertEqual(rating, PEPRatingHaveNoKey);
// Let' say we got that handshake, set PEP_ct_confirmed in Bob's identity
XCTAssertTrue([session trustPersonalKey:identBob error:&error]);
@ -1646,6 +1648,19 @@
NSError *error = nil;
XCTAssertTrue([session updateIdentity:identTest error:&error]);
XCTAssertNil(error);
XCTAssertNil(identTest.fingerPrint); // should be nil before setIdentity
error = nil;
identTest.fingerPrint = fingerPrint;
XCTAssertTrue([session setIdentity:identTest error:&error]);
XCTAssertNil(error);
// forget the fingerprint
identTest.fingerPrint = nil;
error = nil;
XCTAssertTrue([session updateIdentity:identTest error:&error]);
XCTAssertNil(error);
XCTAssertNotNil(identTest.fingerPrint);
XCTAssertEqualObjects(identTest.fingerPrint, fingerPrint);


+ 11
- 0
pEpObjCTests/PEPSessionTest.m View File

@ -15,6 +15,7 @@
#import "PEPTestUtils.h"
#import "PEPSessionProvider.h"
#import "PEPInternalSession.h"
#import "PEPInternalSession+SetIdentity.h"
@interface PEPSessionTest : XCTestCase
@ -454,7 +455,17 @@
NSError *error = nil;
PEPIdentity *identTestUpdated = [self updateIdentity:identTest error:&error];
XCTAssertNil(identTestUpdated.fingerPrint); // key election, no key is chosen yet
PEPInternalSession *session = [PEPInternalSession new];
error = nil;
identTest.fingerPrint = fingerPrint;
[session setIdentity:identTest error:&error];
XCTAssertNil(error);
identTest.fingerPrint = fingerPrint;
identTestUpdated = [self updateIdentity:identTest error:&error];
XCTAssertNil(error);
XCTAssertNotNil(identTestUpdated);
XCTAssertNotNil(identTestUpdated.fingerPrint);


+ 22
- 0
pEpObjCTests/TestUtils/PEPInternalSession+SetIdentity.h View File

@ -0,0 +1,22 @@
//
// PEPInternalSession+SetIdentity.h
// pEpObjCAdapterTests
//
// Created by Dirk Zimmermann on 14.04.21.
// Copyright © 2021 pp. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "PEPInternalSession.h"
NS_ASSUME_NONNULL_BEGIN
@interface PEPInternalSession (SetIdentity)
/// Wraps the (internal) set_identity.
- (BOOL)setIdentity:(PEPIdentity *)identity error:(NSError * _Nullable * _Nullable)error;
@end
NS_ASSUME_NONNULL_END

+ 39
- 0
pEpObjCTests/TestUtils/PEPInternalSession+SetIdentity.m View File

@ -0,0 +1,39 @@
//
// PEPInternalSession+SetIdentity.m
// pEpObjCAdapterTests
//
// Created by Dirk Zimmermann on 14.04.21.
// Copyright © 2021 pp. All rights reserved.
//
#import "PEPInternalSession+SetIdentity.h"
#import "PEPTypes.h"
#import "PEPInternalSession.h"
#import "PEPInternalSession+PassphraseCache.h"
#import "NSError+PEP+Internal.h"
#import "PEPIdentity+Engine.h"
#import "pEpEngine.h"
@implementation PEPInternalSession (SetIdentity)
- (BOOL)setIdentity:(PEPIdentity *)identity error:(NSError * _Nullable * _Nullable)error
{
pEp_identity *ident = [identity toStruct];
PEPStatus status = (PEPStatus) [self runWithPasswords:^PEP_STATUS(PEP_SESSION session) {
return set_identity(self.session, ident);
}];
if ([NSError setError:error fromPEPStatus:status]) {
free_identity(ident);
return NO;
}
free_identity(ident);
return YES;
}
@end

Loading…
Cancel
Save