Files
Ryan 71ef622b4f
Test and deploy MQTT backend / test (push) Successful in 2m8s
Test and deploy MQTT backend / deploy (push) Successful in 18s
Deploy MQTT test backend with private viewer and Gitea CI/CD
2026-10-08 14:48:53 +03:30

35 lines
1.1 KiB
Go

package cli
import (
"bytes"
"context"
"os"
"path/filepath"
"strings"
"testing"
)
func TestPrivateHandoffAndSafeErrors(t *testing.T) {
root := t.TempDir()
credentials := filepath.Join(root, "client.json")
if err := os.WriteFile(credentials, []byte(`{"username":"sim-001","password":"PRIVATE_SENTINEL","host":"unused"}`), 0600); err != nil {
t.Fatal(err)
}
for _, args := range [][]string{{"--credentials", credentials, "check-config"}, {"--credentials", credentials, "--device-id", "bad/+", "check-config"}} {
var out, errOut bytes.Buffer
Run(context.Background(), args, &out, &errOut, false)
if strings.Contains(out.String()+errOut.String(), "PRIVATE_SENTINEL") {
t.Fatal("private credentials leaked")
}
}
var out, errOut bytes.Buffer
if code := Run(context.Background(), []string{"--broker", "mqtt://localhost:1884", "check-config"}, &out, &errOut, false); code != 1 {
t.Fatal("plaintext not rejected")
}
out.Reset()
errOut.Reset()
if code := Run(context.Background(), []string{"--broker", "mqtt://localhost:1884", "--allow-plaintext", "check-config"}, &out, &errOut, false); code != 0 {
t.Fatal("explicit plaintext not accepted")
}
}