Skip to content

Issue #73: Use dynamic future dates in key control tests - #74

Merged
riwoh merged 6 commits into
rdkcentral:mainfrom
seanjin99:fix/expired-test-dates
Sep 3, 2026
Merged

riwoh merged 6 commits into
rdkcentral:mainfrom
seanjin99:fix/expired-test-dates

Conversation

@seanjin99

Copy link
Copy Markdown
Contributor

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

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

@riwoh riwoh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seanjin99 small fix.

Comment thread test/main/cpp/keyctrl.cpp Outdated
@riwoh
riwoh requested a review from mhabrat March 11, 2026 14:10
Co-authored-by: riwoh <107917169+riwoh@users.noreply.github.com>
@riwoh
riwoh self-requested a review March 27, 2026 18:18
riwoh
riwoh previously approved these changes Mar 27, 2026
mhabrat
mhabrat previously approved these changes May 28, 2026
Copilot AI lite review requested due to automatic review settings September 2, 2026 23:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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_after strings 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.

Comment thread test/main/cpp/keyctrl.cpp Outdated
Corner case of Feb 29th causing this to fail.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@riwoh
riwoh dismissed stale reviews from mhabrat and themself via e20edb9 September 3, 2026 00:54
Copilot AI review requested due to automatic review settings September 3, 2026 00:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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 temporary std::string returned by futureDate(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 temporary std::string returned by futureDate(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 temporary std::string returned by futureDate(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 thread test/main/cpp/keyctrl.cpp Outdated
comment update

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings September 3, 2026 02:29
riwoh
riwoh previously approved these changes Sep 3, 2026
@riwoh riwoh changed the title fix: use dynamic future dates in key control tests Issue #74: Use dynamic future dates in key control tests Sep 3, 2026
@riwoh riwoh changed the title Issue #74: Use dynamic future dates in key control tests Issue #73: Use dynamic future dates in key control tests Sep 3, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

Comment thread test/main/cpp/keyctrl.cpp
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.
Copilot AI review requested due to automatic review settings September 3, 2026 02:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

Comment thread test/main/cpp/keyctrl.cpp
@riwoh
riwoh merged commit f07957b into rdkcentral:main Sep 3, 2026
4 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 3, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Hardcoded date in key validity test is now expired.

4 participants