Skip to content

Commit

Permalink
Check that proxy URL starts with http://
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumerose authored and gbraad committed Jul 13, 2020
1 parent 1904e3a commit 95d8759
Show file tree
Hide file tree
Showing 25 changed files with 6,059 additions and 0 deletions.
1 change: 1 addition & 0 deletions go.mod
Expand Up @@ -23,6 +23,7 @@ require (
github.com/spf13/cobra v0.0.3
github.com/spf13/pflag v1.0.3
github.com/spf13/viper v1.3.2
github.com/stretchr/testify v1.3.0
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4
golang.org/x/sys v0.0.0-20200116001909-b77594299b42
Expand Down
6 changes: 6 additions & 0 deletions pkg/crc/network/proxy.go
Expand Up @@ -133,6 +133,12 @@ func ValidateProxyURL(proxyUrl string) error {
return nil
}

if strings.HasPrefix(proxyUrl, "https://") {
return fmt.Errorf("Proxy URL '%s' is not valid: https is not supported", proxyUrl)
}
if !strings.HasPrefix(proxyUrl, "http://") {
return fmt.Errorf("Proxy URL '%s' is not valid: url should start with http://", proxyUrl)
}
if !govalidator.IsURL(proxyUrl) {
return fmt.Errorf("Proxy URL '%s' is not valid.", proxyUrl)
}
Expand Down
14 changes: 14 additions & 0 deletions pkg/crc/network/proxy_test.go
@@ -0,0 +1,14 @@
package network

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestValidateProxyURL(t *testing.T) {
assert.NoError(t, ValidateProxyURL("http://company.com"))

assert.EqualError(t, ValidateProxyURL("company.com:8080"), "Proxy URL 'company.com:8080' is not valid: url should start with http://")
assert.EqualError(t, ValidateProxyURL("https://company.com"), "Proxy URL 'https://company.com' is not valid: https is not supported")
}
15 changes: 15 additions & 0 deletions vendor/github.com/davecgh/go-spew/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

145 changes: 145 additions & 0 deletions vendor/github.com/davecgh/go-spew/spew/bypass.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions vendor/github.com/davecgh/go-spew/spew/bypasssafe.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 95d8759

Please sign in to comment.