Merge PR #3674: Remove password/keybase from REST Client

This commit is contained in:
Alexander Bezobchuk
2019-02-19 10:15:39 -08:00
committed by Jack Zampolin
parent 6967de1073
commit e39debd359
26 changed files with 335 additions and 1335 deletions
+7 -15
View File
@@ -22,7 +22,6 @@ type GasEstimateResponse struct {
// that all share common "base" fields.
type BaseReq struct {
From string `json:"from"`
Password string `json:"password"`
Memo string `json:"memo"`
ChainID string `json:"chain_id"`
AccountNumber uint64 `json:"account_number"`
@@ -31,19 +30,17 @@ type BaseReq struct {
GasPrices sdk.DecCoins `json:"gas_prices"`
Gas string `json:"gas"`
GasAdjustment string `json:"gas_adjustment"`
GenerateOnly bool `json:"generate_only"`
Simulate bool `json:"simulate"`
}
// NewBaseReq creates a new basic request instance and sanitizes its values
func NewBaseReq(
from, password, memo, chainID string, gas, gasAdjustment string,
accNumber, seq uint64, fees sdk.Coins, gasPrices sdk.DecCoins, genOnly, simulate bool,
from, memo, chainID string, gas, gasAdjustment string, accNumber, seq uint64,
fees sdk.Coins, gasPrices sdk.DecCoins, simulate bool,
) BaseReq {
return BaseReq{
From: strings.TrimSpace(from),
Password: password,
Memo: strings.TrimSpace(memo),
ChainID: strings.TrimSpace(chainID),
Fees: fees,
@@ -52,7 +49,6 @@ func NewBaseReq(
GasAdjustment: strings.TrimSpace(gasAdjustment),
AccountNumber: accNumber,
Sequence: seq,
GenerateOnly: genOnly,
Simulate: simulate,
}
}
@@ -60,8 +56,8 @@ func NewBaseReq(
// Sanitize performs basic sanitization on a BaseReq object.
func (br BaseReq) Sanitize() BaseReq {
return NewBaseReq(
br.From, br.Password, br.Memo, br.ChainID, br.Gas, br.GasAdjustment,
br.AccountNumber, br.Sequence, br.Fees, br.GasPrices, br.GenerateOnly, br.Simulate,
br.From, br.Memo, br.ChainID, br.Gas, br.GasAdjustment,
br.AccountNumber, br.Sequence, br.Fees, br.GasPrices, br.Simulate,
)
}
@@ -69,12 +65,8 @@ func (br BaseReq) Sanitize() BaseReq {
// logic is needed, the implementing request handler should perform those
// checks manually.
func (br BaseReq) ValidateBasic(w http.ResponseWriter) bool {
if !br.GenerateOnly && !br.Simulate {
if !br.Simulate {
switch {
case len(br.Password) == 0:
WriteErrorResponse(w, http.StatusUnauthorized, "password required but not specified")
return false
case len(br.ChainID) == 0:
WriteErrorResponse(w, http.StatusUnauthorized, "chain-id required but not specified")
return false
@@ -91,8 +83,8 @@ func (br BaseReq) ValidateBasic(w http.ResponseWriter) bool {
}
}
if len(br.From) == 0 {
WriteErrorResponse(w, http.StatusUnauthorized, "name or address required but not specified")
if _, err := sdk.AccAddressFromBech32(br.From); err != nil || len(br.From) == 0 {
WriteErrorResponse(w, http.StatusUnauthorized, fmt.Sprintf("invalid from address: %s", br.From))
return false
}
+10 -19
View File
@@ -14,35 +14,27 @@ import (
type mockResponseWriter struct{}
func TestBaseReq_ValidateBasic(t *testing.T) {
func TestBaseReqValidateBasic(t *testing.T) {
fromAddr := "cosmos1cq0sxam6x4l0sv9yz3a2vlqhdhvt2k6jtgcse0"
tenstakes, err := types.ParseCoins("10stake")
require.NoError(t, err)
onestake, err := types.ParseDecCoins("1.0stake")
require.NoError(t, err)
req1 := NewBaseReq(
"nonempty", "nonempty", "", "nonempty", "", "",
0, 0, tenstakes, nil, false, false,
fromAddr, "", "nonempty", "", "", 0, 0, tenstakes, nil, false,
)
req2 := NewBaseReq(
"", "nonempty", "", "nonempty", "", "",
0, 0, tenstakes, nil, false, false,
"", "", "nonempty", "", "", 0, 0, tenstakes, nil, false,
)
req3 := NewBaseReq(
"nonempty", "", "", "nonempty", "", "",
0, 0, tenstakes, nil, false, false,
fromAddr, "", "", "", "", 0, 0, tenstakes, nil, false,
)
req4 := NewBaseReq(
"nonempty", "nonempty", "", "", "", "",
0, 0, tenstakes, nil, false, false,
fromAddr, "", "nonempty", "", "", 0, 0, tenstakes, onestake, false,
)
req5 := NewBaseReq(
"nonempty", "nonempty", "", "nonempty", "", "",
0, 0, tenstakes, onestake, false, false,
)
req6 := NewBaseReq(
"nonempty", "nonempty", "", "nonempty", "", "",
0, 0, types.Coins{}, types.DecCoins{}, false, false,
fromAddr, "", "nonempty", "", "", 0, 0, types.Coins{}, types.DecCoins{}, false,
)
tests := []struct {
@@ -52,11 +44,10 @@ func TestBaseReq_ValidateBasic(t *testing.T) {
want bool
}{
{"ok", req1, httptest.NewRecorder(), true},
{"neither fees nor gasprices provided", req6, httptest.NewRecorder(), true},
{"neither fees nor gasprices provided", req5, httptest.NewRecorder(), true},
{"empty from", req2, httptest.NewRecorder(), false},
{"empty password", req3, httptest.NewRecorder(), false},
{"empty chain-id", req4, httptest.NewRecorder(), false},
{"fees and gasprices provided", req5, httptest.NewRecorder(), false},
{"empty chain-id", req3, httptest.NewRecorder(), false},
{"fees and gasprices provided", req4, httptest.NewRecorder(), false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {