|
|
|
@ -72,49 +72,49 @@ func mixAddr(a string) (*common.MixedcaseAddress, error) { |
|
|
|
|
return common.NewMixedcaseAddressFromString(a) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
type alwaysDenyUi struct{} |
|
|
|
|
type alwaysDenyUI struct{} |
|
|
|
|
|
|
|
|
|
func (alwaysDenyUi) OnSignerStartup(info core.StartupInfo) { |
|
|
|
|
func (alwaysDenyUI) OnSignerStartup(info core.StartupInfo) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (alwaysDenyUi) ApproveTx(request *core.SignTxRequest) (core.SignTxResponse, error) { |
|
|
|
|
func (alwaysDenyUI) ApproveTx(request *core.SignTxRequest) (core.SignTxResponse, error) { |
|
|
|
|
return core.SignTxResponse{Transaction: request.Transaction, Approved: false, Password: ""}, nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (alwaysDenyUi) ApproveSignData(request *core.SignDataRequest) (core.SignDataResponse, error) { |
|
|
|
|
func (alwaysDenyUI) ApproveSignData(request *core.SignDataRequest) (core.SignDataResponse, error) { |
|
|
|
|
return core.SignDataResponse{Approved: false, Password: ""}, nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (alwaysDenyUi) ApproveExport(request *core.ExportRequest) (core.ExportResponse, error) { |
|
|
|
|
func (alwaysDenyUI) ApproveExport(request *core.ExportRequest) (core.ExportResponse, error) { |
|
|
|
|
return core.ExportResponse{Approved: false}, nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (alwaysDenyUi) ApproveImport(request *core.ImportRequest) (core.ImportResponse, error) { |
|
|
|
|
func (alwaysDenyUI) ApproveImport(request *core.ImportRequest) (core.ImportResponse, error) { |
|
|
|
|
return core.ImportResponse{Approved: false, OldPassword: "", NewPassword: ""}, nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (alwaysDenyUi) ApproveListing(request *core.ListRequest) (core.ListResponse, error) { |
|
|
|
|
func (alwaysDenyUI) ApproveListing(request *core.ListRequest) (core.ListResponse, error) { |
|
|
|
|
return core.ListResponse{Accounts: nil}, nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (alwaysDenyUi) ApproveNewAccount(request *core.NewAccountRequest) (core.NewAccountResponse, error) { |
|
|
|
|
func (alwaysDenyUI) ApproveNewAccount(request *core.NewAccountRequest) (core.NewAccountResponse, error) { |
|
|
|
|
return core.NewAccountResponse{Approved: false, Password: ""}, nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (alwaysDenyUi) ShowError(message string) { |
|
|
|
|
func (alwaysDenyUI) ShowError(message string) { |
|
|
|
|
panic("implement me") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (alwaysDenyUi) ShowInfo(message string) { |
|
|
|
|
func (alwaysDenyUI) ShowInfo(message string) { |
|
|
|
|
panic("implement me") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (alwaysDenyUi) OnApprovedTx(tx ethapi.SignTransactionResult) { |
|
|
|
|
func (alwaysDenyUI) OnApprovedTx(tx ethapi.SignTransactionResult) { |
|
|
|
|
panic("implement me") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func initRuleEngine(js string) (*rulesetUi, error) { |
|
|
|
|
r, err := NewRuleEvaluator(&alwaysDenyUi{}, storage.NewEphemeralStorage(), storage.NewEphemeralStorage()) |
|
|
|
|
func initRuleEngine(js string) (*rulesetUI, error) { |
|
|
|
|
r, err := NewRuleEvaluator(&alwaysDenyUI{}, storage.NewEphemeralStorage(), storage.NewEphemeralStorage()) |
|
|
|
|
if err != nil { |
|
|
|
|
return nil, fmt.Errorf("failed to create js engine: %v", err) |
|
|
|
|
} |
|
|
|
@ -196,59 +196,59 @@ func TestSignTxRequest(t *testing.T) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
type dummyUi struct { |
|
|
|
|
type dummyUI struct { |
|
|
|
|
calls []string |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (d *dummyUi) ApproveTx(request *core.SignTxRequest) (core.SignTxResponse, error) { |
|
|
|
|
func (d *dummyUI) ApproveTx(request *core.SignTxRequest) (core.SignTxResponse, error) { |
|
|
|
|
d.calls = append(d.calls, "ApproveTx") |
|
|
|
|
return core.SignTxResponse{}, core.ErrRequestDenied |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (d *dummyUi) ApproveSignData(request *core.SignDataRequest) (core.SignDataResponse, error) { |
|
|
|
|
func (d *dummyUI) ApproveSignData(request *core.SignDataRequest) (core.SignDataResponse, error) { |
|
|
|
|
d.calls = append(d.calls, "ApproveSignData") |
|
|
|
|
return core.SignDataResponse{}, core.ErrRequestDenied |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (d *dummyUi) ApproveExport(request *core.ExportRequest) (core.ExportResponse, error) { |
|
|
|
|
func (d *dummyUI) ApproveExport(request *core.ExportRequest) (core.ExportResponse, error) { |
|
|
|
|
d.calls = append(d.calls, "ApproveExport") |
|
|
|
|
return core.ExportResponse{}, core.ErrRequestDenied |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (d *dummyUi) ApproveImport(request *core.ImportRequest) (core.ImportResponse, error) { |
|
|
|
|
func (d *dummyUI) ApproveImport(request *core.ImportRequest) (core.ImportResponse, error) { |
|
|
|
|
d.calls = append(d.calls, "ApproveImport") |
|
|
|
|
return core.ImportResponse{}, core.ErrRequestDenied |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (d *dummyUi) ApproveListing(request *core.ListRequest) (core.ListResponse, error) { |
|
|
|
|
func (d *dummyUI) ApproveListing(request *core.ListRequest) (core.ListResponse, error) { |
|
|
|
|
d.calls = append(d.calls, "ApproveListing") |
|
|
|
|
return core.ListResponse{}, core.ErrRequestDenied |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (d *dummyUi) ApproveNewAccount(request *core.NewAccountRequest) (core.NewAccountResponse, error) { |
|
|
|
|
func (d *dummyUI) ApproveNewAccount(request *core.NewAccountRequest) (core.NewAccountResponse, error) { |
|
|
|
|
d.calls = append(d.calls, "ApproveNewAccount") |
|
|
|
|
return core.NewAccountResponse{}, core.ErrRequestDenied |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (d *dummyUi) ShowError(message string) { |
|
|
|
|
func (d *dummyUI) ShowError(message string) { |
|
|
|
|
d.calls = append(d.calls, "ShowError") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (d *dummyUi) ShowInfo(message string) { |
|
|
|
|
func (d *dummyUI) ShowInfo(message string) { |
|
|
|
|
d.calls = append(d.calls, "ShowInfo") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (d *dummyUi) OnApprovedTx(tx ethapi.SignTransactionResult) { |
|
|
|
|
func (d *dummyUI) OnApprovedTx(tx ethapi.SignTransactionResult) { |
|
|
|
|
d.calls = append(d.calls, "OnApprovedTx") |
|
|
|
|
} |
|
|
|
|
func (d *dummyUi) OnSignerStartup(info core.StartupInfo) { |
|
|
|
|
func (d *dummyUI) OnSignerStartup(info core.StartupInfo) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//TestForwarding tests that the rule-engine correctly dispatches requests to the next caller
|
|
|
|
|
func TestForwarding(t *testing.T) { |
|
|
|
|
|
|
|
|
|
js := "" |
|
|
|
|
ui := &dummyUi{make([]string, 0)} |
|
|
|
|
ui := &dummyUI{make([]string, 0)} |
|
|
|
|
jsBackend := storage.NewEphemeralStorage() |
|
|
|
|
credBackend := storage.NewEphemeralStorage() |
|
|
|
|
r, err := NewRuleEvaluator(ui, jsBackend, credBackend) |
|
|
|
|