Skip to content

Commit

Permalink
update: remove unused function and move helpers to internal
Browse files Browse the repository at this point in the history
  • Loading branch information
davidebianchi committed Jul 5, 2023
1 parent 6202e76 commit 2d96aab
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 216 deletions.
74 changes: 0 additions & 74 deletions helpers/headers_to_proxy.go

This file was deleted.

137 changes: 0 additions & 137 deletions helpers/headers_to_proxy_test.go

This file was deleted.

File renamed without changes.
File renamed without changes.
30 changes: 30 additions & 0 deletions internal/helpers/headers_to_proxy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2021 Mia srl
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package helpers

import (
"net/http"
)

func GetHeadersToProxy(r *http.Request, headerNamesToAdd []string) http.Header {
headersToProxy := http.Header{}
for _, headerNameToAdd := range headerNamesToAdd {
headerValue := r.Header.Get(headerNameToAdd)
if len(headerValue) > 0 {
headersToProxy.Set(headerNameToAdd, headerValue)
}
}
return headersToProxy
}
52 changes: 52 additions & 0 deletions internal/helpers/headers_to_proxy_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright 2021 Mia srl
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package helpers

import (
"net/http"
"net/http/httptest"
"testing"

"github.com/stretchr/testify/require"
)

func TestGetHeadersToProxy(t *testing.T) {
t.Run("not set header if empty headers to proxy", func(t *testing.T) {
req := httptest.NewRequest(http.MethodGet, "/", nil)
actual := GetHeadersToProxy(req, nil)

expected := http.Header{}

require.Equal(t, actual, expected)
})

t.Run("get headers to proxy correctly", func(t *testing.T) {
requestHeaders := http.Header{}
requestHeaders.Set("foo", "bar")
requestHeaders.Set("taz", "ok")
requestHeaders.Set("proxy", "me")

req := httptest.NewRequest(http.MethodGet, "/", nil)
req.Header = requestHeaders

actual := GetHeadersToProxy(req, []string{"foo", "proxy"})

expected := http.Header{}
expected.Set("foo", "bar")
expected.Set("proxy", "me")

require.Equal(t, actual, expected)
})
}
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import (

"github.com/prometheus/client_golang/prometheus"
"github.com/rond-authz/rond/core"
"github.com/rond-authz/rond/helpers"
"github.com/rond-authz/rond/internal/config"
"github.com/rond-authz/rond/internal/helpers"
"github.com/rond-authz/rond/internal/mongoclient"
"github.com/rond-authz/rond/openapi"
"github.com/rond-authz/rond/service"
Expand Down
3 changes: 0 additions & 3 deletions service/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"github.com/getkin/kin-openapi/openapi3"
"github.com/prometheus/client_golang/prometheus"
"github.com/rond-authz/rond/core"
"github.com/rond-authz/rond/helpers"
"github.com/rond-authz/rond/internal/config"
"github.com/rond-authz/rond/internal/metrics"
"github.com/rond-authz/rond/internal/mongoclient"
Expand Down Expand Up @@ -116,8 +115,6 @@ func SetupRouter(

evalRouter := router.NewRoute().Subrouter()
if env.Standalone {
router.Use(helpers.AddHeadersToProxyMiddleware(log, env.GetAdditionalHeadersToProxy()))

swaggerRouter, err := swagger.NewRouter(gorilla.NewRouter(router), swagger.Options{
Context: context.Background(),
Openapi: &openapi3.T{
Expand Down
2 changes: 1 addition & 1 deletion service/standalone_apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (
"fmt"
"net/http"

"github.com/rond-authz/rond/helpers"
"github.com/rond-authz/rond/internal/config"
"github.com/rond-authz/rond/internal/helpers"
"github.com/rond-authz/rond/internal/utils"
"github.com/rond-authz/rond/types"

Expand Down

0 comments on commit 2d96aab

Please sign in to comment.