mirror of
https://github.com/nais/wonderwall.git
synced 2026-05-06 00:17:27 +00:00
style: go fix
This commit is contained in:
@@ -3,6 +3,7 @@ package http
|
||||
import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/nais/wonderwall/pkg/cookie"
|
||||
@@ -34,15 +35,13 @@ func Accepts(r *http.Request, accepted ...string) bool {
|
||||
// iterate over all Accept headers
|
||||
for _, header := range r.Header.Values("Accept") {
|
||||
// iterate over all comma-separated values in a single Accept header
|
||||
for _, v := range strings.Split(header, ",") {
|
||||
for v := range strings.SplitSeq(header, ",") {
|
||||
v = strings.ToLower(v)
|
||||
v = strings.TrimSpace(v)
|
||||
v = strings.Split(v, ";")[0]
|
||||
|
||||
for _, accept := range accepted {
|
||||
if v == accept {
|
||||
return true
|
||||
}
|
||||
if slices.Contains(accepted, v) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ func TestHandler_Error(t *testing.T) {
|
||||
r := idp.GetRequest(idp.RelyingPartyServer.URL)
|
||||
|
||||
// should be automatically redirected to the retry URI until maximum attempts are exhausted
|
||||
for i := 0; i < errorhandler.MaxAutoRetryAttempts; i++ {
|
||||
for range errorhandler.MaxAutoRetryAttempts {
|
||||
w := httptest.NewRecorder()
|
||||
|
||||
test.fn(w, r, fmt.Errorf("some error"))
|
||||
|
||||
@@ -85,7 +85,7 @@ func (l *logEntryAdapter) Write(status, bytes int, _ http.Header, elapsed time.D
|
||||
Debugf("response: %d %s", status, http.StatusText(status))
|
||||
}
|
||||
|
||||
func (l *logEntryAdapter) Panic(v interface{}, _ []byte) {
|
||||
func (l *logEntryAdapter) Panic(v any, _ []byte) {
|
||||
stacktrace := "#"
|
||||
|
||||
fields := log.Fields{
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"net/http/cookiejar"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"slices"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -309,13 +310,7 @@ func (ip *IdentityProviderHandler) parseAuthorizationRequest(query url.Values) (
|
||||
for param, allowed := range allowedParamValues {
|
||||
paramValue := query.Get(param)
|
||||
|
||||
found := false
|
||||
for _, allowedValue := range allowed {
|
||||
if paramValue == allowedValue {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
found := slices.Contains(allowed, paramValue)
|
||||
|
||||
if !found {
|
||||
return nil, fmt.Errorf("%q is an invalid value for %q, must be %q", paramValue, param, allowed)
|
||||
|
||||
@@ -2,6 +2,7 @@ package acr
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"slices"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -40,10 +41,8 @@ func Validate(expected, actual string) error {
|
||||
return fmt.Errorf("invalid acr: got %q, expected %q", actual, expected)
|
||||
}
|
||||
|
||||
for _, accepted := range acceptedValues {
|
||||
if actual == accepted {
|
||||
return nil
|
||||
}
|
||||
if slices.Contains(acceptedValues, actual) {
|
||||
return nil
|
||||
}
|
||||
|
||||
return fmt.Errorf("invalid acr: got %q, must be one of %s", actual, acceptedValues)
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"slices"
|
||||
|
||||
"github.com/lestrrat-go/jwx/v3/jwa"
|
||||
log "github.com/sirupsen/logrus"
|
||||
@@ -192,10 +193,8 @@ func (c *ProviderMetadata) validateLocaleValues(locale string) error {
|
||||
}
|
||||
|
||||
func (c *ProviderMetadata) validateIDTokenSigningAlg(algorithm string) error {
|
||||
for _, alg := range c.IDTokenSigningAlgValuesSupported {
|
||||
if alg == algorithm {
|
||||
return nil
|
||||
}
|
||||
if slices.Contains(c.IDTokenSigningAlgValuesSupported, algorithm) {
|
||||
return nil
|
||||
}
|
||||
|
||||
return fmt.Errorf("identity provider does not support '%s=%s', must be one of %s", config.OpenIDIDTokenSigningAlg, algorithm, c.IDTokenSigningAlgValuesSupported)
|
||||
@@ -204,10 +203,5 @@ func (c *ProviderMetadata) validateIDTokenSigningAlg(algorithm string) error {
|
||||
type Supported []string
|
||||
|
||||
func (in Supported) Contains(value string) bool {
|
||||
for _, allowed := range in {
|
||||
if allowed == value {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
return slices.Contains(in, value)
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package openid
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"maps"
|
||||
"net/url"
|
||||
|
||||
"github.com/nais/wonderwall/pkg/openid/scopes"
|
||||
@@ -119,9 +120,7 @@ func (a RequestParams) URLValues() url.Values {
|
||||
// With returns a new RequestParams with the given RequestParams added.
|
||||
// Conflicting keys are overridden by the given RequestParams.
|
||||
func (a RequestParams) With(other RequestParams) RequestParams {
|
||||
for key, val := range other {
|
||||
a[key] = val
|
||||
}
|
||||
maps.Copy(a, other)
|
||||
|
||||
return a
|
||||
}
|
||||
|
||||
@@ -240,7 +240,7 @@ func (in *IDToken) StringSliceClaim(claim string) ([]string, error) {
|
||||
}
|
||||
|
||||
// the claim is a slice of interfaces...
|
||||
claimValues, ok := gotClaim.([]interface{})
|
||||
claimValues, ok := gotClaim.([]any)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("'%s' claim is not a slice", claim)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user