Skip to content

Commit 2fe95cc

Browse files
lmvlmvlverrall
andauthored
Add check for for valid URLs and unit tests (#49)
* Add check for for valid URLs and unit tests * Fix up tests --------- Co-authored-by: Leon Verrall <lverrall@slb.com>
1 parent ab8f06a commit 2fe95cc

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

client/client.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ func NewClient(c *Config) (*Client, error) {
8282
if err != nil {
8383
return nil, err
8484
}
85+
86+
if !regexp.MustCompile(`(slb\.com|slb-ds\.com|cluster\.local|localhost|-service|127\.0\.0\.1)[:\d]*$`).MatchString(u.Host) {
87+
return nil, errors.New("Invalid URL " + u.Host)
88+
}
89+
8590
//swap to websockets scheme
8691
u.Scheme = strings.Replace(u.Scheme, "http", "ws", 1)
8792
//apply default port

client/client_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ func TestCustomHeaders(t *testing.T) {
4747
func TestFallbackLegacyFingerprint(t *testing.T) {
4848
config := Config{
4949
Fingerprint: "a5:32:92:c6:56:7a:9e:61:26:74:1b:81:a6:f5:1b:44",
50+
Server: "http://localhost:9000",
5051
}
5152
c, err := NewClient(&config)
5253
if err != nil {
@@ -70,6 +71,7 @@ func TestFallbackLegacyFingerprint(t *testing.T) {
7071
func TestVerifyLegacyFingerprint(t *testing.T) {
7172
config := Config{
7273
Fingerprint: "a5:32:92:c6:56:7a:9e:61:26:74:1b:81:a6:f5:1b:44",
74+
Server: "http://localhost:9000",
7375
}
7476
c, err := NewClient(&config)
7577
if err != nil {
@@ -93,6 +95,7 @@ func TestVerifyLegacyFingerprint(t *testing.T) {
9395
func TestVerifyFingerprint(t *testing.T) {
9496
config := Config{
9597
Fingerprint: "qmrRoo8MIqePv3jC8+wv49gU6uaFgD3FASQx9V8KdmY=",
98+
Server: "http://localhost:9000",
9699
}
97100
c, err := NewClient(&config)
98101
if err != nil {

0 commit comments

Comments
 (0)