diff --git a/src/credentials/tests/TestCommissionerDUTVectors.cpp b/src/credentials/tests/TestCommissionerDUTVectors.cpp index 2f31b79e688f1b..d841151a9b4bc8 100644 --- a/src/credentials/tests/TestCommissionerDUTVectors.cpp +++ b/src/credentials/tests/TestCommissionerDUTVectors.cpp @@ -35,7 +35,6 @@ #include #include -#include #include #include @@ -52,17 +51,21 @@ static void OnAttestationInformationVerificationCallback(void * context, const D static void TestCommissionerDUTVectors(nlTestSuite * inSuite, void * inContext) { - constexpr char kCommissionerDUTTestVectorsRootPath[] = "../../credentials/development/commissioner_dut"; - DeviceAttestationVerifier * example_dac_verifier = GetDefaultDACVerifier(GetTestAttestationTrustStore()); NL_TEST_ASSERT(inSuite, example_dac_verifier != nullptr); - DIR * dir = opendir(kCommissionerDUTTestVectorsRootPath); - NL_TEST_ASSERT(inSuite, dir != nullptr); - - char cwd[256]; - getcwd(cwd, sizeof(cwd)); - fprintf(stderr, "DEBUG PRINT 00: %s\n", cwd); + std::string dirPath("../../../../../credentials/development/commissioner_dut/"); + DIR * dir = opendir(dirPath.c_str()); + while (dir == nullptr && (dirPath.find("../") == 0)) + { + dirPath = dirPath.substr(3); + dir = opendir(dirPath.c_str()); + } + if (dir == nullptr) + { + ChipLogError(Crypto, "Couldn't open folder with Commissioner DUT Test Vectors."); + return; + } dirent * entry; while ((entry = readdir(dir)) != nullptr) @@ -74,8 +77,7 @@ static void TestCommissionerDUTVectors(nlTestSuite * inSuite, void * inContext) if (strstr(entry->d_name, "struct_dac_sig_curve_secp256k1")) continue; - std::string jsonFilePath(kCommissionerDUTTestVectorsRootPath); - jsonFilePath += std::string("/") + std::string(entry->d_name) + std::string("/test_case_vector.json"); + std::string jsonFilePath = dirPath + std::string(entry->d_name) + std::string("/test_case_vector.json"); chip::Credentials::Examples::TestHarnessDACProvider dacProvider; dacProvider.Init(jsonFilePath.c_str()); @@ -155,14 +157,17 @@ static void TestCommissionerDUTVectors(nlTestSuite * inSuite, void * inContext) isSuccessCase = true; } - fprintf(stderr, "DEBUG PRINT 01: %s\n", cwd); + if (!isSuccessCase && (attestationResult == AttestationVerificationResult::kSuccess)) + { + fprintf(stderr, "DEBUG PRINT 02: %s\n", jsonFilePath.c_str()); + } + if (isSuccessCase) { NL_TEST_ASSERT(inSuite, attestationResult == AttestationVerificationResult::kSuccess); } else { - fprintf(stderr, "DEBUG PRINT 02: %s\n", jsonFilePath.c_str()); NL_TEST_ASSERT(inSuite, attestationResult != AttestationVerificationResult::kSuccess); } }