forked from BuzzBumbleBee/fosite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: isloopback returns true incorrectly (ory#765)
Closes ory#750
- Loading branch information
1 parent
f75e657
commit f4555cb
Showing
2 changed files
with
74 additions
and
2 deletions.
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,69 @@ | ||
// Copyright © 2023 Ory Corp | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package fosite | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestIsLookbackAddress(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
have string | ||
expected bool | ||
}{ | ||
{ | ||
"ShouldReturnTrueIPv4Loopback", | ||
"127.0.0.1", | ||
true, | ||
}, | ||
{ | ||
"ShouldReturnTrueIPv4LoopbackWithPort", | ||
"127.0.0.1:1230", | ||
true, | ||
}, | ||
{ | ||
"ShouldReturnTrueIPv6Loopback", | ||
"[::1]", | ||
true, | ||
}, | ||
{ | ||
"ShouldReturnTrueIPv6LoopbackWithPort", | ||
"[::1]:1230", | ||
true, | ||
}, { | ||
"ShouldReturnFalse12700255", | ||
"127.0.0.255", | ||
false, | ||
}, | ||
{ | ||
"ShouldReturnFalse12700255WithPort", | ||
"127.0.0.255:1230", | ||
false, | ||
}, | ||
{ | ||
"ShouldReturnFalseInvalidFourthOctet", | ||
"127.0.0.11230", | ||
false, | ||
}, | ||
{ | ||
"ShouldReturnFalseInvalidIPv4", | ||
"127x0x0x11230", | ||
false, | ||
}, | ||
{ | ||
"ShouldReturnFalseInvalidIPv6", | ||
"[::1]1230", | ||
false, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
assert.Equal(t, tc.expected, isLoopbackAddress(tc.have)) | ||
}) | ||
} | ||
} |