Skip to content

Commit

Permalink
Add some unit tests for [MTRCertificates isCertificate:equalTo:]
Browse files Browse the repository at this point in the history
  • Loading branch information
bzbarsky-apple committed Sep 25, 2024
1 parent c9daf0c commit ef35429
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions src/darwin/Framework/CHIPTests/MTRCertificateTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -513,4 +513,59 @@ - (void)testGenerateCSR
XCTAssertEqualObjects(publicKey, originalPublicKey);
}

- (void)testEqualTo
{
__auto_type * testKeys1 = [[MTRTestKeys alloc] init];
XCTAssertNotNil(testKeys1);

__auto_type * testKeys2 = [[MTRTestKeys alloc] init];
XCTAssertNotNil(testKeys2);

__auto_type * issuerID1 = @(1);
__auto_type * issuerID2 = @(2);

__auto_type * fabricID1 = @(3);
__auto_type * fabricID2 = @(4);

NSError * error;
__auto_type * cert111a = [MTRCertificates createRootCertificate:testKeys1 issuerID:issuerID1 fabricID:fabricID1 error:&error];
XCTAssertNil(error);
XCTAssertNotNil(cert111a);

__auto_type * cert111b = [MTRCertificates createRootCertificate:testKeys1 issuerID:issuerID1 fabricID:fabricID1 error:&error];
XCTAssertNil(error);
XCTAssertNotNil(cert111b);

__auto_type * interval = [[NSDateInterval alloc] initWithStartDate:[NSDate now] duration:500];
__auto_type * cert111c = [MTRCertificates createRootCertificate:testKeys1 issuerID:issuerID1 fabricID:fabricID1 validityPeriod:interval error:&error];
XCTAssertNil(error);
XCTAssertNotNil(cert111c);

__auto_type * cert112 = [MTRCertificates createRootCertificate:testKeys1 issuerID:issuerID1 fabricID:fabricID2 error:&error];
XCTAssertNil(error);
XCTAssertNotNil(cert112);

__auto_type * cert121 = [MTRCertificates createRootCertificate:testKeys1 issuerID:issuerID2 fabricID:fabricID1 error:&error];
XCTAssertNil(error);
XCTAssertNotNil(cert121);

__auto_type * cert211 = [MTRCertificates createRootCertificate:testKeys2 issuerID:issuerID1 fabricID:fabricID1 error:&error];
XCTAssertNil(error);
XCTAssertNotNil(cert121);

XCTAssertTrue([MTRCertificates isCertificate:cert111a equalTo:cert111b]);
XCTAssertTrue([MTRCertificates isCertificate:cert111a equalTo:cert111c]);
XCTAssertTrue([MTRCertificates isCertificate:cert111b equalTo:cert111c]);
XCTAssertTrue([MTRCertificates isCertificate:cert111c equalTo:cert111b]);

XCTAssertFalse([MTRCertificates isCertificate:cert111a equalTo:cert112]);
XCTAssertFalse([MTRCertificates isCertificate:cert111a equalTo:cert121]);
XCTAssertFalse([MTRCertificates isCertificate:cert111a equalTo:cert211]);

XCTAssertFalse([MTRCertificates isCertificate:cert112 equalTo:cert121]);
XCTAssertFalse([MTRCertificates isCertificate:cert112 equalTo:cert211]);

XCTAssertFalse([MTRCertificates isCertificate:cert121 equalTo:cert211]);
}

@end

0 comments on commit ef35429

Please sign in to comment.