Skip to content

Commit 2a1ca53

Browse files
committed
updated
1 parent 4eb53a6 commit 2a1ca53

5 files changed

Lines changed: 21 additions & 13 deletions

File tree

config.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
basedir = os.path.abspath(os.path.dirname(__file__))
1111
load_dotenv(os.path.join(basedir, '.env'))
1212
LOCAL_SECRET_KEY_PATH = os.path.join(basedir, 'database', '.finora_secret_key')
13-
LOCAL_SECRET_KEY_PREFIX = 'finora-key:v1:'
13+
LOCAL_SECRET_KEY_PREFIX = 'finora-local:v1:' # nosec B105
14+
LEGACY_LOCAL_SECRET_KEY_PREFIX = 'finora-key:v1:' # nosec B105
1415
DEFAULT_UPDATE_MANIFEST_PATH = os.path.join(basedir, 'updates', 'manifest.json')
1516

1617

@@ -47,10 +48,16 @@ def _decrypt_persisted_local_secret(persisted_value):
4748
persisted_value = (persisted_value or '').strip()
4849
if not persisted_value:
4950
return ''
50-
if not persisted_value.startswith(LOCAL_SECRET_KEY_PREFIX):
51+
matched_prefix = None
52+
for prefix in (LOCAL_SECRET_KEY_PREFIX, LEGACY_LOCAL_SECRET_KEY_PREFIX):
53+
if persisted_value.startswith(prefix):
54+
matched_prefix = prefix
55+
break
56+
57+
if matched_prefix is None:
5158
return persisted_value
5259

53-
encrypted_payload = persisted_value[len(LOCAL_SECRET_KEY_PREFIX):].encode('utf-8')
60+
encrypted_payload = persisted_value[len(matched_prefix):].encode('utf-8')
5461
decrypted_secret = _get_local_secret_cipher().decrypt(encrypted_payload)
5562
return decrypted_secret.decode('utf-8')
5663

services/update_service.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,8 @@ def _run_database_upgrade(app):
381381
target_root = _get_update_target_root(app)
382382
environment = _build_upgrade_environment(app)
383383

384-
# nosec B603,B607 - fixed interpreter command with sanitized cwd and environment.
385-
result = subprocess.run( # nosec
384+
# Fixed interpreter command with sanitized cwd and environment.
385+
result = subprocess.run( # nosec B603,B607
386386
[sys.executable, '-m', 'flask', 'db', 'upgrade'],
387387
cwd=target_root,
388388
env=environment,

tests/test_ci_coverage_support.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,7 @@ def exception(self, *args):
110110
assert mail_service.send_email(app, '', 'Assunto', 'Corpo')['reason'] == 'missing_recipient'
111111
assert mail_service.send_email(app, 'dest@example.com', 'Assunto', 'Corpo')['delivery'] == 'log'
112112
assert 'info' in logged
113-
_message, *payload = logged['info']
114-
assert payload[-1] == len('Corpo')
113+
assert logged['info'][-1] == len('Corpo')
115114

116115
class FakeSMTP:
117116
def __init__(self, *_args, **_kwargs):

tests/test_update_service_phase8.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,10 @@ def test_apply_update_restores_backup_when_upgrade_fails(app, tmp_path, monkeypa
147147
},
148148
)
149149

150-
monkeypatch.setattr(
151-
update_service,
152-
'_run_database_upgrade',
153-
lambda _app: (_ for _ in ()).throw(RuntimeError('migration failed')),
154-
)
150+
def raise_migration_failed(_app):
151+
raise RuntimeError('migration failed')
152+
153+
monkeypatch.setattr(update_service, '_run_database_upgrade', raise_migration_failed)
155154

156155
app.config['UPDATE_MANIFEST_URL'] = str(manifest_path)
157156
app.config['UPDATE_TARGET_ROOT'] = str(target_root)

tests/test_validation_and_schema_round8.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,5 +159,8 @@ def flaky_operation():
159159

160160
def test_run_idempotent_db_operation_does_not_hide_non_retryable_errors(app):
161161
with app.app_context():
162+
def failing_operation():
163+
raise RuntimeError('boom')
164+
162165
with pytest.raises(RuntimeError):
163-
run_idempotent_db_operation(lambda: (_ for _ in ()).throw(RuntimeError('boom')))
166+
run_idempotent_db_operation(failing_operation)

0 commit comments

Comments
 (0)