Skip to content

Commit

Permalink
chore: fix failing tests
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 Jul 8, 2022
1 parent 070a067 commit 6410599
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 23 deletions.
2 changes: 2 additions & 0 deletions cliv2/internal/httpauth/httpauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package httpauth

import (
"fmt"
"io"
"log"
"net/url"
)
Expand Down Expand Up @@ -55,6 +56,7 @@ func NewHandler(mechanism AuthenticationMechanism) AuthenticationHandlerInterfac
spnegoProvider: SpnegoProviderInstance(),
Mechanism: mechanism,
state: Initial,
logger: log.New(io.Discard, "", 0),
}
return a
}
Expand Down
25 changes: 19 additions & 6 deletions cliv2/internal/httpauth/httpauth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ func Test_DisableAuthentication(t *testing.T) {
proxyAddr, _ := url.Parse("http://127.0.0.1")
expectedValue := ""

authHandler := httpauth.AuthenticationHandler{
Mechanism: httpauth.NoAuth,
}
authHandler := httpauth.NewHandler(httpauth.NoAuth)

actualValue, err := authHandler.GetAuthorizationValue(proxyAddr, "")
assert.Nil(t, err)
Expand All @@ -29,9 +27,7 @@ func Test_EnabledAuthentication_Mock(t *testing.T) {
proxyAddr, _ := url.Parse("http://127.0.0.1")
expectedValue := "Mock"

authHandler := httpauth.AuthenticationHandler{
Mechanism: httpauth.Mock,
}
authHandler := httpauth.NewHandler(httpauth.Mock)

actualValue, err := authHandler.GetAuthorizationValue(proxyAddr, "")
assert.Nil(t, err)
Expand Down Expand Up @@ -59,3 +55,20 @@ func Test_AuthenticationMechanismFromAndToString(t *testing.T) {
}

}

func Test_LookupSchemeFromAddress(t *testing.T) {
defaultValue := "none"

input := map[string]string{
"snyk.io:443": "https",
"snyk.io:80": "http",
"snyk.io:1080": "socks5",
"snyk.io": defaultValue,
"snyk.io:443:das": defaultValue,
}

for addr, expected := range input {
actual := httpauth.LookupSchemeFromCannonicalAddress(addr, defaultValue)
assert.Equal(t, expected, actual)
}
}
17 changes: 0 additions & 17 deletions cliv2/internal/proxy/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,20 +210,3 @@ func Test_SetUpstreamProxy(t *testing.T) {
assert.Nil(t, err)
assert.Equal(t, expectedUrl, actualUrl)
}

func Test_LookupSchemeFromAddress(t *testing.T) {
defaultValue := "none"

input := map[string]string{
"snyk.io:443": "https",
"snyk.io:80": "http",
"snyk.io:1080": "socks5",
"snyk.io": defaultValue,
"snyk.io:443:das": defaultValue,
}

for addr, expected := range input {
actual := proxy.LookupSchemeFromCannonicalAddress(addr, defaultValue)
assert.Equal(t, expected, actual)
}
}

0 comments on commit 6410599

Please sign in to comment.