-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2412 from Roasbeef/node-alias-validation
lnwire+peer: fully validate node aliases on the wire, don't d/c due to invalid aliases
- Loading branch information
Showing
5 changed files
with
94 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package lnwire | ||
|
||
import "testing" | ||
|
||
// TestNodeAliasValidation tests that the NewNodeAlias method will only accept | ||
// valid node announcements. | ||
func TestNodeAliasValidation(t *testing.T) { | ||
t.Parallel() | ||
|
||
var testCases = []struct { | ||
alias string | ||
valid bool | ||
}{ | ||
// UTF-8 alias with valid length. | ||
{ | ||
alias: "meruem", | ||
valid: true, | ||
}, | ||
|
||
// UTF-8 alias with invalid length. | ||
{ | ||
alias: "p3kysxqr23swl33m6h5grmzddgw5nsgkky3g52zc6frpwz", | ||
valid: false, | ||
}, | ||
|
||
// String with non UTF-8 characters. | ||
{ | ||
alias: "\xE0\x80\x80", | ||
valid: false, | ||
}, | ||
} | ||
for i, testCase := range testCases { | ||
_, err := NewNodeAlias(testCase.alias) | ||
switch { | ||
case err != nil && testCase.valid: | ||
t.Fatalf("#%v: alias should have been invalid", i) | ||
|
||
case err == nil && !testCase.valid: | ||
t.Fatalf("#%v: invalid alias was missed", i) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters