The 1.4.2 extension replaced the old signed/encrypted chat gateway with an
OpenAI-compatible aigateway. Align the proxy with the new flow:
- Use ecloud.10086.cn login/model base URLs, zhanlu_ide plugin headers and
v1.4.2 plugin version
- Provision the model API key via SM2-signed get-or-create after v1/login
profile fetch; store api_key/model_base_url/email in credentials
- Chat via Bearer apiKey against {modelBaseUrl}/chat/completions with plain
OpenAI SSE passthrough; fetch /v1/models from the gateway model-info endpoint
- Force HTTP/1.1 upstream (gateway drops HTTP/2 ALPN negotiation with EOF)
- Drop obsolete AES body encryption, model name mapping and vscode headers
33 lines
977 B
Go
33 lines
977 B
Go
package auth
|
|
|
|
import (
|
|
"encoding/hex"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestSignSM2Authorization(t *testing.T) {
|
|
const privHex = "8d6ee90b3c4d299ae5abd655dbc3547c110ae8aeff1de18b0df241f215f90748"
|
|
sig, err := SignSM2Authorization(privHex, "1754460000:AbCdEfGh1234567890AbCdEfGh123456:{\"email\":\"[email protected]\"}")
|
|
if err != nil {
|
|
t.Fatalf("SignSM2Authorization: %v", err)
|
|
}
|
|
if len(sig) != 128 {
|
|
t.Fatalf("signature length = %d, want 128 (r||s hex)", len(sig))
|
|
}
|
|
if _, err := hex.DecodeString(sig); err != nil {
|
|
t.Fatalf("signature is not hex: %v", err)
|
|
}
|
|
// Deterministic inputs must produce a stable signature across calls only if
|
|
// the nonce is fixed; sm-crypto randomizes k, so just check shape + parse.
|
|
if strings.TrimSpace(sig) != sig {
|
|
t.Fatalf("signature contains whitespace")
|
|
}
|
|
}
|
|
|
|
func TestSignSM2AuthorizationInvalidKey(t *testing.T) {
|
|
if _, err := SignSM2Authorization("zz", "x"); err == nil {
|
|
t.Fatal("expected error for invalid private key hex")
|
|
}
|
|
}
|