mirror of
https://github.com/lightninglabs/lightning-terminal.git
synced 2026-08-13 12:33:36 +02:00
test: add coverage for account checkLabel validation
checkLabel rejects labels that could be mistaken for a hex-encoded account ID. Add a table-driven test covering the accepted cases (empty, plain text, short hex, and non-hex strings of account-ID length) as well as the rejected cases (lower- and upper-case hex strings of account-ID length). Signed-off-by: 0xfandom <kashyapshivank01@gmail.com>
This commit is contained in:
parent
4ed4b03324
commit
163cccba89
1 changed files with 58 additions and 0 deletions
|
|
@ -778,3 +778,61 @@ func TestLastInvoiceIndexes(t *testing.T) {
|
|||
require.EqualValues(t, 7, add)
|
||||
require.EqualValues(t, 99, settle)
|
||||
}
|
||||
|
||||
// TestCheckLabel ensures that only labels that could be mistaken for a hex
|
||||
// encoded account ID are rejected, while all other labels (including the empty
|
||||
// label) are accepted.
|
||||
func TestCheckLabel(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
label string
|
||||
expectErr bool
|
||||
}{{
|
||||
name: "empty label is allowed",
|
||||
label: "",
|
||||
}, {
|
||||
name: "plain text label is allowed",
|
||||
label: "my account",
|
||||
}, {
|
||||
name: "short hex label is allowed",
|
||||
label: "00112233",
|
||||
}, {
|
||||
name: "non-hex label with account ID length is allowed",
|
||||
// 16 characters long, matching an encoded account ID, but not
|
||||
// valid hex.
|
||||
label: "zzzzzzzzzzzzzzzz",
|
||||
}, {
|
||||
name: "lowercase hex label with account ID length is rejected",
|
||||
// 16 characters of valid hex, exactly the length of an encoded
|
||||
// account ID.
|
||||
label: "0011223344556677",
|
||||
expectErr: true,
|
||||
}, {
|
||||
name: "uppercase hex label with account ID length is rejected",
|
||||
// hex.DecodeString also accepts uppercase digits, so this must
|
||||
// be rejected as well.
|
||||
label: "00112233445566AA",
|
||||
expectErr: true,
|
||||
}}
|
||||
|
||||
for _, tc := range tests {
|
||||
tc := tc
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
err := checkLabel(tc.label)
|
||||
if tc.expectErr {
|
||||
require.ErrorContains(
|
||||
t, err, "is not allowed as it can be "+
|
||||
"mistaken",
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
require.NoError(t, err)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue