snoop on info messages sent to UI

This commit is contained in:
shwoop 2025-07-02 16:52:45 +02:00
parent e6246c48ce
commit 346c15bebd
No known key found for this signature in database
GPG key ID: 95A35B68C1E5F95A
4 changed files with 10 additions and 7 deletions

View file

@ -41,8 +41,9 @@ import (
// Used for testing
type headlessUi struct {
approveCh chan string // to send approve/deny
inputCh chan string // to send password
approveCh chan string // to send approve/deny
inputCh chan string // to send password
infoMessages []string
}
func (ui *headlessUi) OnInputRequired(info core.UserInputRequest) (core.UserInputResponse, error) {
@ -104,6 +105,7 @@ func (ui *headlessUi) ShowError(message string) {
func (ui *headlessUi) ShowInfo(message string) {
//stdout is used by communication
fmt.Fprintln(os.Stderr, message)
ui.infoMessages = append(ui.infoMessages, message)
}
func tmpDirName(t *testing.T) string {
@ -120,7 +122,7 @@ func setup(t *testing.T, enableSIWE bool) (*core.SignerAPI, *headlessUi) {
if err != nil {
t.Fatal(err.Error())
}
ui := &headlessUi{make(chan string, 20), make(chan string, 20)}
ui := &headlessUi{make(chan string, 20), make(chan string, 20), []string{}}
am := core.StartClefAccountManager(tmpDirName(t), true, true, "")
api := core.NewSignerAPI(am, 1337, true, ui, db, true, &storage.NoStorage{}, enableSIWE)
return api, ui

View file

@ -42,7 +42,7 @@ func (api *SignerAPI) sign(req *SignDataRequest, legacyV bool) (hexutil.Bytes, e
// perform SIWE validation
err := validateSIWE(req)
if err != nil {
if errors.Is(err, ErrMalformedSIWEMEssage) {
if errors.Is(err, ErrMalformedSIWEMessage) {
api.UI.ShowInfo(err.Error())
} else {
return nil, err

View file

@ -1196,7 +1196,8 @@ func TestSignInWithEtheriumWarning(t *testing.T) {
control.inputCh <- "a_long_password"
signature, err := api.SignData(ctx, apitypes.TextPlain.Mime, a, hexutil.Encode([]byte(message)))
require.NoError(t, err)
// todo: check UI for warning message
require.Equal(t, 1, len(control.infoMessages))
require.Equal(t, core.ErrMalformedSIWEMessage.Error(), control.infoMessages[0])
if signature == nil || len(signature) != 65 {
t.Errorf("Expected 65 byte signature (got %d bytes)", len(signature))

View file

@ -77,7 +77,7 @@ var siweMessageRegex = regexp.MustCompile(`(?m)^` + messageSize + scheme + domai
uri + version + chainID + nonce + issuedAt +
expiration + notBefore + requestID + resources + `$`)
var ErrMalformedSIWEMEssage = errors.New("the message is asking to sign in with Ethereum but does not conform to EIP-4361")
var ErrMalformedSIWEMessage = errors.New("the message is asking to sign in with Ethereum but does not conform to EIP-4361")
func validateSIWE(req *SignDataRequest) error {
for _, message := range req.Messages {
@ -91,7 +91,7 @@ func validateSIWE(req *SignDataRequest) error {
patterns := siweMessageRegex.FindStringSubmatch(s)
if patterns == nil {
return ErrMalformedSIWEMEssage
return ErrMalformedSIWEMessage
}
scheme := "https"
if patterns[1] != "" {