Merge pull request #85687 from dmage/decode_base64

fix: padded base64 encoded docker auth field
This commit is contained in:
Kubernetes Prow Robot 2019-11-28 11:17:03 -08:00 committed by GitHub
commit 53740bbade
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 2 deletions

View File

@ -287,8 +287,7 @@ func decodeDockerConfigFieldAuth(field string) (username, password string, err e
// StdEncoding can only decode padded string
// RawStdEncoding can only decode unpadded string
// a string is correctly padded if and only if its length is a multiple of 4
if (len(field) % 4) == 0 {
if strings.HasSuffix(strings.TrimSpace(field), "=") {
// decode padded data
decoded, err = base64.StdEncoding.DecodeString(field)
} else {

View File

@ -214,6 +214,13 @@ func TestDecodeDockerConfigFieldAuth(t *testing.T) {
password: "bar",
},
// some test as before but with new line characters
{
input: "Zm9vOm\nJhcg==\n",
username: "foo",
password: "bar",
},
// standard encoding (with padding)
{
input: base64.StdEncoding.EncodeToString([]byte("foo:bar")),
@ -241,6 +248,12 @@ func TestDecodeDockerConfigFieldAuth(t *testing.T) {
fail: true,
},
// only new line characters are ignored
{
input: "Zm9vOmJhcg== ",
fail: true,
},
// bad base64 data
{
input: "pants",