Add monitoring metrics, numeric sorting, report-time display, vehicle number labels, and map layout fixes. Include accumulated mileage, hydrogen, OneOS authentication, open platform, ingestion, deployment, and UI updates. Exclude temporary files, generated reports, and credentials. Validate frontend 632 tests and production build, API packages, vehicle-map tests, and release installer tests. Gateway suite has one pre-existing date-sensitive identity throttling test failure reproduced on the parent commit.
74 lines
2.9 KiB
Go
74 lines
2.9 KiB
Go
package gzev
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"io"
|
|
"net/http"
|
|
"net/url"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
type roundTripFunc func(*http.Request) (*http.Response, error)
|
|
|
|
func (f roundTripFunc) RoundTrip(r *http.Request) (*http.Response, error) { return f(r) }
|
|
func TestSMSRequestAndBusinessFailure(t *testing.T) {
|
|
for _, code := range []string{"OK", "isv.BUSINESS_LIMIT_CONTROL"} {
|
|
calls := 0
|
|
s := SMS{AccessKeyID: "test-id", AccessKeySecret: "test-secret", SecurityToken: "sts-token", SignName: "测试签名", TemplateCode: "SMS_TEST", TemplateParam: `{"system":"广州里程"}`}
|
|
s.HTTP = &http.Client{Transport: roundTripFunc(func(r *http.Request) (*http.Response, error) {
|
|
calls++
|
|
b, _ := io.ReadAll(r.Body)
|
|
form, _ := url.ParseQuery(string(b))
|
|
if r.URL.String() != "https://dysmsapi.aliyuncs.com/" || form.Get("PhoneNumbers") != "16605225837" || form.Get("TemplateCode") != "SMS_TEST" {
|
|
t.Fatal("wrong SMS destination")
|
|
}
|
|
if r.Header.Get("x-acs-content-sha256") != hashHex(b) || r.Header.Get("x-acs-action") != "SendSms" || !strings.Contains(r.Header.Get("Authorization"), "x-acs-security-token") {
|
|
t.Fatal("incorrect signed request")
|
|
}
|
|
return &http.Response{StatusCode: 200, Body: io.NopCloser(strings.NewReader(`{"Code":"` + code + `"}`)), Header: http.Header{}}, nil
|
|
})}
|
|
err := s.Send(context.Background())
|
|
if (err == nil) != (code == "OK") || calls != 1 {
|
|
t.Fatalf("%s: %v", code, err)
|
|
}
|
|
}
|
|
}
|
|
func TestSMSMissingConfigDoesNotSend(t *testing.T) {
|
|
if (SMS{}).Send(context.Background()) == nil {
|
|
t.Fatal("missing config reported success")
|
|
}
|
|
}
|
|
|
|
func TestSMSIncludesUploadURLAndSingleUseRecovery(t *testing.T) {
|
|
path := filepath.Join(t.TempDir(), "session.json")
|
|
t.Setenv("GZEV_SESSION_FILE", path)
|
|
t.Setenv("GZEV_SESSION_UPLOAD_URL", "https://vehicle.d.lnoneos.com/gzev/session/")
|
|
s := SMS{AccessKeyID: "id", AccessKeySecret: "secret", SignName: "sign", TemplateCode: "SMS_TEST"}
|
|
var code string
|
|
s.HTTP = &http.Client{Transport: roundTripFunc(func(r *http.Request) (*http.Response, error) {
|
|
b, _ := io.ReadAll(r.Body)
|
|
form, _ := url.ParseQuery(string(b))
|
|
var params map[string]string
|
|
if json.Unmarshal([]byte(form.Get("TemplateParam")), ¶ms) != nil {
|
|
t.Fatal("invalid template params")
|
|
}
|
|
if params["upload_url"] != "https://vehicle.d.lnoneos.com/gzev/session/" || len(params["recovery_code"]) != 48 {
|
|
t.Fatal("missing actionable recovery information")
|
|
}
|
|
code = params["recovery_code"]
|
|
return &http.Response{StatusCode: 200, Header: http.Header{}, Body: io.NopCloser(strings.NewReader(`{"Code":"OK"}`))}, nil
|
|
})}
|
|
if err := s.Send(context.Background()); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := ConsumeRecovery(path+".recovery.json", code, func() error { return nil }); err != nil {
|
|
t.Fatal("SMS code not usable")
|
|
}
|
|
if err := ConsumeRecovery(path+".recovery.json", code, func() error { return nil }); err == nil {
|
|
t.Fatal("SMS code reused")
|
|
}
|
|
}
|