-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
validate backend #1908
Merged
Merged
validate backend #1908
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
73aefb6
validate backend
rawdaGastan e61c8a7
allow negative numbers + add ipv6 tests
rawdaGastan 129f13d
prevent negative numbers + add ipv6 tests
rawdaGastan 1e22626
expand function docs
rawdaGastan 20c9a6c
Merge branch 'development_backend_validate' of https://github.com/thr…
rawdaGastan e3a8f5e
expand function docs
rawdaGastan b8072ca
change valid to parse
rawdaGastan 3debc75
fix use backend instead of host
rawdaGastan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
package zos | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestValidBackend(t *testing.T) { | ||
require := require.New(t) | ||
|
||
t.Run("test ip:port cases", func(t *testing.T) { | ||
rawdaGastan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
backend := Backend("1.1.1.1:10") | ||
err := backend.Valid(true) | ||
require.NoError(err) | ||
|
||
backend = Backend("1.1.1.1:10") | ||
err = backend.Valid(false) | ||
require.Error(err) | ||
|
||
backend = Backend("1.1.1.1") | ||
err = backend.Valid(true) | ||
require.Error(err) | ||
|
||
backend = Backend("1.1.1.1:port") | ||
err = backend.Valid(true) | ||
require.Error(err) | ||
|
||
backend = Backend("ip:10") | ||
err = backend.Valid(true) | ||
require.Error(err) | ||
|
||
backend = Backend("1.1.1.1:1000000") | ||
err = backend.Valid(true) | ||
require.Error(err) | ||
}) | ||
|
||
t.Run("test http://ip:port cases", func(t *testing.T) { | ||
backend := Backend("http://1.1.1.1:10") | ||
err := backend.Valid(false) | ||
require.NoError(err) | ||
|
||
backend = Backend("http://1.1.1.1:10") | ||
err = backend.Valid(true) | ||
require.Error(err) | ||
|
||
backend = Backend("http://1.1.1.1:port") | ||
err = backend.Valid(false) | ||
require.Error(err) | ||
|
||
backend = Backend("http://ip:10") | ||
err = backend.Valid(false) | ||
require.Error(err) | ||
}) | ||
|
||
t.Run("test http://ip cases", func(t *testing.T) { | ||
backend := Backend("http://1.1.1.1") | ||
err := backend.Valid(false) | ||
require.NoError(err) | ||
|
||
backend = Backend("http://1.1.1.1") | ||
err = backend.Valid(true) | ||
require.Error(err) | ||
|
||
backend = Backend("http://ip") | ||
err = backend.Valid(false) | ||
require.Error(err) | ||
}) | ||
} | ||
|
||
func TestValidBackendIP6(t *testing.T) { | ||
require := require.New(t) | ||
|
||
t.Run("test ip:port cases", func(t *testing.T) { | ||
backend := Backend("[2001:db8:3333:4444:CCCC:DDDD:EEEE:FFFF]:10") | ||
err := backend.Valid(true) | ||
require.NoError(err) | ||
|
||
backend = Backend("[2001:db8:3333:4444:CCCC:DDDD:EEEE:FFFF]:10") | ||
err = backend.Valid(false) | ||
require.Error(err) | ||
|
||
backend = Backend("[2001:db8:3333:4444:CCCC:DDDD:EEEE:FFFF]:port") | ||
err = backend.Valid(true) | ||
require.Error(err) | ||
|
||
backend = Backend("[2001:db8:3333:4444:CCCC:DDDD:EEEE:FFFF]:1000000") | ||
err = backend.Valid(true) | ||
require.Error(err) | ||
}) | ||
|
||
t.Run("test http://ip:port cases", func(t *testing.T) { | ||
backend := Backend("http://[2001:db8:3333:4444:CCCC:DDDD:EEEE:FFFF]:10") | ||
err := backend.Valid(false) | ||
require.NoError(err) | ||
|
||
backend = Backend("http://[2001:db8:3333:4444:CCCC:DDDD:EEEE:FFFF]:10") | ||
err = backend.Valid(true) | ||
require.Error(err) | ||
|
||
backend = Backend("http://[2001:db8:3333:4444:CCCC:DDDD:EEEE:FFFF]:port") | ||
err = backend.Valid(false) | ||
require.Error(err) | ||
}) | ||
|
||
t.Run("test http://ip cases", func(t *testing.T) { | ||
backend := Backend("http://[2001:db8:3333:4444:CCCC:DDDD:EEEE:FFFF]") | ||
err := backend.Valid(false) | ||
require.NoError(err) | ||
|
||
backend = Backend("http://[2001:db8:3333:4444:CCCC:DDDD:EEEE:FFFF]") | ||
err = backend.Valid(true) | ||
require.Error(err) | ||
}) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is wrong because you need to return
ip:port
in case of tls, orhttp://ip:port
in case of no tls