@@ -111,12 +111,9 @@ func TestOldInvalidsAuth(t *testing.T) {
111111 invalids := map [string ]string {
112112 `username = test` : "The Auth config file is empty" ,
113113 `username
114- password
115- email` : "Invalid Auth config file" ,
114+ password` : "Invalid Auth config file" ,
116115 `username = test
117116email` : "Invalid auth configuration file" ,
118- `username = am9lam9lOmhlbGxv
119- email` : "Invalid Auth config file" ,
120117 }
121118
122119 tmpHome , err := ioutil .TempDir ("" , "config-test" )
@@ -164,7 +161,7 @@ func TestOldValidAuth(t *testing.T) {
164161
165162 fn := filepath .Join (tmpHome , oldConfigfile )
166163 js := `username = am9lam9lOmhlbGxv
167- email = user@example.com`
164+ email = user@example.com`
168165 if err := ioutil .WriteFile (fn , []byte (js ), 0600 ); err != nil {
169166 t .Fatal (err )
170167 }
@@ -176,15 +173,23 @@ email = user@example.com`
176173
177174 // defaultIndexserver is https://index.docker.io/v1/
178175 ac := config .AuthConfigs ["https://index.docker.io/v1/" ]
179- if ac .Email != "user@example.com" || ac . Username != "joejoe" || ac .Password != "hello" {
176+ if ac .Username != "joejoe" || ac .Password != "hello" {
180177 t .Fatalf ("Missing data from parsing:\n %q" , config )
181178 }
182179
183180 // Now save it and make sure it shows up in new form
184181 configStr := saveConfigAndValidateNewFormat (t , config , tmpHome )
185182
186- if ! strings .Contains (configStr , "user@example.com" ) {
187- t .Fatalf ("Should have save in new form: %s" , configStr )
183+ expConfStr := `{
184+ "auths": {
185+ "https://index.docker.io/v1/": {
186+ "auth": "am9lam9lOmhlbGxv"
187+ }
188+ }
189+ }`
190+
191+ if configStr != expConfStr {
192+ t .Fatalf ("Should have save in new form: \n %s\n not \n %s" , configStr , expConfStr )
188193 }
189194}
190195
@@ -239,15 +244,24 @@ func TestOldJson(t *testing.T) {
239244 }
240245
241246 ac := config .AuthConfigs ["https://index.docker.io/v1/" ]
242- if ac .Email != "user@example.com" || ac . Username != "joejoe" || ac .Password != "hello" {
247+ if ac .Username != "joejoe" || ac .Password != "hello" {
243248 t .Fatalf ("Missing data from parsing:\n %q" , config )
244249 }
245250
246251 // Now save it and make sure it shows up in new form
247252 configStr := saveConfigAndValidateNewFormat (t , config , tmpHome )
248253
249- if ! strings .Contains (configStr , "user@example.com" ) {
250- t .Fatalf ("Should have save in new form: %s" , configStr )
254+ expConfStr := `{
255+ "auths": {
256+ "https://index.docker.io/v1/": {
257+ "auth": "am9lam9lOmhlbGxv",
258+ "email": "user@example.com"
259+ }
260+ }
261+ }`
262+
263+ if configStr != expConfStr {
264+ t .Fatalf ("Should have save in new form: \n '%s'\n not \n '%s'\n " , configStr , expConfStr )
251265 }
252266}
253267
@@ -259,7 +273,7 @@ func TestNewJson(t *testing.T) {
259273 defer os .RemoveAll (tmpHome )
260274
261275 fn := filepath .Join (tmpHome , ConfigFileName )
262- js := ` { "auths": { "https://index.docker.io/v1/": { "auth": "am9lam9lOmhlbGxv", "email": "user@example.com" } } }`
276+ js := ` { "auths": { "https://index.docker.io/v1/": { "auth": "am9lam9lOmhlbGxv" } } }`
263277 if err := ioutil .WriteFile (fn , []byte (js ), 0600 ); err != nil {
264278 t .Fatal (err )
265279 }
@@ -270,15 +284,62 @@ func TestNewJson(t *testing.T) {
270284 }
271285
272286 ac := config .AuthConfigs ["https://index.docker.io/v1/" ]
273- if ac .Email != "user@example.com" || ac . Username != "joejoe" || ac .Password != "hello" {
287+ if ac .Username != "joejoe" || ac .Password != "hello" {
274288 t .Fatalf ("Missing data from parsing:\n %q" , config )
275289 }
276290
277291 // Now save it and make sure it shows up in new form
278292 configStr := saveConfigAndValidateNewFormat (t , config , tmpHome )
279293
280- if ! strings .Contains (configStr , "user@example.com" ) {
281- t .Fatalf ("Should have save in new form: %s" , configStr )
294+ expConfStr := `{
295+ "auths": {
296+ "https://index.docker.io/v1/": {
297+ "auth": "am9lam9lOmhlbGxv"
298+ }
299+ }
300+ }`
301+
302+ if configStr != expConfStr {
303+ t .Fatalf ("Should have save in new form: \n %s\n not \n %s" , configStr , expConfStr )
304+ }
305+ }
306+
307+ func TestNewJsonNoEmail (t * testing.T ) {
308+ tmpHome , err := ioutil .TempDir ("" , "config-test" )
309+ if err != nil {
310+ t .Fatal (err )
311+ }
312+ defer os .RemoveAll (tmpHome )
313+
314+ fn := filepath .Join (tmpHome , ConfigFileName )
315+ js := ` { "auths": { "https://index.docker.io/v1/": { "auth": "am9lam9lOmhlbGxv" } } }`
316+ if err := ioutil .WriteFile (fn , []byte (js ), 0600 ); err != nil {
317+ t .Fatal (err )
318+ }
319+
320+ config , err := Load (tmpHome )
321+ if err != nil {
322+ t .Fatalf ("Failed loading on empty json file: %q" , err )
323+ }
324+
325+ ac := config .AuthConfigs ["https://index.docker.io/v1/" ]
326+ if ac .Username != "joejoe" || ac .Password != "hello" {
327+ t .Fatalf ("Missing data from parsing:\n %q" , config )
328+ }
329+
330+ // Now save it and make sure it shows up in new form
331+ configStr := saveConfigAndValidateNewFormat (t , config , tmpHome )
332+
333+ expConfStr := `{
334+ "auths": {
335+ "https://index.docker.io/v1/": {
336+ "auth": "am9lam9lOmhlbGxv"
337+ }
338+ }
339+ }`
340+
341+ if configStr != expConfStr {
342+ t .Fatalf ("Should have save in new form: \n %s\n not \n %s" , configStr , expConfStr )
282343 }
283344}
284345
@@ -366,7 +427,7 @@ func TestJsonReaderNoFile(t *testing.T) {
366427 }
367428
368429 ac := config .AuthConfigs ["https://index.docker.io/v1/" ]
369- if ac .Email != "user@example.com" || ac . Username != "joejoe" || ac .Password != "hello" {
430+ if ac .Username != "joejoe" || ac .Password != "hello" {
370431 t .Fatalf ("Missing data from parsing:\n %q" , config )
371432 }
372433
@@ -381,7 +442,7 @@ func TestOldJsonReaderNoFile(t *testing.T) {
381442 }
382443
383444 ac := config .AuthConfigs ["https://index.docker.io/v1/" ]
384- if ac .Email != "user@example.com" || ac . Username != "joejoe" || ac .Password != "hello" {
445+ if ac .Username != "joejoe" || ac .Password != "hello" {
385446 t .Fatalf ("Missing data from parsing:\n %q" , config )
386447 }
387448}
@@ -404,7 +465,7 @@ func TestJsonWithPsFormatNoFile(t *testing.T) {
404465
405466func TestJsonSaveWithNoFile (t * testing.T ) {
406467 js := `{
407- "auths": { "https://index.docker.io/v1/": { "auth": "am9lam9lOmhlbGxv", "email": "user@example.com" } },
468+ "auths": { "https://index.docker.io/v1/": { "auth": "am9lam9lOmhlbGxv" } },
408469 "psFormat": "table {{.ID}}\\t{{.Label \"com.docker.label.cpu\"}}"
409470}`
410471 config , err := LoadFromReader (strings .NewReader (js ))
@@ -426,9 +487,16 @@ func TestJsonSaveWithNoFile(t *testing.T) {
426487 t .Fatalf ("Failed saving to file: %q" , err )
427488 }
428489 buf , err := ioutil .ReadFile (filepath .Join (tmpHome , ConfigFileName ))
429- if ! strings .Contains (string (buf ), `"auths":` ) ||
430- ! strings .Contains (string (buf ), "user@example.com" ) {
431- t .Fatalf ("Should have save in new form: %s" , string (buf ))
490+ expConfStr := `{
491+ "auths": {
492+ "https://index.docker.io/v1/": {
493+ "auth": "am9lam9lOmhlbGxv"
494+ }
495+ },
496+ "psFormat": "table {{.ID}}\\t{{.Label \"com.docker.label.cpu\"}}"
497+ }`
498+ if string (buf ) != expConfStr {
499+ t .Fatalf ("Should have save in new form: \n %s\n not \n %s" , string (buf ), expConfStr )
432500 }
433501}
434502
@@ -454,14 +522,23 @@ func TestLegacyJsonSaveWithNoFile(t *testing.T) {
454522 t .Fatalf ("Failed saving to file: %q" , err )
455523 }
456524 buf , err := ioutil .ReadFile (filepath .Join (tmpHome , ConfigFileName ))
457- if ! strings .Contains (string (buf ), `"auths":` ) ||
458- ! strings .Contains (string (buf ), "user@example.com" ) {
459- t .Fatalf ("Should have save in new form: %s" , string (buf ))
525+
526+ expConfStr := `{
527+ "auths": {
528+ "https://index.docker.io/v1/": {
529+ "auth": "am9lam9lOmhlbGxv",
530+ "email": "user@example.com"
531+ }
532+ }
533+ }`
534+
535+ if string (buf ) != expConfStr {
536+ t .Fatalf ("Should have save in new form: \n %s\n not \n %s" , string (buf ), expConfStr )
460537 }
461538}
462539
463540func TestEncodeAuth (t * testing.T ) {
464- newAuthConfig := & types.AuthConfig {Username : "ken" , Password : "test" , Email : "test@example.com" }
541+ newAuthConfig := & types.AuthConfig {Username : "ken" , Password : "test" }
465542 authStr := encodeAuth (newAuthConfig )
466543 decAuthConfig := & types.AuthConfig {}
467544 var err error
0 commit comments