Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests leave key in keyring #1639

Open
wants to merge 38 commits into
base: master
Choose a base branch
from

Conversation

ganeshrevadi
Copy link
Contributor

@ganeshrevadi ganeshrevadi commented Mar 9, 2023

Adding remove password abstract method in abc.py and implementing in secretstorage.py.
@real-yfprojects

@ganeshrevadi ganeshrevadi changed the title Adding remove password Tests leave key in keyring Mar 9, 2023
Copy link
Collaborator

@real-yfprojects real-yfprojects left a comment

Choose a reason for hiding this comment

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

Looking good! Next up would be KWallet. We use the dbus daemon exposed by KWallet. Refer to the Qt DBus docs how to use dbus via qt. You will have to do some research to find a documentation of set kwallet daemon.

src/vorta/keyring/secretstorage.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@real-yfprojects real-yfprojects left a comment

Choose a reason for hiding this comment

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

Great, it works. Where did you find the removeEntry dbus method? Next up would be MacOS support which is quite hard without access to a Mac. We use the PyObj-C bridge allowing access to MacOS native libraries. You can refer to the apple developer docs.

src/vorta/keyring/kwallet.py Outdated Show resolved Hide resolved
@m3nu
Copy link
Contributor

m3nu commented Mar 12, 2023

I'll try macOS today.

@m3nu
Copy link
Contributor

m3nu commented Mar 12, 2023

Added for macOS:

In [1]: from vorta.keyring import darwin

In [2]: k = darwin.VortaDarwinKeyring()

In [3]: k.get_password('vorta', 'google.com')

In [4]: k.set_password('vorta', 'google.com', 'asdf')

In [5]: k.get_password('vorta', 'google.com')
Out[5]: 'asdf'

In [6]: k.remove_password('vorta', 'google.com')

In [7]: k.get_password('vorta', 'google.com')

In [8]: 

@real-yfprojects
Copy link
Collaborator

That's bad you just removed the commits containing MacOS support.

@ganeshrevadi
Copy link
Contributor Author

That's bad you just removed the commits containing MacOS support.

Hey I'm really sorry how can this be fixed now?

@m3nu
Copy link
Contributor

m3nu commented Mar 12, 2023

Rebased and pushed it again.

Please be careful with force-push and use it only when really needed.

@real-yfprojects
Copy link
Collaborator

And when you do use --force-with-lease.

@ganeshrevadi
Copy link
Contributor Author

And when you do use --force-with-lease.

when you update a branch changed by other people

@ganeshrevadi
Copy link
Contributor Author

ganeshrevadi commented Mar 13, 2023

should remove_password next implemented in db.py?

@m3nu
Copy link
Contributor

m3nu commented Mar 13, 2023

For macOS-related stuff it's needed because some libraries aren't available on linux (pyobjc).

In this case it could be due to circular dependencies. Needs to be reviewed. If no issues, put it at the start of the file, where it belongs.

@ganeshrevadi
Copy link
Contributor Author

For macOS-related stuff it's needed because some libraries aren't available on linux (pyobjc).

In this case it could be due to circular dependencies. Needs to be reviewed. If no issues, put it at the start of the file, where it belongs.

I tried adding it above but its failing the pre-commit run!

@real-yfprojects
Copy link
Collaborator

I tried adding it above but its failing the pre-commit run!

As always, nobody can help you if you just say that it failed. You will have to provide more details. The error/complaint message is a minimum.

@ganeshrevadi
Copy link
Contributor Author

I have imported the RepoPassword at beginning of the file and it works fine and sorry for the lack of info in above comment.

@ganeshrevadi
Copy link
Contributor Author

Not quite.

  • The keyring instance you create in the fixture isn't used in the test and Vorta will always make its own.
  • You wouldn't need to remove the password inside tests, if the fixture was working. keyring.remove_password('vorta-repo', test_repo_url)
  • Your fixture runs at the module level. So all tests in one file would use the same password and remove it??

So what you need is this:

  • Fixture that runs again for each test
  • Fixture that returns some random repo URL and random password for testing, as we do in some places: test_repo_url = f'vorta-test-repo.{uuid.uuid4()}.com:repo' # Random repo URL to avoid macOS keychain and password = str(uuid.uuid4())
  • The repo URL and password are then used during testing
  • After each test function the password for the test repo is removed again.

This should be more clear and deduplicates some more code (creating a random repo URL and password)

One more thing: vorta-test-repo.{uuid.uuid4()}.com:repo would give a SFTP-style URL that's not supported in the future. Best if you change it to ssh:// format.

This means that the repo url and password that are generated in the test has to be removed and only to be generated in the fixture and then used in multiple tests . Same question for remove_password ?

@m3nu
Copy link
Contributor

m3nu commented Mar 25, 2023

Repo URL and password are generated by the fixture. The password manager entry is also removed by the fixture during cleanup.

@ganeshrevadi
Copy link
Contributor Author

@m3nu I've tried implementing pytest fixture as per your suggestion , but the tests are failing. Need some help here!

@@ -116,8 +110,6 @@ def test_repo_add_success(qapp, qtbot, mocker, borg_json_output, keyring_fixture
keyring = VortaKeyring.get_keyring()
assert keyring.get_password("vorta-repo", RepoModel.get(id=2).url) == LONG_PASSWORD
Copy link
Contributor Author

Choose a reason for hiding this comment

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

gives me a assertion error here.

Copy link
Contributor

Choose a reason for hiding this comment

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

In that case you should debug the test and see why it fails. Looking at the compared values would be a first good step.

@m3nu m3nu mentioned this pull request Apr 17, 2023
9 tasks
@real-yfprojects real-yfprojects linked an issue Jun 27, 2023 that may be closed by this pull request
@real-yfprojects real-yfprojects mentioned this pull request Jun 27, 2023
9 tasks
@stale
Copy link

stale bot commented Jul 19, 2023

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the wontfix label Jul 19, 2023
@real-yfprojects
Copy link
Collaborator

Are you still working on this @ganeshrevadi? This would be a big quality of life improvement for developers.

@ganeshrevadi
Copy link
Contributor Author

@real-yfprojects Hey I'm currently not working on this!

@real-yfprojects real-yfprojects added good first issue Simple change to start learning code base help wanted This issue is available, comment if you want to fix it and removed wontfix good first issue Simple change to start learning code base labels Jul 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted This issue is available, comment if you want to fix it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tests leave key in keyring.
3 participants