Skip to content

Commit

Permalink
Fix lint gosec (#528)
Browse files Browse the repository at this point in the history
  • Loading branch information
p53 authored Dec 15, 2024
1 parent 3ba6ade commit f14863f
Show file tree
Hide file tree
Showing 11 changed files with 160 additions and 77 deletions.
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ linters:
- ireturn
- maintidx
- wrapcheck
- gosec
- gocritic
- gci
- gofumpt
Expand Down
68 changes: 45 additions & 23 deletions e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package e2e_test
import (
"bytes"
"context"
"crypto/rand"
"fmt"
"math/rand"
"math/big"
"net"
"net/http"
"net/http/httptest"
Expand All @@ -30,14 +31,18 @@ import (
)

const (
testRealm = "test"
testClient = "test-client"
testClientSecret = "6447d0c0-d510-42a7-b654-6e3a16b2d7e2"
pkceTestClient = "test-client-pkce"
pkceTestClientSecret = "F2GqU40xwX0P2LrTvHUHqwNoSk4U4n5R"
umaTestClient = "test-client-uma"
umaTestClientSecret = "A5vokiGdI3H2r4aXFrANbKvn4R7cbf6P"
loaTestClient = "test-loa"
testRealm = "test"
testClient = "test-client"
//nolint:gosec
testClientSecret = "6447d0c0-d510-42a7-b654-6e3a16b2d7e2"
pkceTestClient = "test-client-pkce"
//nolint:gosec
pkceTestClientSecret = "F2GqU40xwX0P2LrTvHUHqwNoSk4U4n5R"
umaTestClient = "test-client-uma"
//nolint:gosec
umaTestClientSecret = "A5vokiGdI3H2r4aXFrANbKvn4R7cbf6P"
loaTestClient = "test-loa"
//nolint:gosec
loaTestClientSecret = "4z9PoOooXNFmSCPZx0xHXaUxX4eYGFO0"
timeout = time.Second * 300
idpURI = "http://localhost:8081"
Expand All @@ -59,18 +64,24 @@ const (
loaStepUpPath = "/level2"
loaDefaultLevel = "level1"
loaStepUpLevel = "level2"
otpSecret = "NE4VKZJYKVDDSYTIK5CVOOLVOFDFE2DC"
postLoginRedirectPath = "/post/login/path"
pkceCookieName = "TESTPKCECOOKIE"
//nolint:gosec
otpSecret = "NE4VKZJYKVDDSYTIK5CVOOLVOFDFE2DC"
postLoginRedirectPath = "/post/login/path"
pkceCookieName = "TESTPKCECOOKIE"
)

var idpRealmURI = fmt.Sprintf("%s/realms/%s", idpURI, testRealm)

func generateRandomPort() string {
rg := rand.New(rand.NewSource(time.Now().UnixNano()))
minPort := 1024
maxPort := 65000
return strconv.Itoa(rg.Intn(maxPort-minPort+1) + minPort)
func generateRandomPort() (string, error) {
var minPort int64 = 1024
var maxPort int64 = 65000
maxRand := big.NewInt(maxPort - minPort + 1)
randPort, err := rand.Int(rand.Reader, maxRand)
if err != nil {
return "", err
}
randP := int(randPort.Int64() + minPort)
return strconv.Itoa(randP), nil
}

func startAndWait(portNum string, osArgs []string) {
Expand Down Expand Up @@ -129,8 +140,10 @@ var _ = Describe("NoRedirects Simple login/logout", func() {
var proxyAddress string

BeforeEach(func() {
var err error
server := httptest.NewServer(&testsuite.FakeUpstreamService{})
portNum = generateRandomPort()
portNum, err = generateRandomPort()
Expect(err).NotTo(HaveOccurred())
proxyAddress = localURI + portNum

osArgs := []string{os.Args[0]}
Expand Down Expand Up @@ -189,8 +202,10 @@ var _ = Describe("Code Flow login/logout", func() {
var proxyAddress string

BeforeEach(func() {
var err error
server := httptest.NewServer(&testsuite.FakeUpstreamService{})
portNum = generateRandomPort()
portNum, err = generateRandomPort()
Expect(err).NotTo(HaveOccurred())
proxyAddress = localURI + portNum

osArgs := []string{os.Args[0]}
Expand Down Expand Up @@ -333,8 +348,10 @@ var _ = Describe("Code Flow PKCE login/logout", func() {
var proxyAddress string

BeforeEach(func() {
var err error
server := httptest.NewServer(&testsuite.FakeUpstreamService{})
portNum = generateRandomPort()
portNum, err = generateRandomPort()
Expect(err).NotTo(HaveOccurred())
proxyAddress = localURI + portNum
osArgs := []string{os.Args[0]}
proxyArgs := []string{
Expand Down Expand Up @@ -389,8 +406,10 @@ var _ = Describe("Code Flow login/logout with session check", func() {
var proxyAddressSec string

BeforeEach(func() {
var err error
server := httptest.NewServer(&testsuite.FakeUpstreamService{})
portNum = generateRandomPort()
portNum, err = generateRandomPort()
Expect(err).NotTo(HaveOccurred())
proxyAddressFirst = "http://127.0.0.1:" + portNum

osArgs := []string{os.Args[0]}
Expand All @@ -417,7 +436,8 @@ var _ = Describe("Code Flow login/logout with session check", func() {
osArgs = append(osArgs, proxyArgs...)
startAndWait(portNum, osArgs)

portNum = generateRandomPort()
portNum, err = generateRandomPort()
Expect(err).NotTo(HaveOccurred())
proxyAddressSec = localURI + portNum
osArgs = []string{os.Args[0]}
proxyArgs = []string{
Expand Down Expand Up @@ -488,8 +508,10 @@ var _ = Describe("Level Of Authentication Code Flow login/logout", func() {
var proxyAddress string

BeforeEach(func() {
var err error
server := httptest.NewServer(&testsuite.FakeUpstreamService{})
portNum = generateRandomPort()
portNum, err = generateRandomPort()
Expect(err).NotTo(HaveOccurred())
proxyAddress = localURI + portNum

osArgs := []string{os.Args[0]}
Expand Down
26 changes: 19 additions & 7 deletions e2e/e2e_uma_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ var _ = Describe("UMA Code Flow authorization", func() {
var umaCookieName = "TESTUMACOOKIE"

BeforeEach(func() {
var err error
server := httptest.NewServer(&testsuite.FakeUpstreamService{})
portNum = generateRandomPort()
portNum, err = generateRandomPort()
Expect(err).NotTo(HaveOccurred())
proxyAddress = localURI + portNum
osArgs := []string{os.Args[0]}
proxyArgs := []string{
Expand Down Expand Up @@ -117,8 +119,10 @@ var _ = Describe("UMA Code Flow authorization with method scope", func() {
var umaCookieName = "TESTUMACOOKIE"

BeforeEach(func() {
var err error
server := httptest.NewServer(&testsuite.FakeUpstreamService{})
portNum = generateRandomPort()
portNum, err = generateRandomPort()
Expect(err).NotTo(HaveOccurred())
proxyAddress = localURI + portNum
osArgs := []string{os.Args[0]}
proxyArgs := []string{
Expand Down Expand Up @@ -181,9 +185,12 @@ var _ = Describe("UMA no-redirects authorization with forwarding client credenti
var fwdProxyAddress string

BeforeEach(func() {
var err error
server := httptest.NewServer(&testsuite.FakeUpstreamService{})
portNum = generateRandomPort()
fwdPortNum = generateRandomPort()
portNum, err = generateRandomPort()
Expect(err).NotTo(HaveOccurred())
fwdPortNum, err = generateRandomPort()
Expect(err).NotTo(HaveOccurred())
proxyAddress = localURI + portNum
fwdProxyAddress = localURI + fwdPortNum
osArgs := []string{os.Args[0]}
Expand Down Expand Up @@ -265,9 +272,12 @@ var _ = Describe("UMA no-redirects authorization with forwarding direct access g
var fwdProxyAddress string

BeforeEach(func() {
var err error
server := httptest.NewServer(&testsuite.FakeUpstreamService{})
portNum = generateRandomPort()
fwdPortNum = generateRandomPort()
portNum, err = generateRandomPort()
Expect(err).NotTo(HaveOccurred())
fwdPortNum, err = generateRandomPort()
Expect(err).NotTo(HaveOccurred())
proxyAddress = localURI + portNum
fwdProxyAddress = localURI + fwdPortNum
osArgs := []string{os.Args[0]}
Expand Down Expand Up @@ -367,7 +377,9 @@ var _ = Describe("UMA Code Flow, NOPROXY authorization with method scope", func(
// server := httptest.NewServer(&testsuite.FakeUpstreamService{})

BeforeEach(func() {
portNum = generateRandomPort()
var err error
portNum, err = generateRandomPort()
Expect(err).NotTo(HaveOccurred())
proxyAddress = localURI + portNum
osArgs := []string{os.Args[0]}
proxyArgs := []string{
Expand Down
1 change: 1 addition & 0 deletions pkg/constant/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const (

AllPath = "/*"

//nolint:gosec
IdpWellKnownURI = "/.well-known/openid-configuration"
IdpCertsURI = "/protocol/openid-connect/certs"
IdpTokenURI = "/protocol/openid-connect/token"
Expand Down
Loading

0 comments on commit f14863f

Please sign in to comment.