Merge branch 'main' into implement_room_upgrade

This commit is contained in:
kegsay 2022-04-04 14:25:36 +01:00 committed by GitHub
commit 4e0000f0a1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 2 deletions

View file

@ -94,4 +94,4 @@ For more general questions please use
We ask that everyone who contributes to the project signs off their We ask that everyone who contributes to the project signs off their
contributions, in accordance with the contributions, in accordance with the
[DCO](https://github.com/matrix-org/matrix-doc/blob/main/CONTRIBUTING.rst#sign-off). [DCO](https://github.com/matrix-org/matrix-spec/blob/main/CONTRIBUTING.rst#sign-off).

View file

@ -169,7 +169,7 @@ func (r *uploadRequest) doUpload(
} }
// Check if temp file size exceeds max file size configuration // Check if temp file size exceeds max file size configuration
if bytesWritten > types.FileSizeBytes(*cfg.MaxFileSizeBytes) { if *cfg.MaxFileSizeBytes > 0 && bytesWritten > types.FileSizeBytes(*cfg.MaxFileSizeBytes) {
fileutils.RemoveDir(tmpDir, r.Logger) // delete temp file fileutils.RemoveDir(tmpDir, r.Logger) // delete temp file
return requestEntityTooLargeJSONResponse(*cfg.MaxFileSizeBytes) return requestEntityTooLargeJSONResponse(*cfg.MaxFileSizeBytes)
} }

View file

@ -36,6 +36,7 @@ func Test_uploadRequest_doUpload(t *testing.T) {
} }
maxSize := config.FileSizeBytes(8) maxSize := config.FileSizeBytes(8)
unlimitedSize := config.FileSizeBytes(0)
logger := log.New().WithField("mediaapi", "test") logger := log.New().WithField("mediaapi", "test")
testdataPath := filepath.Join(wd, "./testdata") testdataPath := filepath.Join(wd, "./testdata")
@ -117,6 +118,27 @@ func Test_uploadRequest_doUpload(t *testing.T) {
}, },
want: requestEntityTooLargeJSONResponse(maxSize), want: requestEntityTooLargeJSONResponse(maxSize),
}, },
{
name: "upload ok with unlimited filesize",
args: args{
ctx: context.Background(),
reqReader: strings.NewReader("test test test"),
cfg: &config.MediaAPI{
MaxFileSizeBytes: &unlimitedSize,
BasePath: config.Path(testdataPath),
AbsBasePath: config.Path(testdataPath),
DynamicThumbnails: false,
},
db: db,
},
fields: fields{
Logger: logger,
MediaMetadata: &types.MediaMetadata{
MediaID: "1339",
UploadName: "test fail",
},
},
},
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {