Skip to content

Commit 548c9c3

Browse files
author
Kazuyoshi Kato
committed
1 parent 7eae7f2 commit 548c9c3

2 files changed

Lines changed: 25 additions & 4 deletions

File tree

remotes/docker/auth/parse.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,6 @@ func parseValueAndParams(header string) (value string, params map[string]string)
134134
}
135135
var pvalue string
136136
pvalue, s = expectTokenOrQuoted(s[1:])
137-
if pvalue == "" {
138-
return
139-
}
140137
pkey = strings.ToLower(pkey)
141138
params[pkey] = pvalue
142139
s = skipSpace(s)

remotes/docker/auth/parse_test.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ import (
2121
"net/http"
2222
"reflect"
2323
"testing"
24+
25+
"github.com/stretchr/testify/assert"
2426
)
2527

26-
func TestParseAuthHeader(t *testing.T) {
28+
func TestParseAuthHeaderBearer(t *testing.T) {
2729
headerTemplate := `Bearer realm="%s",service="%s",scope="%s"`
2830

2931
for _, tc := range []struct {
@@ -69,3 +71,25 @@ func TestParseAuthHeader(t *testing.T) {
6971
})
7072
}
7173
}
74+
75+
func TestParseAuthHeader(t *testing.T) {
76+
v := `Bearer realm="https://auth.example.io/token",empty="",service="registry.example.io",scope="repository:library/hello-world:pull,push"`
77+
h := http.Header{http.CanonicalHeaderKey("WWW-Authenticate"): []string{v}}
78+
challenge := ParseAuthHeader(h)
79+
80+
actual, ok := challenge[0].Parameters["empty"]
81+
assert.True(t, ok)
82+
assert.Equal(t, "", actual)
83+
84+
actual, ok = challenge[0].Parameters["service"]
85+
assert.True(t, ok)
86+
assert.Equal(t, "registry.example.io", actual)
87+
}
88+
89+
func FuzzParseAuthHeader(f *testing.F) {
90+
f.Add(`Bearer realm="https://example.com/token",service="example.com",scope="repository:foo/bar:pull,push"`)
91+
f.Fuzz(func(t *testing.T, v string) {
92+
h := http.Header{http.CanonicalHeaderKey("WWW-Authenticate"): []string{v}}
93+
_ = ParseAuthHeader(h)
94+
})
95+
}

0 commit comments

Comments
 (0)