Skip to content

fix(bitwarden_item): honor check mode and preserve password on None#271

Merged
markuslf merged 1 commit into
mainfrom
fix/bitwarden-item-check-mode-and-password
May 25, 2026
Merged

fix(bitwarden_item): honor check mode and preserve password on None#271
markuslf merged 1 commit into
mainfrom
fix/bitwarden-item-check-mode-and-password

Conversation

@markuslf
Copy link
Copy Markdown
Member

Two deferred behavior-changing fixes for the bitwarden_item module.

check_mode

The module declared supports_check_mode=True but called edit_item / create_item / add_attachment regardless, so a --check run mutated the vault. Every write is now guarded by not module.check_mode; in check mode the module returns the would-be item and the correct changed.

None password

diff_and_update treated a target password of None (the default, when password is not given) as differing from an existing real password and wrote null over it, wiping the password. A None password now preserves the existing item's password.

This matches the documented behavior, which already stated that existing passwords "are overwritten by every non-None value" (i.e. None must not overwrite). The DOCUMENTATION is clarified to spell out the existing-item case.

Tests

main()-level tests using a fake Bitwarden client and the shared ansible module harness:

  • check-mode create and edit do not write (assert create_item / edit_item not called).
  • a run without password reports changed=false, does not edit, and keeps the existing password.
  • a changed password does write when not in check mode.

Deferred

The get_item_by_id returns-or-raises contract (the lookup wants a friendly "not found"; the module wants the id to exist) needs its own design and stays a separate PR.

Validation

Full tox matrix green (100 tests across 13 envs); ansible-doc renders; pre-commit green.

…ssword on None

Two behavior fixes:

- check_mode: the module declared supports_check_mode but wrote to the
  vault regardless (edit/create/add_attachment). Guard every write behind
  'not module.check_mode' and return the predicted item in check mode.

- None password: diff_and_update saw target password None vs an existing
  real password as a change and overwrote it with null. A None password
  now preserves the existing item's password, matching the documented
  behavior ('overwritten by every non-None value').

Clarify the DOCUMENTATION accordingly and add main()-level tests (fake
Bitwarden client + the ansible module harness) for both paths.

The get_item_by_id returns-or-raises contract is left for a separate PR.
@markuslf markuslf requested a review from NavidSassan May 25, 2026 08:18
@markuslf markuslf merged commit 4138ee0 into main May 25, 2026
11 checks passed
@markuslf markuslf deleted the fix/bitwarden-item-check-mode-and-password branch May 25, 2026 08:31
ebuerki-lf pushed a commit that referenced this pull request May 26, 2026
…ssword on None (#271)

Two behavior fixes:

- check_mode: the module declared supports_check_mode but wrote to the
  vault regardless (edit/create/add_attachment). Guard every write behind
  'not module.check_mode' and return the predicted item in check mode.

- None password: diff_and_update saw target password None vs an existing
  real password as a change and overwrote it with null. A None password
  now preserves the existing item's password, matching the documented
  behavior ('overwritten by every non-None value').

Clarify the DOCUMENTATION accordingly and add main()-level tests (fake
Bitwarden client + the ansible module harness) for both paths.

The get_item_by_id returns-or-raises contract is left for a separate PR.
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.

1 participant