mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-23 21:26:42 +00:00
snoop on info messages sent to UI
This commit is contained in:
parent
e6246c48ce
commit
346c15bebd
4 changed files with 10 additions and 7 deletions
|
|
@ -43,6 +43,7 @@ import (
|
|||
type headlessUi struct {
|
||||
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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -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] != "" {
|
||||
|
|
|
|||
Loading…
Reference in a new issue