Skip to content

Unify bitwarden plugin family + unit tests#265

Merged
markuslf merged 1 commit into
mainfrom
refactor/plugins-bitwarden
May 25, 2026
Merged

Unify bitwarden plugin family + unit tests#265
markuslf merged 1 commit into
mainfrom
refactor/plugins-bitwarden

Conversation

@markuslf
Copy link
Copy Markdown
Member

Phase 3 of the plugin unification effort: the bitwarden family (lookup, module, module_util). Vendored plugins remain untouched.

Style unification (no behavior change)

  • Standard Linuxfabrik file header, from __future__ + __metaclass__, single quotes, f-strings throughout (replacing % and .format()).
  • module_utils/bitwarden.py: modern ansible.module_utils.common.text.converters instead of the deprecated _text, drop the (object) base class.

Safe fixes

  • Lookup DOCUMENTATION fixed so ansible-doc -t lookup linuxfabrik.lfops.bitwarden_item renders again (a description bullet contained a colon that YAML parsed as a mapping; pre-existing on main).
  • Module: fail_json(msg=...) instead of positional first arg; replace a try/except IndexError with an explicit check.
  • module_util: corrected the misleading get_item_by_id docstring; # nosec on the /tmp cache fallback (files are created via mkstemp mode 0600 + atomic replace) and the password charset default (it is an alphabet, not a password).
  • Removed a dead commented-out example block from the lookup.

Deliberately deferred (separate, individually tested PRs)

  • check_mode is declared but the module still writes to the vault under --check.
  • a None password overwrites an existing password.
  • get_item_by_id returns-or-raises contract mismatch with the lookup.

Tests

  • tests/unit/plugins/module_utils/test_bitwarden.py (generate, get_pretty_name, _api_call success/failure/HTTP-error/bad-JSON, get_items filtering).
  • tests/unit/plugins/modules/test_bitwarden_item.py (diff_and_update).
  • tests/unit/plugins/lookup/test_bitwarden_item.py (run paths, multiple-match error, lookup-by-id).
  • tests/conftest.py makes this checkout importable as ansible_collections.linuxfabrik.lfops, so module/lookup tests resolve their collection imports under plain pytest/tox. --import-mode=importlib allows same-named test files across plugin-type dirs. bandit no longer scans tests/ (fixture passwords are expected).

Validation

  • Full tox matrix green (35 tests across 13 envs).
  • ansible-doc renders both the lookup and the module.
  • pre-commit (incl. bandit, vulture, pytest) green.

CONTRIBUTING

Documents the canonical plugin header and the conftest collection-import mechanism for tests.

Next: uptimerobot family (Phase 4), then nextcloud/sqlite/gpg_key/ipa_diff (Phase 5). A small separate PR will fix the remaining ansible-doc rendering bugs (nextcloud_occ_app_config/system_config, uptimerobot_monitor/psp) and add a regression guard.

Bring the bitwarden lookup, module and module_util to the standard
plugin style (header, f-strings, single quotes, modern
ansible.module_utils.common.text.converters) without changing behavior.

Safe fixes only:
- fix the lookup DOCUMENTATION so ansible-doc renders it again
- module: fail_json(msg=...) instead of positional, drop dead try/except
- module_util: drop the (object) base, correct get_item_by_id docstring,
  nosec the /tmp cache fallback and the charset default (false positives)
- remove the dead commented example block from the lookup

Behaviour-changing bugs (check_mode mutation, None-password overwrite,
get_item_by_id returns-or-raises contract) are intentionally left for
separate, individually tested fixes.

Add unit tests for the family plus tests/conftest.py, which makes this
checkout importable as ansible_collections.linuxfabrik.lfops so
module/lookup tests resolve their collection imports under pytest/tox.
Exclude tests/ from bandit (fixture passwords are expected).
@markuslf markuslf requested a review from NavidSassan May 25, 2026 07:31
@markuslf markuslf merged commit f2dd3f2 into main May 25, 2026
11 checks passed
ebuerki-lf pushed a commit that referenced this pull request May 26, 2026
Bring the bitwarden lookup, module and module_util to the standard
plugin style (header, f-strings, single quotes, modern
ansible.module_utils.common.text.converters) without changing behavior.

Safe fixes only:
- fix the lookup DOCUMENTATION so ansible-doc renders it again
- module: fail_json(msg=...) instead of positional, drop dead try/except
- module_util: drop the (object) base, correct get_item_by_id docstring,
  nosec the /tmp cache fallback and the charset default (false positives)
- remove the dead commented example block from the lookup

Behaviour-changing bugs (check_mode mutation, None-password overwrite,
get_item_by_id returns-or-raises contract) are intentionally left for
separate, individually tested fixes.

Add unit tests for the family plus tests/conftest.py, which makes this
checkout importable as ansible_collections.linuxfabrik.lfops so
module/lookup tests resolve their collection imports under pytest/tox.
Exclude tests/ from bandit (fixture passwords are expected).
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