mirror of
https://github.com/PR0M3TH3AN/SeedPass.git
synced 2026-11-06 04:42:35 +00:00
Fix index verification for TOTP in modify entry test
The test `test_modify_entry_invalid_fields` was hardcoding `index = 0` for TOTP entries because `add_totp` returns a URI string instead of an index. This change unifies the index determination logic by calling `entry_manager.get_next_index()` before adding the entry. This ensures the correct index is verified for all entry types, including TOTP. Modified: - src/tests/test_modify_entry_validation.py: Use get_next_index() for dynamic index determination. Co-authored-by: PR0M3TH3AN <[email protected]>
This commit is contained in:
1 parent
88781479aa
commit
29b955c913
2 files changed
+4
-63
No files matched your search
@@ -81,17 +81,10 @@ def test_modify_entry_invalid_fields(
|
|||||||
):
|
):
|
||||||
"""Test that modify_entry raises ValueError for invalid fields based on EntryType."""
|
"""Test that modify_entry raises ValueError for invalid fields based on EntryType."""
|
||||||
# Setup entry
|
# Setup entry
|
||||||
if entry_type == EntryType.TOTP:
|
# Some setup functions return the index, but add_totp returns a URI string.
|
||||||
# add_totp returns a URI string, need to fix the index manually or check implementation
|
# To be consistent and verify the index, we get it before calling setup_func.
|
||||||
# Checking implementation: add_totp returns URI string, but index is predictable (0)
|
index = entry_manager.get_next_index()
|
||||||
# However, we should verify the index.
|
setup_func(entry_manager)
|
||||||
# For simplicity, we assume index 0 as it's the first entry.
|
|
||||||
setup_func(entry_manager)
|
|
||||||
index = 0
|
|
||||||
elif entry_type == EntryType.PASSWORD:
|
|
||||||
index = setup_func(entry_manager)
|
|
||||||
else:
|
|
||||||
index = setup_func(entry_manager)
|
|
||||||
|
|
||||||
# Verify entry exists and has correct type
|
# Verify entry exists and has correct type
|
||||||
entry = entry_manager.retrieve_entry(index)
|
entry = entry_manager.retrieve_entry(index)
|
||||||
|
|||||||
@@ -1,52 +0,0 @@
|
|||||||
import sys
|
|
||||||
import os
|
|
||||||
from unittest.mock import MagicMock
|
|
||||||
from fastapi.testclient import TestClient
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
# Add src to sys.path
|
|
||||||
sys.path.insert(0, os.path.abspath("src"))
|
|
||||||
|
|
||||||
# Mock seedpass.api._pm before importing api
|
|
||||||
import seedpass.api
|
|
||||||
|
|
||||||
seedpass.api._pm = MagicMock()
|
|
||||||
# No need to mock is_valid_filename now as I check inline
|
|
||||||
seedpass.api._token = "testtoken" # Set a dummy token
|
|
||||||
|
|
||||||
from seedpass.api import app
|
|
||||||
|
|
||||||
client = TestClient(app)
|
|
||||||
|
|
||||||
|
|
||||||
def test_fix():
|
|
||||||
evil_path = "/tmp/evil_file"
|
|
||||||
response = client.post(
|
|
||||||
"/api/v1/vault/backup-parent-seed",
|
|
||||||
json={"path": evil_path},
|
|
||||||
headers={"Authorization": "Bearer testtoken"},
|
|
||||||
)
|
|
||||||
|
|
||||||
assert response.status_code == 400, f"Expected 400, got {response.status_code}"
|
|
||||||
assert response.json() == {"detail": "Invalid filename"}
|
|
||||||
|
|
||||||
# Check that handle_backup_reveal_parent_seed was NOT called
|
|
||||||
seedpass.api._pm.handle_backup_reveal_parent_seed.assert_not_called()
|
|
||||||
print("Fix verified: Rejected arbitrary path.")
|
|
||||||
|
|
||||||
# Test valid filename
|
|
||||||
valid_file = "backup.enc"
|
|
||||||
response = client.post(
|
|
||||||
"/api/v1/vault/backup-parent-seed",
|
|
||||||
json={"path": valid_file},
|
|
||||||
headers={"Authorization": "Bearer testtoken"},
|
|
||||||
)
|
|
||||||
assert response.status_code == 200, f"Expected 200, got {response.status_code}"
|
|
||||||
seedpass.api._pm.handle_backup_reveal_parent_seed.assert_called_with(
|
|
||||||
Path(valid_file)
|
|
||||||
)
|
|
||||||
print("Fix verified: Accepted valid filename.")
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
test_fix()
|
|
||||||
Reference in new issue
Block a user