MM-50419: Fix panic at interface conversion (#22284)

We were incorrectly returning a subset of the methods,
whereas at other places, clients needed access to other
interfaces as well.

https://mattermost.atlassian.net/browse/MM-50419

```release-note
NONE
```
Этот коммит содержится в:
Agniva De Sarker
2023-02-09 20:07:23 +05:30
коммит произвёл GitHub
родитель e325f3fa1c
Коммит 0880837fd0
2 изменённых файлов: 22 добавлений и 12 удалений

Просмотреть файл

@@ -57,6 +57,11 @@ var (
imageMimeTypes = map[string]string{".jpg": "image/jpeg", ".jpeg": "image/jpeg", ".gif": "image/gif", ".bmp": "image/bmp", ".png": "image/png", ".tiff": "image/tiff", ".tif": "image/tif"}
)
var (
// Ensure that the ReaderAt interface is implemented.
_ io.ReaderAt = (*s3WithCancel)(nil)
)
func isFileExtImage(ext string) bool {
ext = strings.ToLower(ext)
return imageExtensions[ext]
@@ -208,7 +213,7 @@ func (b *S3FileBackend) MakeBucket() error {
// s3WithCancel is a wrapper struct which cancels the context
// when the object is closed.
type s3WithCancel struct {
io.ReadSeekCloser
*s3.Object
timer *time.Timer
cancel context.CancelFunc
}
@@ -216,7 +221,7 @@ type s3WithCancel struct {
func (sc *s3WithCancel) Close() error {
sc.timer.Stop()
sc.cancel()
return sc.ReadSeekCloser.Close()
return sc.Object.Close()
}
// CancelTimeout attempts to cancel the timeout for this reader. It allows calling
@@ -237,9 +242,9 @@ func (b *S3FileBackend) Reader(path string) (ReadCloseSeeker, error) {
}
sc := &s3WithCancel{
ReadSeekCloser: minioObject,
timer: time.AfterFunc(b.timeout, cancel),
cancel: cancel,
Object: minioObject,
timer: time.AfterFunc(b.timeout, cancel),
cancel: cancel,
}
return sc, nil

Просмотреть файл

@@ -10,7 +10,6 @@ import (
"encoding/base64"
"errors"
"fmt"
"io"
"net/http/httptest"
"net/http/httputil"
"net/url"
@@ -19,6 +18,7 @@ import (
"testing"
"time"
s3 "github.com/minio/minio-go/v7"
"github.com/stretchr/testify/require"
)
@@ -283,20 +283,25 @@ func TestS3WithCancel(t *testing.T) {
})
}
func newMockS3WithCancel(timeout time.Duration, closeErr error) (*s3WithCancel, context.Context) {
func newMockS3WithCancel(timeout time.Duration, closeErr error) (*fauxCloser, context.Context) {
ctx, cancel := context.WithCancel(context.Background())
return &s3WithCancel{
ReadSeekCloser: fauxCloser{strings.NewReader("testdata"), closeErr},
timer: time.AfterFunc(timeout, cancel),
cancel: cancel,
return &fauxCloser{
s3WithCancel: &s3WithCancel{
Object: &s3.Object{},
timer: time.AfterFunc(timeout, cancel),
cancel: cancel,
},
closeErr: closeErr,
}, ctx
}
type fauxCloser struct {
io.ReadSeeker
*s3WithCancel
closeErr error
}
func (fc fauxCloser) Close() error {
fc.s3WithCancel.timer.Stop()
fc.s3WithCancel.cancel()
return fc.closeErr
}