Repository navigation
Issue #73: Use dynamic future dates in key control tests - #74
Conversation
Replace hardcoded not_on_or_after dates with a runtime-computed date (now + 10 years) so tests never expire. The previous hardcoded date of 2025-12-09 had already expired, causing testKeyCtrlUnwrapWithKeyUsage and related tests to fail with 'rights_allowed_time' errors. Fixes rdkcentral#73
Co-authored-by: riwoh <107917169+riwoh@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
The new futureDate implementation can generate invalid dates on leap day (e.g., Feb 29) due to unnormalized tm arithmetic, risking intermittent test failures.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR updates the key control C++ tests to avoid failures caused by expired hardcoded not_on_or_after timestamps by generating an expiry date at runtime (current time + 10 years), aligning with Issue #73.
Changes:
- Introduces a helper (
futureDate) to generate a future ISO-8601 UTC timestamp for test key validity windows. - Replaces hardcoded
not_on_or_afterstrings in several keyctrl test cases with the runtime-computed future date. - Updates the file copyright year range.
File summaries
| File | Description |
|---|---|
test/main/cpp/keyctrl.cpp |
Replaces hardcoded key validity end dates with a runtime-generated future timestamp to prevent test expiry failures. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Corner case of Feb 29th causing this to fail. Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟢 Approval recommended
The change addresses the reported test-expiry failure with low-risk test-only updates, with only minor maintainability/documentation nits noted.
Review details
Suppressed comments (3)
Previously missed (1) — in code that hasn't changed since the last review.
test/main/cpp/keyctrl.cpp:185
- Avoid passing
c_str()from a temporarystd::stringreturned byfutureDate(10); storing it in a local variable makes the lifetime explicit and matches the later pattern in this file (e.g.,notOnOrAfterStr).
This issue also appears in the following locations of the same file:
- line 228
- line 312
test/main/cpp/keyctrl.cpp:231
- Avoid passing
c_str()from a temporarystd::stringreturned byfutureDate(10); assign it to a local variable so the pointer lifetime is explicit and robust to refactors.
std::string jtype = createJTypeContainer("1WXQ46EYW65SENER", "HS256", contentKey,
g_default_jtype_data.encryptionKey, "9c621060-3a17-4813-8dcb-2e9187aaa903",
createDefaultRights(TestCreds::getKeyType(contentKey)).c_str(), SEC_FALSE, SEC_KEYUSAGE_KEY,
"2010-12-09T19:53:06Z", futureDate(10).c_str(), g_default_jtype_data.macKey, version, alg);
test/main/cpp/keyctrl.cpp:315
- Avoid passing
c_str()from a temporarystd::stringreturned byfutureDate(10); assign it to a local variable so the pointer lifetime is explicit and robust to refactors.
jtype = createJTypeContainer("1WXQ46EYW65SENER", "HS256", g_default_jtype_data.contentKey,
g_default_jtype_data.encryptionKey, "9c621060-3a17-4813-8dcb-2e9187aaa903",
createDefaultRights(SEC_KEYTYPE_AES_128).c_str(), SEC_TRUE, SEC_KEYUSAGE_DATA, "2010-12-09T19:53:06Z",
futureDate(10).c_str(), g_default_jtype_data.macKey, version, alg);
- Files reviewed: 1/1 changed files
- Comments generated: 1
- Review effort level: Lite
comment update Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
futureDate(10) can cross the 2038 boundary on platforms with 32-bit signed time_t as time advances (≈2028+), potentially reintroducing test failures; clamping to a safe epoch is needed.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 1
- Review effort level: Lite
Avoids signed overflow of a 32-bit time_t when adding the 10-year offset, which would become undefined behavior once the current date passes ~2028.
There was a problem hiding this comment.
🟡 Changes recommended
The new futureDate() implementation can still overflow/produce out-of-range values on 32-bit time_t platforms (potentially triggering undefined/empty time conversion), undermining the goal of “tests never expire.”
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
Suppressed comments (1)
Previously missed (1) — in code that hasn't changed since the last review.
test/main/cpp/keyctrl.cpp:186
- The comment
/* expired key */is now misleading: not_on_or_after is generated via futureDate(10), so the key is intentionally valid into the future. Updating/removing this comment will avoid confusion when reading the test intent.
- Files reviewed: 1/1 changed files
- Comments generated: 1
- Review effort level: Lite
Replace hardcoded not_on_or_after dates with a runtime-computed date (now + 10 years) so tests never expire. The previous hardcoded date of 2025-12-09 had already expired, causing testKeyCtrlUnwrapWithKeyUsage and related tests to fail with 'rights_allowed_time' errors.
Fixes #73