Skip to content

Commit

Permalink
Merge pull request #14 from aptly-io/improve_version_check
Browse files Browse the repository at this point in the history
Improve version check
  • Loading branch information
aptly-io authored Jul 16, 2022
2 parents 1d8c4ed + 51c3182 commit 09ec715
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 21 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ jobs:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
nvm install 14.4.0
npm install -g [email protected]
nvm install 18.6.0
npm --version
npm i @bitwarden/cli@1.19.1
npm i @bitwarden/cli
PATH=$PATH:$GITHUB_WORKSPACE/node_modules/.bin
bw --version
python --version
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
node_modules/
package-lock.json
package.json
__pycache__/
.venv/
.venv_install_check/
Expand Down
3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ repos:
- id: trailing-whitespace
- id: end-of-file-fixer
- repo: https://github.com/psf/black
rev: "22.1.0"
rev: "22.6.0"
hooks:
- id: black
additional_dependencies: ['click==8.0.4']
- repo: local
hooks:
- id: pylint
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ This tool and its installation description can be found
[here](https://bitwarden.com/help/article/cli/#download-and-install).

```bash
npm install -g @bitwarden/cli@1.19.1
npm install -g @bitwarden/cli
```

```bash
Expand Down Expand Up @@ -126,6 +126,9 @@ export TEST_BW_CLIENT_SECRET=
export TEST_BW_MASTER_PASSWORD=
python -m pytest -s -vvv --cov=pwsync --cov-report=xml:cov.xml tests || echo "FAILED"

# or run a specific individual test
python -m pytest -s -vvv tests/test_bwc.py -k test_create_one_collection

# for distribution
# for the proper version to be generated, use the main branch with a tag like v0.1b5
python -m build
Expand Down Expand Up @@ -173,6 +176,7 @@ causes a create/delete modification!
To synchronize, `pwsync` depends on:
- The python [_diffsync_](https://pypi.org/project/diffsync/) module: determines the differences between two password databases.
- The python [_pykeepass_](https://pypi.org/project/pykeepass/) module: modifies a Keepass_ file.
- The python [_prompt-toolkit_](https://pypi.org/project/prompt-toolkit/) module
- Bitwarden's official(?) [_command line client_](https://bitwarden.com/help/article/cli/): modifies a Bitwarden online password database.

An curated dump of the console output is shown below:
Expand Down
12 changes: 7 additions & 5 deletions pwsync/bw_cli_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

# Bitwarden client 1.21.1 on MacOs has an issue with bw list items
# (https://github.com/bitwarden/cli/issues/490)
BW_SUPPORTED_VERSION = "1.19.1"
BW_SUPPORTED_VERSION_MAJOR = 2022

# Item Types. Used with the create command to specify a Vault item type:
USER_TYPE = 1 # a login item (has inside a login sub-type)
Expand Down Expand Up @@ -194,13 +194,15 @@ def _check_output(
self._logger.debug("cmd: %s, result: %s", cmd, result_json)
return json.loads(result_json)
except CalledProcessError as exc:
result_json = f"ret: {exc.returncode}, stdout: {exc.output}, stderr: {exc.stderr}"
out = exc.stdout.decode("utf-8") if exc.stdout is not None else "''"
err = exc.stderr.decode("utf-8") if exc.stderr is not None else "''"
result_json = f"ret: {exc.returncode}, stdout: {out}, stderr: {err}"
self._logger.error("cmd: %s, result: %s", cmd, result_json)
raise exc

@eet
def _get_status(self):
version = check_output(["bw", "--version"]).strip().decode("utf-8")
version = tuple(map(int, check_output(["bw", "--version"]).strip().decode("utf-8").split(".")))
status_obj = self._check_output(["bw", "--raw", "status"])
status = status_obj.get("status", "unauthenticated") # locked, unlocked, unauthenticated
user_id = status_obj.get("userId", "")
Expand All @@ -221,8 +223,8 @@ def _make_session(
):
status, user_id, version = self._get_status()

if version != BW_SUPPORTED_VERSION:
raise PwsUnsupported(f"Use bitwareden-cli {BW_SUPPORTED_VERSION}. {version} is not supported!")
if version[0] < BW_SUPPORTED_VERSION_MAJOR:
raise PwsUnsupported(f"Use bitwareden-cli {BW_SUPPORTED_VERSION_MAJOR}. {version} is not supported!")

if client_id != f"user.{user_id}" and status != "unauthenticated":
self.logout()
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
python_requires=">=3.7.0",
packages=find_packages(),
install_requires=[
"pykeepass==4.0.1",
"diffsync==1.4.2",
"prompt-toolkit==3.0.28",
"pykeepass==4.0.3",
"diffsync==1.6.0",
"prompt-toolkit==3.0.30",
],
extras_require={
"dev": [
Expand Down
8 changes: 0 additions & 8 deletions tests/test_kp_kp_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,40 +36,32 @@

@pytest.fixture(name="cli1")
def _cli1():
LOGGER.info("Setup cli1")
try:
remove(KP1_FILENAME)
except FileNotFoundError:
pass # maybe file did not exist
cli = KeepassDatabaseClient(KP1_FILENAME, KP1_PW)
yield cli
LOGGER.info("Teardown cli1")


@pytest.fixture(name="ds1")
def _ds1(cli1):
LOGGER.info("Setup ds1")
yield PasswordDataset(KP1_FILENAME, QUERY_INFO, cli1)
LOGGER.info("Teardown ds1")


@pytest.fixture(name="cli2")
def _cli2():
LOGGER.info("Setup cli2")
try:
remove(KP2_FILENAME)
except FileNotFoundError:
pass # maybe file did not exist
cli = KeepassDatabaseClient(KP2_FILENAME, KP2_PW)
yield cli
LOGGER.info("Teardown cli2")


@pytest.fixture(name="ds2")
def _ds2(cli2):
LOGGER.info("Setup ds2")
yield PasswordDataset(KP1_FILENAME, QUERY_INFO, cli2)
LOGGER.info("Teardown ds2")


@pytest.fixture(name="sync")
Expand Down

0 comments on commit 09ec715

Please sign in to comment.