Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3b2a7ab163 | ||
|
|
a5339d98d5 |
@ -83,7 +83,7 @@ func TestBuiltinSigners(t *testing.T) {
|
|||||||
if err := signer.Sign(req, config); err != nil {
|
if err := signer.Sign(req, config); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
expected := "Basic " + encoding.Base64ToString([]byte("admin:123"))
|
expected := "Basic " + encoding.Base64([]byte("admin:123"))
|
||||||
if req.GetHeader("Authorization") != expected {
|
if req.GetHeader("Authorization") != expected {
|
||||||
t.Errorf("expected %s, got %s", expected, req.GetHeader("Authorization"))
|
t.Errorf("expected %s, got %s", expected, req.GetHeader("Authorization"))
|
||||||
}
|
}
|
||||||
|
|||||||
@ -218,8 +218,8 @@ func decryptMapWithPrefix(m map[string]any) []*safe.SafeBuf {
|
|||||||
raw := s[2:]
|
raw := s[2:]
|
||||||
var b64 []byte
|
var b64 []byte
|
||||||
var err error
|
var err error
|
||||||
if b64, err = encoding.UnUrlBase64FromString(raw); err != nil {
|
if b64, err = encoding.UnURLBase64(raw); err != nil {
|
||||||
b64, err = encoding.UnBase64FromString(raw)
|
b64, err = encoding.UnBase64(raw)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err == nil && len(b64) > 0 {
|
if err == nil && len(b64) > 0 {
|
||||||
@ -249,8 +249,8 @@ func decryptMap(m map[string]any) []*safe.SafeBuf {
|
|||||||
inner = s[4 : len(s)-1]
|
inner = s[4 : len(s)-1]
|
||||||
}
|
}
|
||||||
|
|
||||||
if b64, err = encoding.UnUrlBase64FromString(inner); err != nil {
|
if b64, err = encoding.UnURLBase64(inner); err != nil {
|
||||||
b64, err = encoding.UnBase64FromString(inner)
|
b64, err = encoding.UnBase64(inner)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err == nil && len(b64) > 0 {
|
if err == nil && len(b64) > 0 {
|
||||||
|
|||||||
12
js_export.go
12
js_export.go
@ -8,18 +8,16 @@ import (
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
jsmod.Register("api", map[string]any{
|
jsmod.Register("api", map[string]any{
|
||||||
"call": call,
|
"Call": call,
|
||||||
"setConfig": SetConfig,
|
"SetConfig": SetConfig,
|
||||||
"registerAction": RegisterAction,
|
"RegisterAction": RegisterAction,
|
||||||
"registerSigner": registerSigner,
|
"RegisterSigner": registerSigner,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// call 提供给 JS 的私有入口
|
// call 提供给 JS 的私有入口
|
||||||
func call(ctx context.Context, name string, payload any) (any, error) {
|
func call(ctx context.Context, name string, payload any) (any, error) {
|
||||||
// 注意:在低代码环境中,我们可能需要将 ctx 传入以透传追踪信息给 JS 签名器。
|
// 将 ctx 传入以透传追踪信息给 JS 签名器
|
||||||
// 虽然 api.CallBy[any] 目前不接收 ctx,但底层的 jsRunner 钩子可以从 context 中获取信息。
|
|
||||||
// 如果未来 jsRunner 需要 ctx,我们可以在这里通过 context.WithValue 注入。
|
|
||||||
return CallBy[any](name, payload)
|
return CallBy[any](name, payload)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -15,7 +15,7 @@ func TestSafeConfigDecryption(t *testing.T) {
|
|||||||
|
|
||||||
plaintext := "my-secret-password"
|
plaintext := "my-secret-password"
|
||||||
ciphertext, _ := confAES.EncryptBytes([]byte(plaintext))
|
ciphertext, _ := confAES.EncryptBytes([]byte(plaintext))
|
||||||
b64 := encoding.Base64ToString(ciphertext)
|
b64 := encoding.Base64(ciphertext)
|
||||||
|
|
||||||
GlobalConfigs = map[string]any{
|
GlobalConfigs = map[string]any{
|
||||||
"api": map[string]any{
|
"api": map[string]any{
|
||||||
@ -51,7 +51,7 @@ func TestSafeConfigDecryption(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
expectedAuth := "Basic " + encoding.Base64ToString([]byte("admin:"+plaintext))
|
expectedAuth := "Basic " + encoding.Base64([]byte("admin:"+plaintext))
|
||||||
if req.GetHeader("Authorization") != expectedAuth {
|
if req.GetHeader("Authorization") != expectedAuth {
|
||||||
t.Errorf("expected %s, got %s", expectedAuth, req.GetHeader("Authorization"))
|
t.Errorf("expected %s, got %s", expectedAuth, req.GetHeader("Authorization"))
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user