-
Notifications
You must be signed in to change notification settings - Fork 8
Add method to check if IP Address is inside Block range #59
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
Open
cherchezlafemme
wants to merge
4
commits into
infratographer:main
Choose a base branch
from
cherchezlafemme:block-valid
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+183
−17
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
bc8cb5b
Add method to check if IP Address is inside Block range
cherchezlafemme 4bd40ac
Merge branch 'main' into block-valid
cherchezlafemme 959e7c3
Update error messages to validation of ips
cherchezlafemme 26dfce6
Add resolver tests
cherchezlafemme 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 hidden or 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,30 @@ | ||
| package validator | ||
|
|
||
| import ( | ||
| "errors" | ||
| "fmt" | ||
| ) | ||
|
|
||
| // ErrInvalidIPAddr is an error raised when provided IP Address is invalid | ||
| var ErrInvalidIPAddr = errors.New("ip Address is invalid") | ||
|
|
||
| // InvalidIPAddrError returns Error Invalid IP Address | ||
| func InvalidIPAddrError(ip string) error { | ||
| return fmt.Errorf("%w: %s", ErrInvalidIPAddr, ip) | ||
| } | ||
|
|
||
| // ErrInvalidIPPref is an error raised when provided IP Block Prefix is invalid | ||
| var ErrInvalidIPPref = errors.New("ip block prefix is invalid") | ||
|
|
||
| // InvalidIPPrefError returns Error Invalid IP Block Prefix | ||
| func InvalidIPPrefError(prefix string) error { | ||
| return fmt.Errorf("%w: %s", ErrInvalidIPPref, prefix) | ||
| } | ||
|
|
||
| // ErrIPAddrOutsideBlock is an error raised when provided IP Address is not part of the IP Block | ||
| var ErrIPAddrOutsideBlock = errors.New("ip address is invalid for IP Block Prefix") | ||
|
|
||
| // IPAddrOutsideBlockError returns Error IP Address doesn't belong to the IP Block | ||
| func IPAddrOutsideBlockError(block string, ip string) error { | ||
| return fmt.Errorf("%w: ip address: %s, ip block %s", ErrIPAddrOutsideBlock, ip, block) | ||
| } |
This file contains hidden or 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 hidden or 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,55 @@ | ||
| package validator | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestPartOfBlock(t *testing.T) { | ||
| type args struct { | ||
| ipBl string | ||
| ipAdrr string | ||
| } | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| args args | ||
| wantErr bool | ||
| }{ | ||
| { | ||
|
|
||
| name: "happy path", | ||
| args: args{ | ||
| ipBl: "192.168.1.0/28", | ||
| ipAdrr: "192.168.1.13"}, | ||
| wantErr: false, | ||
| }, | ||
| { | ||
| name: "outside block", | ||
| args: args{ | ||
| ipBl: "192.168.1.0/28", | ||
| ipAdrr: "192.168.1.25"}, | ||
| wantErr: true, | ||
| }, | ||
| { | ||
| name: "far from block", | ||
| args: args{ | ||
| ipBl: "108.1.80.128/30", | ||
| ipAdrr: "192.168.10.12"}, | ||
| wantErr: true, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| err := PartOfBlock(tt.args.ipBl, tt.args.ipAdrr) | ||
| if tt.wantErr { | ||
| assert.Error(t, err) | ||
| assert.ErrorContainsf(t, err, tt.args.ipAdrr, tt.args.ipBl) | ||
| } else { | ||
| assert.Nil(t, err) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.