From d4b8e23d94287788513688c93d8e02429e234788 Mon Sep 17 00:00:00 2001 From: James Elliott Date: Sat, 19 Aug 2023 12:15:50 +1000 Subject: [PATCH] test: add test case for 750 This adds a test case proving #750 --- authorize_helper_whitebox_test.go | 66 +++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 authorize_helper_whitebox_test.go diff --git a/authorize_helper_whitebox_test.go b/authorize_helper_whitebox_test.go new file mode 100644 index 00000000..de3a37c3 --- /dev/null +++ b/authorize_helper_whitebox_test.go @@ -0,0 +1,66 @@ +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, + }, + { + "ShouldReturnTrue12700255WithPort", + "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)) + }) + } +}