(t *testing.T)
| 97 | } |
| 98 | |
| 99 | func TestRetrieveAuthTokenFromImage(t *testing.T) { |
| 100 | // configFileContent contains a plain-text "username:password", as stored by |
| 101 | // the plain-text store; |
| 102 | // https://github.com/docker/cli/blob/v28.0.4/cli/config/configfile/file.go#L218-L229 |
| 103 | const configFileContent = `{"auths": { |
| 104 | "https://index.docker.io/v1/": {"auth": "dXNlcm5hbWU6cGFzc3dvcmQ="}, |
| 105 | "[::1]": {"auth": "dXNlcm5hbWU6cGFzc3dvcmQ="}, |
| 106 | "[::1]:5000": {"auth": "dXNlcm5hbWU6cGFzc3dvcmQ="}, |
| 107 | "127.0.0.1": {"auth": "dXNlcm5hbWU6cGFzc3dvcmQ="}, |
| 108 | "127.0.0.1:5000": {"auth": "dXNlcm5hbWU6cGFzc3dvcmQ="}, |
| 109 | "localhost": {"auth": "dXNlcm5hbWU6cGFzc3dvcmQ="}, |
| 110 | "localhost:5000": {"auth": "dXNlcm5hbWU6cGFzc3dvcmQ="}, |
| 111 | "registry-1.docker.io": {"auth": "dXNlcm5hbWU6cGFzc3dvcmQ="}, |
| 112 | "registry.hub.docker.com": {"auth": "dXNlcm5hbWU6cGFzc3dvcmQ="} |
| 113 | } |
| 114 | }` |
| 115 | cfg := configfile.ConfigFile{} |
| 116 | err := cfg.LoadFromReader(bytes.NewReader([]byte(configFileContent))) |
| 117 | assert.NilError(t, err) |
| 118 | |
| 119 | remoteRefs := []string{ |
| 120 | "ubuntu", |
| 121 | "ubuntu:latest", |
| 122 | "ubuntu:latest@sha256:72297848456d5d37d1262630108ab308d3e9ec7ed1c3286a32fe09856619a782", |
| 123 | "ubuntu@sha256:72297848456d5d37d1262630108ab308d3e9ec7ed1c3286a32fe09856619a782", |
| 124 | "library/ubuntu", |
| 125 | "library/ubuntu:latest", |
| 126 | "library/ubuntu:latest@sha256:72297848456d5d37d1262630108ab308d3e9ec7ed1c3286a32fe09856619a782", |
| 127 | "library/ubuntu@sha256:72297848456d5d37d1262630108ab308d3e9ec7ed1c3286a32fe09856619a782", |
| 128 | } |
| 129 | |
| 130 | tests := []struct { |
| 131 | prefix string |
| 132 | expectedAddress string |
| 133 | expectedAuthCfg registry.AuthConfig |
| 134 | }{ |
| 135 | { |
| 136 | prefix: "", |
| 137 | expectedAddress: "https://index.docker.io/v1/", |
| 138 | expectedAuthCfg: registry.AuthConfig{Username: "username", Password: "password", ServerAddress: "https://index.docker.io/v1/"}, |
| 139 | }, |
| 140 | { |
| 141 | prefix: "docker.io", |
| 142 | expectedAddress: "https://index.docker.io/v1/", |
| 143 | expectedAuthCfg: registry.AuthConfig{Username: "username", Password: "password", ServerAddress: "https://index.docker.io/v1/"}, |
| 144 | }, |
| 145 | { |
| 146 | prefix: "index.docker.io", |
| 147 | expectedAddress: "https://index.docker.io/v1/", |
| 148 | expectedAuthCfg: registry.AuthConfig{Username: "username", Password: "password", ServerAddress: "https://index.docker.io/v1/"}, |
| 149 | }, |
| 150 | { |
| 151 | // FIXME(thaJeztah): registry-1.docker.io (the actual registry) is the odd one out, and is stored separate from other URLs used for docker hub's registry |
| 152 | prefix: "registry-1.docker.io", |
| 153 | expectedAuthCfg: registry.AuthConfig{Username: "username", Password: "password", ServerAddress: "registry-1.docker.io"}, |
| 154 | }, |
| 155 | { |
| 156 | // FIXME(thaJeztah): registry.hub.docker.com is stored separate from other URLs used for docker hub's registry |
nothing calls this directly
no test coverage detected
searching dependent graphs…