Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added keepassx/__pycache__/__init__.cpython-311.pyc
Binary file not shown.
Binary file added keepassx/__pycache__/clipboard.cpython-311.pyc
Binary file not shown.
Binary file added keepassx/__pycache__/db.cpython-311.pyc
Binary file not shown.
Binary file added keepassx/__pycache__/main.cpython-311.pyc
Binary file not shown.
16 changes: 11 additions & 5 deletions keepassx/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,24 @@ def do_list(args):
def do_get(args):
db = create_db(args)
try:
entry = _search_for_entry(db, args.entry_id)[0]
entries = _search_for_entry(db, args.entry_id)
if args.category:
entries = [entry for entry in entries if entry.group.group_name == args.category]
if not entries:
raise EntryNotFoundError("No entries found in the specified category.")
entry = entries[0]
except EntryNotFoundError as e:
sys.stderr.write(str(e))
sys.stderr.write("\n")
return

default_fields = ['title', 'username', 'url', 'notes']
if args.entry_fields:
fields = args.entry_fields
else:
fields = default_fields
fields = args.entry_fields if args.entry_fields else default_fields

sys.stderr.write('\n')
for field in fields:
print("%-10s %s" % (field + ':', getattr(entry, field)))

if args.clipboard_copy:
clipboard.copy(entry.password)
sys.stderr.write("\nPassword has been copied to clipboard.\n")
Expand Down Expand Up @@ -160,6 +165,7 @@ def create_parser():
get_parser.add_argument('-n', '--no-clipboard-copy', action="store_false",
dest="clipboard_copy", default=True,
help="Don't copy the password to the clipboard")
get_parser.add_argument('-c', '--category', help='Specify the category of the entry.')
get_parser.set_defaults(run=do_get)
return parser

Expand Down
Binary file added tests/__pycache__/test_cli.cpython-311.pyc
Binary file not shown.
Binary file added tests/__pycache__/test_clipboard.cpython-311.pyc
Binary file not shown.
Binary file added tests/__pycache__/test_config.cpython-311.pyc
Binary file not shown.
Binary file added tests/__pycache__/test_keepassx.cpython-311.pyc
Binary file not shown.
32 changes: 32 additions & 0 deletions tests/test_keepassx.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,38 @@ def test_master_password_unicode(self):
# Verify we can read anything from the db.
self.assertEqual(len(db.groups), 2)

def test_get_entry_with_category(self):
kdb_contents = open_data_file('password.kdb').read()
db = Database(kdb_contents, self.password)

# Create a "Backup" group explicitly for testing
backup_group = type('Group', (object,), {
'group_name': 'Backup',
'groupid': 999999,
'level': 0
})
db.groups.append(backup_group)

# Add an entry to the Backup category for testing
db.entries.append(
type('Entry', (object,), {
'title': 'backup_entry',
'uuid': 'backup_uuid',
'group': backup_group,
'username': 'backup_user',
'password': 'backup_pass',
'url': 'backup_url',
'notes': 'backup_notes',
'creation_time': datetime.now()
})
)

# Test retrieval with category filtering
entries = [entry for entry in db.entries if entry.group.group_name == 'Backup']
self.assertEqual(len(entries), 1)
self.assertEqual(entries[0].title, 'backup_entry')
self.assertEqual(entries[0].password, 'backup_pass')


class TestEncodePassword(unittest.TestCase):
def test_encode_ascii(self):
Expand Down