增加短信渠道
This commit is contained in:
@@ -16,7 +16,7 @@ func ReadRuntime(db *gorm.DB) ([]runtimeconfig.Config, error) {
|
||||
}
|
||||
var rows []ConfigPO
|
||||
if err := db.Session(&gorm.Session{NewDB: true}).
|
||||
Where("kind IN ?", []string{"mq", "websocket"}).
|
||||
Where("kind IN ?", []string{"mq", "websocket", "sms"}).
|
||||
Order("kind ASC, provider ASC").
|
||||
Find(&rows).Error; err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, err
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
package integration
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
biz "kra/internal/biz/integration"
|
||||
"kra/internal/integration/runtimeconfig"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSMSSecretsSurviveMaskedSaveAndRuntimeReload(t *testing.T) {
|
||||
db, err := openWithDriver("sqlite", "file:"+t.Name()+"?mode=memory&cache=shared")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = db.AutoMigrate(&ConfigPO{}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
p := &integrationRuntimeTestProvider{Data: &Data{gormDB: newReloadableDB(db)}, store: runtimeconfig.NewStore()}
|
||||
repo := NewIntegrationConfigRepo(p)
|
||||
for _, provider := range []string{"aliyun", "tencent"} {
|
||||
values := biz.DefaultIntegrationConfig("sms", provider)
|
||||
for k, v := range values {
|
||||
if v == "" {
|
||||
values[k] = "test-" + k
|
||||
}
|
||||
}
|
||||
raw, _ := json.Marshal(values)
|
||||
if err = repo.SaveIntegrationConfig(context.Background(), &biz.IntegrationConfig{Kind: "sms", Provider: provider, Enabled: true, Values: raw}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
masked, err := repo.FindIntegrationConfig(context.Background(), "sms", provider)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var public map[string]string
|
||||
_ = json.Unmarshal(masked.Values, &public)
|
||||
for k := range values {
|
||||
if biz.IsIntegrationSecretKey(k) && public[k] != "******" {
|
||||
t.Fatalf("unmasked key %s", k)
|
||||
}
|
||||
}
|
||||
if err = repo.SaveIntegrationConfig(context.Background(), masked); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
rows, err := ReadRuntime(db)
|
||||
if err != nil || len(rows) != 2 {
|
||||
t.Fatalf("runtime rows=%d error=%v", len(rows), err)
|
||||
}
|
||||
for _, row := range rows {
|
||||
var values map[string]string
|
||||
_ = json.Unmarshal(row.Values, &values)
|
||||
key := "access_key_secret"
|
||||
if row.Provider == "tencent" {
|
||||
key = "secret_key"
|
||||
}
|
||||
if values[key] != "test-"+key {
|
||||
t.Fatal("saved secret did not survive runtime reload")
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user