Skip to content

Commit 1378001

Browse files
committed
Fix test to use pid from json
1 parent d3ba007 commit 1378001

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

src/app/tests/suites/credentials/TestHarnessDACProvider.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,10 @@ bool ReadValue(Json::Value jsonValue)
177177
return false;
178178
}
179179

180+
uint16_t ReadUint16(Json::Value jsonValue){
181+
return static_cast<uint16_t>(jsonValue.asUInt());
182+
}
183+
180184
// TODO: This should be moved to a method of P256Keypair
181185
CHIP_ERROR LoadKeypairFromRaw(ByteSpan private_key, ByteSpan public_key, Crypto::P256Keypair & keypair)
182186
{
@@ -205,6 +209,7 @@ void TestHarnessDACProvider::Init(const char * filepath)
205209
static constexpr char kFirmwareInfoKey[] = "firmware_information";
206210
static constexpr char kIsSuccessKey[] = "is_success_case";
207211
static constexpr char kDescription[] = "description";
212+
static constexpr char kPid[] = "basic_info_pid";
208213

209214
std::ifstream json(filepath, std::ifstream::binary);
210215
if (!json)
@@ -272,6 +277,11 @@ void TestHarnessDACProvider::Init(const char * filepath)
272277
data.description.SetValue(ReadValue(root[kDescription], buf, sizeof(buf)));
273278
}
274279

280+
if (root.isMember(kPid))
281+
{
282+
data.pid.SetValue(ReadUint16(root[kPid]));
283+
}
284+
275285
Init(data);
276286
}
277287

@@ -288,6 +298,8 @@ void TestHarnessDACProvider::Init(const TestHarnessDACProviderData & data)
288298

289299
// TODO: We need a real example FirmwareInformation to be populated.
290300
mFirmwareInformation = data.firmwareInformation.HasValue() ? data.firmwareInformation.Value() : ByteSpan();
301+
302+
mPid = data.pid.ValueOr(0x8000);
291303
}
292304

293305
CHIP_ERROR TestHarnessDACProvider::GetDeviceAttestationCert(MutableByteSpan & out_dac_buffer)

src/app/tests/suites/credentials/TestHarnessDACProvider.h

+3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ struct TestHarnessDACProviderData
3333
chip::Optional<ByteSpan> firmwareInformation;
3434
chip::Optional<CharSpan> description;
3535
chip::Optional<bool> isSuccessCase;
36+
chip::Optional<uint16_t> pid;
3637
};
3738

3839
class TestHarnessDACProvider : public DeviceAttestationCredentialsProvider
@@ -47,6 +48,7 @@ class TestHarnessDACProvider : public DeviceAttestationCredentialsProvider
4748
CHIP_ERROR SignWithDeviceAttestationKey(const ByteSpan & message_to_sign, MutableByteSpan & out_signature_buffer) override;
4849
CharSpan GetDescription() { return mDescription; }
4950
bool IsSuccessCase() { return mIsSuccessCase; }
51+
uint16_t GetPid() { return mPid; }
5052

5153
void Init(const char * filepath);
5254
void Init(const TestHarnessDACProviderData & data);
@@ -60,6 +62,7 @@ class TestHarnessDACProvider : public DeviceAttestationCredentialsProvider
6062
ByteSpan mFirmwareInformation;
6163
CharSpan mDescription;
6264
bool mIsSuccessCase;
65+
uint16_t mPid;
6366
};
6467

6568
} // namespace Examples

src/credentials/tests/TestCommissionerDUTVectors.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ TEST_F(TestCommissionerDUTVectors, TestCommissionerDUTVectors)
108108
Crypto::DRBG_get_bytes(attestationNonceBuf, sizeof(attestationNonceBuf));
109109

110110
VendorId vid = TestVendor1;
111-
uint16_t pid = strstr(entry->d_name, "_vidpid_fallback_encoding_") ? 0x00B1 : 0x8000;
111+
uint16_t pid = dacProvider.GetPid();
112112

113113
EXPECT_EQ(dacProvider.GetCertificationDeclaration(certDeclSpan), CHIP_NO_ERROR);
114114
EXPECT_EQ(dacProvider.GetDeviceAttestationCert(dacCertSpan), CHIP_NO_ERROR);

0 commit comments

Comments
 (0)