Merge pull request #12803 from SergeTupchiy/EMQX-11808-remove-uploaded-invalid-backups-5.6.1

fix(emqx_mgmt_data_backup): remove an uploaded backup file if it's not valid (5.6.1 port)
This commit is contained in:
SergeTupchiy 2024-03-28 15:37:10 +02:00 committed by GitHub
commit 93c87fcb25
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 9 additions and 2 deletions

View File

@ -2,7 +2,7 @@
{application, emqx_management, [
{description, "EMQX Management API and CLI"},
% strict semver, bump manually!
{vsn, "5.1.0"},
{vsn, "5.1.1"},
{modules, []},
{registered, [emqx_management_sup]},
{applications, [

View File

@ -315,8 +315,10 @@ do_upload(BackupFileNameStr, BackupFileContent) ->
catch
error:{badmatch, {error, Reason}}:Stack ->
?SLOG(error, #{msg => "emqx_data_upload_failed", reason => Reason, stacktrace => Stack}),
_ = file:delete(FilePath),
{error, Reason};
Class:Reason:Stack ->
_ = file:delete(FilePath),
?SLOG(error, #{
msg => "emqx_data_upload_failed",
exception => Class,

View File

@ -199,7 +199,11 @@ upload_backup_test(Config, BackupName) ->
?assertEqual(ok, upload_backup(?NODE3_PORT, Auth, UploadFile)),
%% This file was specially forged to pass upload validation bat fail on import
?assertEqual(ok, upload_backup(?NODE2_PORT, Auth, BadImportFile)),
?assertEqual({error, bad_request}, upload_backup(?NODE1_PORT, Auth, BadUploadFile)).
?assertEqual({error, bad_request}, upload_backup(?NODE1_PORT, Auth, BadUploadFile)),
%% Invalid file must not be kept
?assertMatch(
{error, {_, 404, _}}, backup_file_op(get, ?NODE1_PORT, Auth, ?BAD_UPLOAD_BACKUP, [])
).
import_backup_test(Config, BackupName) ->
Auth = ?config(auth, Config),

View File

@ -0,0 +1 @@
Do not save invalid uploaded backup files.