Skip to content

[fix] Part init failure with multiple init calls#240

Draft
rajesh-gali wants to merge 2 commits intomainfrom
user/rajeshgali/hsm-part-init-fix
Draft

[fix] Part init failure with multiple init calls#240
rajesh-gali wants to merge 2 commits intomainfrom
user/rajeshgali/hsm-part-init-fix

Conversation

@rajesh-gali
Copy link
Contributor

Addressed an issue where subsequent part init fails after a successful init.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes behavior around partition initialization when init is called multiple times, ensuring subsequent operations behave consistently after an init attempt.

Changes:

  • Updated HsmPartition::init to avoid propagating ddi::init_part errors and instead log them.
  • Adjusted partition init tests to expect init to succeed, and to validate failure via open_session instead.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
api/tests/src/partition_tests.rs Updates init-related negative tests to treat init as non-failing and validate failure through open_session.
api/lib/src/partition.rs Changes HsmPartition::init to swallow init errors (log + return Ok(())).

Comment on lines +171 to 180
let creds = HsmCredentials::new(&APP_ID, &APP_PIN);
part.init(creds, None, None, obk_config, pota)
.expect("init should return Ok even on bad params");

let rev = part.api_rev_range().max();
let result = part.open_session(rev, &creds, None);
assert!(
result.is_err(),
"open_session should fail after init with null OBK"
);
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

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

These negative tests became significantly less specific: they now only assert open_session returns some error and no longer verify the expected error variant (previously InvalidArgument). This can hide regressions (e.g., failing for the wrong reason). Consider asserting the exact error returned by open_session (or by init, depending on the intended contract), and apply the same strengthening across the similar updated tests in this file.

Copilot uses AI. Check for mistakes.
pota,
let creds = HsmCredentials::new(&APP_ID, &APP_PIN);
part.init(creds, None, None, obk_config, pota)
.expect("init should return Ok even on bad params");
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

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

The panic message is misleading/unhelpful for diagnosing failures: it states that init should succeed 'even on bad params', which reads like an unconditional success requirement rather than the specific scenario being tested. Consider updating it to describe the intended behavior more precisely (e.g., init should be idempotent / should not error even if later session creation is rejected).

Suggested change
.expect("init should return Ok even on bad params");
.expect("init should succeed even when caller supplies a null OBK; session creation is expected to fail later");

Copilot uses AI. Check for mistakes.
Rajesh Gali added 2 commits March 6, 2026 22:51
part init changes to allow partition init success for already
established credentials
@rajesh-gali rajesh-gali force-pushed the user/rajeshgali/hsm-part-init-fix branch from 01643c1 to ccddd45 Compare March 6, 2026 22:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants