-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Normalize auth key before calling
SetAuthentication
Recent changes in c/image caused the `SetAuthentication` API to be more restrictive in terms of validating the `key` (`server`) input. To ensure that manually modified or entries in `~/.docker/config.json` still work, we now strip the leading `http[s]://` prefix. Fixes #11235 Signed-off-by: Sascha Grunert <[email protected]>
- Loading branch information
1 parent
858d3e4
commit bbdaf83
Showing
2 changed files
with
85 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package auth | ||
|
||
import ( | ||
"io/ioutil" | ||
"testing" | ||
|
||
"github.com/containers/image/v5/types" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestAuthConfigsToAuthFile(t *testing.T) { | ||
for _, tc := range []struct { | ||
name string | ||
server string | ||
shouldErr bool | ||
expectedContains string | ||
}{ | ||
{ | ||
name: "empty auth configs", | ||
server: "", | ||
shouldErr: false, | ||
expectedContains: "{}", | ||
}, | ||
{ | ||
name: "registry with prefix", | ||
server: "my-registry.local/username", | ||
shouldErr: false, | ||
expectedContains: `"my-registry.local/username":`, | ||
}, | ||
{ | ||
name: "normalize https:// prefix", | ||
server: "http://my-registry.local/username", | ||
shouldErr: false, | ||
expectedContains: `"my-registry.local/username":`, | ||
}, | ||
{ | ||
name: "normalize docker registry with https prefix", | ||
server: "http://index.docker.io/v1/", | ||
shouldErr: false, | ||
expectedContains: `"index.docker.io":`, | ||
}, | ||
{ | ||
name: "normalize docker registry without https prefix", | ||
server: "docker.io/v2/", | ||
shouldErr: false, | ||
expectedContains: `"docker.io":`, | ||
}, | ||
} { | ||
configs := map[string]types.DockerAuthConfig{} | ||
if tc.server != "" { | ||
configs[tc.server] = types.DockerAuthConfig{} | ||
} | ||
|
||
filePath, err := authConfigsToAuthFile(configs) | ||
|
||
if tc.shouldErr { | ||
assert.NotNil(t, err) | ||
assert.Empty(t, filePath) | ||
} else { | ||
assert.Nil(t, err) | ||
content, err := ioutil.ReadFile(filePath) | ||
assert.Nil(t, err) | ||
assert.Contains(t, string(content), tc.expectedContains) | ||
} | ||
} | ||
} |