feat: expand companion platform, device controls, and memoir workflows
ci / verify (push) Canceled after 0s
ci / verify (push) Canceled after 0s
Add customer and operator login, BLE provisioning, device fleet controls, call memory, memoir generation, and refreshed family and maintenance portals. Include API contracts, migrations, firmware sources, tests, assets, and deployment documentation.
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestTencentCaptchaFile(t *testing.T) {
|
||||
valid := `{"secret_id":"test-id","secret_key":"test-key","saas":{"captcha_app_id":"123","app_secret_key":"abcdefghijklmnop"},"mini_program":{"captcha_app_id":"456","app_secret_key":"qrstuvwxyz123456"}}`
|
||||
for _, tc := range []struct {
|
||||
name, raw string
|
||||
ok bool
|
||||
}{
|
||||
{"valid", valid, true}, {"empty", `{}`, true}, {"BOM", "\xef\xbb\xbf" + valid, true},
|
||||
{"partial", `{"secret_id":"test-id"}`, false}, {"unknown", `{"secret_token":"do-not-leak"}`, false},
|
||||
{"same-id", strings.ReplaceAll(valid, `"456"`, `"123"`), false},
|
||||
{"bad-id", strings.ReplaceAll(valid, `"123"`, `"not-numeric"`), false},
|
||||
{"trailing", valid + `{}`, false}, {"oversize", strings.Repeat("x", 16385), false},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
path := filepath.Join(t.TempDir(), "captcha.json")
|
||||
if err := os.WriteFile(path, []byte(tc.raw), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Setenv("TENCENT_CAPTCHA_CONFIG_FILE", path)
|
||||
var c OnboardingConfig
|
||||
err := c.loadTencentCaptchaFile("api")
|
||||
if (err == nil) != tc.ok {
|
||||
t.Fatalf("valid=%v err=%v", tc.ok, err)
|
||||
}
|
||||
if err != nil && strings.Contains(err.Error(), "do-not-leak") {
|
||||
t.Fatal("secret in error")
|
||||
}
|
||||
if err == nil && tc.name == "valid" && (c.TencentCaptcha.SaaS.AppID != "123" || c.TencentCaptcha.Mini.AppID != "456") {
|
||||
t.Fatal("client config mixed")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
func TestTencentCaptchaFileOnlyBackendAndExplicitMissing(t *testing.T) {
|
||||
t.Setenv("TENCENT_CAPTCHA_CONFIG_FILE", filepath.Join(t.TempDir(), "absent.json"))
|
||||
var c OnboardingConfig
|
||||
if c.loadTencentCaptchaFile("callbacks") != nil {
|
||||
t.Fatal("callbacks read config")
|
||||
}
|
||||
if c.loadTencentCaptchaFile("api") == nil {
|
||||
t.Fatal("missing explicit file accepted")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user