mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-23 13:16:42 +00:00
update tests
This commit is contained in:
parent
bc95c932b9
commit
374a2759f5
3 changed files with 24 additions and 8 deletions
|
|
@ -41,9 +41,9 @@ import (
|
|||
|
||||
// Used for testing
|
||||
type headlessUi struct {
|
||||
approveCh chan string // to send approve/deny
|
||||
inputCh chan string // to send password
|
||||
infoMessages []string
|
||||
approveCh chan string // to send approve/deny
|
||||
inputCh chan string // to send password
|
||||
infoMessages, errorMessages []string
|
||||
}
|
||||
|
||||
func (ui *headlessUi) OnInputRequired(info core.UserInputRequest) (core.UserInputResponse, error) {
|
||||
|
|
@ -100,6 +100,7 @@ func (ui *headlessUi) ApproveNewAccount(request *core.NewAccountRequest) (core.N
|
|||
func (ui *headlessUi) ShowError(message string) {
|
||||
//stdout is used by communication
|
||||
fmt.Fprintln(os.Stderr, message)
|
||||
ui.errorMessages = append(ui.errorMessages, message)
|
||||
}
|
||||
|
||||
func (ui *headlessUi) ShowInfo(message string) {
|
||||
|
|
@ -122,7 +123,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), []string{}}
|
||||
ui := &headlessUi{make(chan string, 20), make(chan string, 20), []string{}, []string{}}
|
||||
am := core.StartClefAccountManager(tmpDirName(t), true, true, "")
|
||||
api := core.NewSignerAPI(am, 1337, true, ui, db, true, &storage.NoStorage{}, enableSIWE)
|
||||
return api, ui
|
||||
|
|
|
|||
|
|
@ -1088,6 +1088,8 @@ func TestSignInWithEtheriumValidLocalhost(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)
|
||||
require.Equal(t, 0, len(control.infoMessages))
|
||||
require.Equal(t, 0, len(control.errorMessages))
|
||||
|
||||
if signature == nil || len(signature) != 65 {
|
||||
t.Errorf("Expected 65 byte signature (got %d bytes)", len(signature))
|
||||
|
|
@ -1120,7 +1122,8 @@ func TestSignInWithEtheriumValidMessages(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, 0, len(control.infoMessages))
|
||||
require.Equal(t, 0, len(control.errorMessages))
|
||||
|
||||
if signature == nil || len(signature) != 65 {
|
||||
t.Errorf("Expected 65 byte signature (got %d bytes)", len(signature))
|
||||
|
|
@ -1138,6 +1141,7 @@ func TestSignInWithEtheriumInvlid(t *testing.T) {
|
|||
Source string `json:"source"`
|
||||
Account string `json:"account"`
|
||||
} `json:"request_context"`
|
||||
ErrorMsgPattern string `json:"error_msg_pattern"`
|
||||
}
|
||||
jsonFile, err := os.ReadFile(filepath.Join("testdata", "siwe", "error_spoofing.json"))
|
||||
require.NoError(t, err)
|
||||
|
|
@ -1164,8 +1168,15 @@ func TestSignInWithEtheriumInvlid(t *testing.T) {
|
|||
_, err = api.SignData(ctx, apitypes.TextPlain.Mime, a, hexutil.Encode([]byte(message)))
|
||||
if enabled {
|
||||
require.Error(t, err)
|
||||
|
||||
require.Equal(t, 0, len(control.infoMessages))
|
||||
require.Equal(t, 1, len(control.errorMessages))
|
||||
require.Regexp(t, testData.ErrorMsgPattern, err.Error())
|
||||
} else {
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, 0, len(control.infoMessages))
|
||||
require.Equal(t, 0, len(control.errorMessages))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
@ -1198,6 +1209,7 @@ func TestSignInWithEtheriumWarning(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
require.Equal(t, 1, len(control.infoMessages))
|
||||
require.Equal(t, core.ErrMalformedSIWEMessage.Error(), control.infoMessages[0])
|
||||
require.Equal(t, 0, len(control.errorMessages))
|
||||
|
||||
if signature == nil || len(signature) != 65 {
|
||||
t.Errorf("Expected 65 byte signature (got %d bytes)", len(signature))
|
||||
|
|
|
|||
|
|
@ -4,14 +4,16 @@
|
|||
"request_context": {
|
||||
"transport": "http",
|
||||
"source": "localhost:4361"
|
||||
}
|
||||
},
|
||||
"error_msg_pattern": "sign in request domain \\(https://localhost:4361\\) does not match source: http://localhost:4361"
|
||||
},
|
||||
"spoofed_source": {
|
||||
"msg": "https://important-website.com wants you to sign in with your Ethereum account:\n{{Account}}\n\nSIWE Notepad Example\n\nURI: https://important-website.com\nVersion: 1\nChain ID: 1\nNonce: b19JyMHnM0Jdm20as\nIssued At: 2022-04-19T18:57:09.490Z",
|
||||
"request_context": {
|
||||
"transport": "https",
|
||||
"source": "bad-website.com"
|
||||
}
|
||||
},
|
||||
"error_msg_pattern": "sign in request domain \\(https://important-website.com\\) does not match source: https://bad-website.com"
|
||||
},
|
||||
"spoofed_account": {
|
||||
"msg": "localhost:4361 wants you to sign in with your Ethereum account:\n{{Account}}\n\nSIWE Notepad Example\n\nURI: https://localhost:4361\nVersion: 1\nChain ID: 1\nNonce: b19JyMHnM0Jdm20as\nIssued At: 2022-04-19T18:57:09.490Z",
|
||||
|
|
@ -19,6 +21,7 @@
|
|||
"transport": "https",
|
||||
"source": "localhost:4361",
|
||||
"account": "0x1234567890123456789012345678901234567890"
|
||||
}
|
||||
},
|
||||
"error_msg_pattern": "sign in request address \\(0x1234567890123456789012345678901234567890\\) does not match source: 0x.*"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue