Skip to content

Commit 9099608

Browse files
Improve the unit tests for MTRCertificateInfo.publicKeyData. (#36150)
Checks the value, not just that there is a value.
1 parent 29a567e commit 9099608

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/darwin/Framework/CHIPTests/MTRCertificateInfoTests.m

+24-1
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,22 @@ - (MTRCertificateTLVBytes)exampleRCACertTLV
5858
options:0];
5959
}
6060

61+
- (NSData *)exampleRCACertPublicKey
62+
{
63+
// Needs to match the "Public Key" listed above.
64+
const unsigned char publicKeyBytes[] = "\x04\x61\xE7\x5C\xFE\x03\xEC\x90\x5E\xF4\x53\x77\xE5\xF4\xB5\x1D"
65+
"\xE4\x3D\x55\xF4\xD4\xE7\xEA\x7B\x22\x76\x5E\x59\xCA\x0A\x9B\xDB"
66+
"\x59\x8F\x69\xDB\x12\x8B\xFB\x35\xBF\x03\x1F\xE9\x51\xED\x53\x37"
67+
"\x5D\x35\xB0\x53\x22\xF4\xDF\x7E\xBA\xEC\x02\xAC\x52\xF3\x1B\x9A"
68+
"\xD7";
69+
return [NSData dataWithBytes:publicKeyBytes length:sizeof(publicKeyBytes) - 1];
70+
}
71+
6172
- (void)testParseRootCertificateTLV
6273
{
6374
MTRCertificateInfo * info = [[MTRCertificateInfo alloc] initWithTLVBytes:self.exampleRCACertTLV];
6475
XCTAssertNotNil(info);
76+
XCTAssertEqualObjects(info.publicKeyData, self.exampleRCACertPublicKey);
6577
XCTAssertEqual([NSDate.now compare:info.notBefore], NSOrderedDescending);
6678
XCTAssertEqual([NSDate.now compare:info.notAfter], NSOrderedAscending);
6779

@@ -113,11 +125,22 @@ - (MTRCertificateTLVBytes)exampleNOCertTLV
113125
options:0];
114126
}
115127

128+
- (NSData *)exampleNOCertPublicKey
129+
{
130+
// Needs to match the "Public Key" listed above.
131+
const unsigned char publicKeyBytes[] = "\x04\xFD\x7F\x7A\x19\x37\xE0\x6D\xA4\xC2\xC9\x95\xC5\x5F\x01\x10"
132+
"\xD2\xB0\xFC\x93\x50\x4C\x4A\x2A\xD5\x65\x90\x8B\x42\x7C\xAF\x60"
133+
"\x4A\x1C\x24\xF9\xC1\x75\x61\x4C\x45\xDC\x87\x34\x0F\xB4\x1C\x24"
134+
"\xD2\x40\x11\x3F\x82\x6D\x8B\x2A\x24\x0E\xE4\xA5\x9B\x30\xC6\xA9"
135+
"\x51";
136+
return [NSData dataWithBytes:publicKeyBytes length:sizeof(publicKeyBytes) - 1];
137+
}
138+
116139
- (void)testParseOperationalCertificateTLV
117140
{
118141
MTRCertificateInfo * info = [[MTRCertificateInfo alloc] initWithTLVBytes:self.exampleNOCertTLV];
119142
XCTAssertNotNil(info);
120-
XCTAssertNotNil(info.publicKeyData);
143+
XCTAssertEqualObjects(info.publicKeyData, self.exampleNOCertPublicKey);
121144
XCTAssertEqual([NSDate.now compare:info.notBefore], NSOrderedDescending);
122145
XCTAssertEqual([NSDate.now compare:info.notAfter], NSOrderedAscending);
123146

0 commit comments

Comments
 (0)