fix(storage): align default provider fallback with STORAGE_ALLOW_LIST

Extract storage allowlist into internal/storageallowlist so KB creation
uses FirstAllowed when tenant default_provider is empty or disallowed.
Share pickUsableStorageProvider via editorResources for consistent UI
selection, and add regression tests for OBS status and allow-list defaults.
This commit is contained in:
wizardchen
2026-07-15 10:57:32 +08:00
committed by lyingbug
parent 97490ef7ed
commit 139ec1e6b8
10 changed files with 288 additions and 87 deletions
@@ -0,0 +1,40 @@
package storageallowlist
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestAllowedMap_DefaultAllowsAll(t *testing.T) {
t.Setenv(AllowListEnv, "")
allowed := AllowedMap()
for _, provider := range Supported() {
assert.True(t, allowed[provider], provider)
}
}
func TestAllowedMap_RespectsEnv(t *testing.T) {
t.Setenv(AllowListEnv, "minio,cos")
allowed := AllowedMap()
assert.True(t, allowed["minio"])
assert.True(t, allowed["cos"])
assert.False(t, allowed["local"])
assert.False(t, allowed["obs"])
}
func TestFirstAllowed(t *testing.T) {
t.Setenv(AllowListEnv, "minio")
assert.Equal(t, "minio", FirstAllowed())
}
func TestAllowedList(t *testing.T) {
t.Setenv(AllowListEnv, "obs,minio")
assert.Equal(t, []string{"minio", "obs"}, AllowedList())
}
func TestIsAllowed_EmptyProvider(t *testing.T) {
t.Setenv(AllowListEnv, "minio")
require.True(t, IsAllowed(""))
}