diff --git a/src/darwin/Framework/CHIPTests/MTRCertificateTests.m b/src/darwin/Framework/CHIPTests/MTRCertificateTests.m index 1dfbfd5293af62..a9f49b0d6a9c83 100644 --- a/src/darwin/Framework/CHIPTests/MTRCertificateTests.m +++ b/src/darwin/Framework/CHIPTests/MTRCertificateTests.m @@ -126,6 +126,9 @@ - (void)testGenerateIntermediateCert __auto_type * intermediateKeys = [[MTRTestKeys alloc] init]; XCTAssertNotNil(intermediateKeys); + // TODO: there are several places in our tests where we call `copyPublicKey` on objects without first + // seeing if it's implemented by the receiver. (the `MTRKeypair` protocol says both `publicKey` and + // `copyPublicKey` are optional.) __auto_type * intermediatePublicKey = intermediateKeys.copyPublicKey; XCTAssert(intermediatePublicKey != NULL); CFAutorelease(intermediatePublicKey); diff --git a/src/darwin/Framework/CHIPTests/TestHelpers/MTRTestKeys.m b/src/darwin/Framework/CHIPTests/TestHelpers/MTRTestKeys.m index e6a74f25bdeccf..ac05011350c881 100644 --- a/src/darwin/Framework/CHIPTests/TestHelpers/MTRTestKeys.m +++ b/src/darwin/Framework/CHIPTests/TestHelpers/MTRTestKeys.m @@ -31,6 +31,13 @@ - (NSData *)publicKeyData return (__bridge_transfer NSData *) SecKeyCopyExternalRepresentation([self publicKey], nil); } +- (SecKeyRef)copyPublicKey { + // because this varies significantly from the actual implementations, + // it's probably not a great idea to rely on this for memory leak behavior information. + CFRetain(_publicKey); + return _publicKey; +} + - (instancetype)init { if (!(self = [super init])) {