Merge branch 'IOSAD-239'

pull/3/head
Dirk Zimmermann 8 months ago
commit dc81a4baf4
  1. 3
      build-linux/Makefile
  2. 12
      build-mac/pEpObjCAdapterTests/TKA/PEPInternalSessionTKATest.m
  3. 12
      build-mac/pEpObjCAdapterTests/TKA/PEPSessionTKATest.m
  4. 3
      build-mac/pEpObjCAdapterTests/TKA/PEPTKATestDelegate.h
  5. 3
      build-mac/pEpObjCAdapterTests/TKA/PEPTKATestDelegate.m
  6. 33
      src/TKA/PEPInternalSession+TKA.m

@ -1,7 +1,6 @@
# Content of this library
TARGET = libpEpObjCAdapter
# Can't use find-objects here since that would search the entire repo.
OBJECTS = $(patsubst %.m,%.o,$(wildcard ../*.m ../*/*.m))
OBJECTS = $(call find-objects,../src/)
DEPFILES = $(call find-deps,..)
HEADERS = $(call find-headers,../PublicHeaders/)

@ -53,9 +53,6 @@
XCTAssertTrue([session tkaSubscribeWithKeychangeDelegate:delegate error:&error]);
XCTAssertNil(error);
// now owned by the adapter
delegate = nil;
PEPIdentity *me = [[PEPIdentity alloc]
initWithAddress:@"me@example.org"
userID:@"me_myself"
@ -74,6 +71,15 @@
[self waitForExpectations:@[expDelegateCalled] timeout:PEPTestInternalFastTimeout];
XCTAssertNotNil(delegate.keyReceived);
// NOTE: 256 bits is the expected key size currently produced by the *mock*.
// Bound to change any time.
XCTAssertEqual([delegate.keyReceived length], 256/8);
// now owned by the adapter
delegate = nil;
error = nil;
XCTAssertTrue([session tkaSubscribeWithKeychangeDelegate:nil error:&error]);
XCTAssertNil(error);

@ -43,9 +43,6 @@
XCTAssertTrue([self tkaSubscribeSession:session keychangeDelegate:delegate error:&error]);
XCTAssertNil(error);
// now owned by the adapter
delegate = nil;
PEPIdentity *me = [[PEPIdentity alloc]
initWithAddress:@"me@example.org"
userID:@"me_myself"
@ -64,6 +61,15 @@
[self waitForExpectations:@[expDelegateCalled] timeout:PEPTestInternalFastTimeout];
XCTAssertNotNil(delegate.keyReceived);
// NOTE: 256 bits is the expected key size currently produced by the *mock*.
// Bound to change any time.
XCTAssertEqual([delegate.keyReceived length], 256/8);
// now owned by the adapter
delegate = nil;
error = nil;
XCTAssertTrue([self tkaSubscribeSession:session keychangeDelegate:nil error:&error]);
XCTAssertNil(error);

@ -16,6 +16,9 @@ NS_ASSUME_NONNULL_BEGIN
@interface PEPTKATestDelegate : NSObject <PEPTKADelegate>
/// The key that has been received by the engine.
@property (nonatomic, readonly, nullable) NSString *keyReceived;
- (instancetype)initExpKeyChangedCalled:(XCTestExpectation *)expKeyChangedCalled
expDealloced:(XCTestExpectation *)expDealloced;

@ -10,6 +10,8 @@
@interface PEPTKATestDelegate ()
@property (nonatomic, nullable) NSString *keyReceived;
@property (nonatomic, readonly) XCTestExpectation *expKeyChangedCalled;
@property (nonatomic, readonly) XCTestExpectation *expDealloced;
@ -31,6 +33,7 @@
- (void)tkaKeyChangeForMe:(nonnull PEPIdentity *)me
partner:(nonnull PEPIdentity *)partner
key:(nonnull NSString *)key {
self.keyReceived = key;
[self.expKeyChangedCalled fulfill];
}

@ -13,6 +13,10 @@
// MARK: - Cheap fake of the engine's TKA API
// NOTE: IOSAD-239
// Delete this section once the engine has TKA implemented,
// and instead simply include the correct header.
typedef PEP_STATUS (*tka_keychange_t)(const pEp_identity *me,
const pEp_identity *partner,
const char *key);
@ -25,6 +29,12 @@ PEP_STATUS tka_subscribe_keychange(PEP_SESSION session,
return PEP_STATUS_OK;
}
/// The number of bytes the engine would use for temp key.
const NSUInteger s_numberOfBytesForKey = 256/8;
/// 256 bits of "random" data, which in this mock is always the same.
char *s_mockedTmpKey = NULL;
PEP_STATUS tka_request_temp_key(PEP_SESSION session,
pEp_identity *me,
pEp_identity *partner) {
@ -32,7 +42,28 @@ PEP_STATUS tka_request_temp_key(PEP_SESSION session,
return PEP_ILLEGAL_VALUE;
}
g_tkaKeyChangeCallback(me, partner, "compleeeetely_fake_key");
static dispatch_once_t onlyOnce;
dispatch_once(&onlyOnce, ^{
s_mockedTmpKey = malloc(s_numberOfBytesForKey + 1);
srand(1); // Make the default explicit
for (int byteIndex = 0; byteIndex < s_numberOfBytesForKey; ++byteIndex) {
s_mockedTmpKey[byteIndex] = ' ' + (rand() % 94);
}
s_mockedTmpKey[s_numberOfBytesForKey] = '\0';
});
int64_t nsDelta = 1000000000; // 1s in nanoseconds
dispatch_time_t delay = dispatch_time(DISPATCH_TIME_NOW, nsDelta);
pEp_identity *meCopy = identity_dup(me);
pEp_identity *partnerCopy = identity_dup(partner);
dispatch_after(delay, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
g_tkaKeyChangeCallback(meCopy, partnerCopy, s_mockedTmpKey);
free_identity(meCopy);
free_identity(partnerCopy);
});
return PEP_STATUS_OK;
}

Loading…
Cancel
Save