fix: verify OSS objects before serving

This commit is contained in:
richjohnrambo
2026-09-09 16:28:56 +08:00
parent c3e5cc0831
commit cae5039afe
2 changed files with 60 additions and 10 deletions
+12
View File
@@ -1,9 +1,12 @@
package oss
import (
"net/http"
"testing"
"time"
aliyunoss "github.com/aliyun/aliyun-oss-go-sdk/oss"
"github.com/tinode/chat/server/store"
"github.com/tinode/chat/server/store/types"
)
@@ -46,6 +49,15 @@ func TestGetIdFromUrl(t *testing.T) {
}
}
func TestIsOSSObjectNotFound(t *testing.T) {
if !isOSSObjectNotFound(aliyunoss.ServiceError{StatusCode: http.StatusNotFound, Code: "NoSuchKey"}) {
t.Fatal("NoSuchKey should be treated as missing object")
}
if isOSSObjectNotFound(aliyunoss.ServiceError{StatusCode: http.StatusForbidden, Code: "AccessDenied"}) {
t.Fatal("AccessDenied must not be treated as missing object")
}
}
func TestLoadSysConfig(t *testing.T) {
original := store.ThirdPartyConfig
store.ThirdPartyConfig = fakeThirdPartyConfig{