mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-06-02 03:01:37 +02:00
fix IsValidRelayURL
This commit is contained in:
parent
f3f29950b7
commit
4f71918311
3
utils.go
3
utils.go
@ -14,9 +14,6 @@ func IsValidRelayURL(u string) bool {
|
|||||||
if parsed.Scheme != "wss" && parsed.Scheme != "ws" {
|
if parsed.Scheme != "wss" && parsed.Scheme != "ws" {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if len(strings.Split(parsed.Host, ".")) < 2 {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
28
utils_test.go
Normal file
28
utils_test.go
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
package nostr
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestIsValidRelayURL(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
u string
|
||||||
|
want bool
|
||||||
|
}{
|
||||||
|
{"ws://127.0.0.1", true},
|
||||||
|
{"ws://localhost", true},
|
||||||
|
{"wss://localhost", true},
|
||||||
|
{"wss://relay.nostr.com", true},
|
||||||
|
{"http://127.0.0.1", false},
|
||||||
|
{"127.0.0.1", false},
|
||||||
|
//{"wss://relay.nostr.com'", false},
|
||||||
|
//{"wss://relay.nostr.com'hiphop", true},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
got := IsValidRelayURL(test.u)
|
||||||
|
if got != test.want {
|
||||||
|
t.Errorf("IsValidRelayURL want %v for %q but got %v", test.want, test.u, got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user