Skip to content

Commit

Permalink
fix: ensure to actually copy static headers
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Schäfer <101886095+PeterSchafer@users.noreply.github.com>
  • Loading branch information
PeterSchafer committed Dec 13, 2022
1 parent 3eef6b0 commit 73c09da
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
9 changes: 8 additions & 1 deletion pkg/networking/networking.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,14 @@ func (n *NetworkImpl) AddHeaderField(key string, value string) {
}

func (n *NetworkImpl) GetDefaultHeader(url *url.URL) http.Header {
h := n.staticHeader
h := http.Header{}

// add static header
for k, v := range n.staticHeader {
for i := range v {
h.Add(k, v[i])
}
}

if url != nil {
// determine configured api url
Expand Down
20 changes: 12 additions & 8 deletions pkg/networking/networking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ func Test_GetDefaultHeader_WithAuth(t *testing.T) {
"Authorization": {"token " + token},
}

url, _ := url.Parse(config.GetString(configuration.API_URL))
actualHeader := net.GetDefaultHeader(url)

assert.Equal(t, expectedHeader, actualHeader)
// run method under test multiple times to ensure that it behaves the same way each time
for i := 0; i < 3; i++ {
url, _ := url.Parse(config.GetString(configuration.API_URL))
actualHeader := net.GetDefaultHeader(url)
assert.Equal(t, expectedHeader, actualHeader)
}
}

func Test_GetDefaultHeader_WithoutAuth(t *testing.T) {
Expand All @@ -47,10 +49,12 @@ func Test_GetDefaultHeader_WithoutAuth(t *testing.T) {
"User-Agent": {defaultUserAgent},
}

url, _ := url.Parse("https://www.myexample.com")
actualHeader := net.GetDefaultHeader(url)

assert.Equal(t, expectedHeader, actualHeader)
// run method under test multiple times to ensure that it behaves the same way each time
for i := 0; i < 3; i++ {
url, _ := url.Parse("https://www.myexample.com")
actualHeader := net.GetDefaultHeader(url)
assert.Equal(t, expectedHeader, actualHeader)
}
}

func Test_Roundtripper_SecureHTTPS(t *testing.T) {
Expand Down

0 comments on commit 73c09da

Please sign in to comment.