Skip to content

Commit 4244288

Browse files
Merge pull request #11054 from saschagrunert/login-logout-path-tests
Add `--accept-repositories` integration tests
2 parents 5733cd2 + 732ece6 commit 4244288

File tree

17 files changed

+462
-89
lines changed

17 files changed

+462
-89
lines changed

cmd/podman/login.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ func init() {
5252
loginOptions.Stdin = os.Stdin
5353
loginOptions.Stdout = os.Stdout
5454
loginOptions.AcceptUnspecifiedRegistry = true
55+
loginOptions.AcceptRepositories = true
5556
}
5657

5758
// Implementation of podman-login.

cmd/podman/logout.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ func init() {
4343

4444
logoutOptions.Stdout = os.Stdout
4545
logoutOptions.AcceptUnspecifiedRegistry = true
46+
logoutOptions.AcceptRepositories = true
4647
}
4748

4849
// Implementation of podman-logout.

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ require (
1212
github.com/containernetworking/cni v0.8.1
1313
github.com/containernetworking/plugins v0.9.1
1414
github.com/containers/buildah v1.21.1-0.20210721171232-54cafea4c933
15-
github.com/containers/common v0.41.1-0.20210721172332-291287e9d060
15+
github.com/containers/common v0.41.1-0.20210730122913-cd6c45fd20e3
1616
github.com/containers/conmon v2.0.20+incompatible
1717
github.com/containers/image/v5 v5.14.0
1818
github.com/containers/ocicrypt v1.1.2

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,8 @@ github.com/containernetworking/plugins v0.9.1/go.mod h1:xP/idU2ldlzN6m4p5LmGiwRD
242242
github.com/containers/buildah v1.21.1-0.20210721171232-54cafea4c933 h1:jqO3hDypBoKM5be+fVcqGHOpX2fOiQy2DFEeb/VKpsk=
243243
github.com/containers/buildah v1.21.1-0.20210721171232-54cafea4c933/go.mod h1:9gspFNeUJxIK72n1IMIKIHmtcePEZQsv0tjo+1LqkCo=
244244
github.com/containers/common v0.41.1-0.20210721112610-c95d2f794edf/go.mod h1:Ba5YVNCnyX6xDtg1JqEHa2EMVMW5UbHmIyEqsEwpeGE=
245-
github.com/containers/common v0.41.1-0.20210721172332-291287e9d060 h1:HgGff2MeEKfYoKp2WQFl9xdsgP7KV8rr/1JZRIuPXmg=
246-
github.com/containers/common v0.41.1-0.20210721172332-291287e9d060/go.mod h1:Ba5YVNCnyX6xDtg1JqEHa2EMVMW5UbHmIyEqsEwpeGE=
245+
github.com/containers/common v0.41.1-0.20210730122913-cd6c45fd20e3 h1:lHOZ+G5B7aP2YPsbDo4DtALFAuFG5PWH3Pv5zL2bC08=
246+
github.com/containers/common v0.41.1-0.20210730122913-cd6c45fd20e3/go.mod h1:UzAAjDsxwd4qkN1mgsk6aspduBY5bspxvKgwQElaBwk=
247247
github.com/containers/conmon v2.0.20+incompatible h1:YbCVSFSCqFjjVwHTPINGdMX1F6JXHGTUje2ZYobNrkg=
248248
github.com/containers/conmon v2.0.20+incompatible/go.mod h1:hgwZ2mtuDrppv78a/cOBNiCm6O0UMWGx1mu7P00nu5I=
249249
github.com/containers/image/v5 v5.13.2/go.mod h1:GkWursKDlDcUIT7L7vZf70tADvZCk/Ga0wgS0MuF0ag=

test/e2e/login_logout_test.go

Lines changed: 219 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,24 @@ var _ = Describe("Podman login and logout", func() {
9797
os.RemoveAll(certDirPath)
9898
})
9999

100+
readAuthInfo := func(filePath string) map[string]interface{} {
101+
authBytes, err := ioutil.ReadFile(filePath)
102+
Expect(err).To(BeNil())
103+
104+
var authInfo map[string]interface{}
105+
err = json.Unmarshal(authBytes, &authInfo)
106+
Expect(err).To(BeNil())
107+
fmt.Println(authInfo)
108+
109+
const authsKey = "auths"
110+
Expect(authInfo).To(HaveKey(authsKey))
111+
112+
auths, ok := authInfo[authsKey].(map[string]interface{})
113+
Expect(ok).To(BeTrue())
114+
115+
return auths
116+
}
117+
100118
It("podman login and logout", func() {
101119
session := podmanTest.Podman([]string{"login", "-u", "podmantest", "-p", "test", server})
102120
session.WaitWithDefaultTimeout()
@@ -151,10 +169,7 @@ var _ = Describe("Podman login and logout", func() {
151169
session.WaitWithDefaultTimeout()
152170
Expect(session).Should(Exit(0))
153171

154-
authInfo, _ := ioutil.ReadFile(authFile)
155-
var info map[string]interface{}
156-
json.Unmarshal(authInfo, &info)
157-
fmt.Println(info)
172+
readAuthInfo(authFile)
158173

159174
// push should fail with nonexistent authfile
160175
session = podmanTest.Podman([]string{"push", "--authfile", "/tmp/nonexistent", ALPINE, testImg})
@@ -284,4 +299,204 @@ var _ = Describe("Podman login and logout", func() {
284299
session.WaitWithDefaultTimeout()
285300
Expect(session).To(ExitWithError())
286301
})
302+
303+
It("podman login and logout with repository", func() {
304+
authFile := filepath.Join(podmanTest.TempDir, "auth.json")
305+
306+
testRepository := server + "/podmantest"
307+
session := podmanTest.Podman([]string{
308+
"login",
309+
"-u", "podmantest",
310+
"-p", "test",
311+
"--authfile", authFile,
312+
testRepository,
313+
})
314+
session.WaitWithDefaultTimeout()
315+
Expect(session).Should(Exit(0))
316+
317+
authInfo := readAuthInfo(authFile)
318+
Expect(authInfo).To(HaveKey(testRepository))
319+
320+
session = podmanTest.Podman([]string{
321+
"logout",
322+
"--authfile", authFile,
323+
testRepository,
324+
})
325+
session.WaitWithDefaultTimeout()
326+
Expect(session).Should(Exit(0))
327+
328+
authInfo = readAuthInfo(authFile)
329+
Expect(authInfo).NotTo(HaveKey(testRepository))
330+
})
331+
332+
It("podman login and logout with repository and specified image", func() {
333+
authFile := filepath.Join(podmanTest.TempDir, "auth.json")
334+
335+
testTarget := server + "/podmantest/test-alpine"
336+
session := podmanTest.Podman([]string{
337+
"login",
338+
"-u", "podmantest",
339+
"-p", "test",
340+
"--authfile", authFile,
341+
testTarget,
342+
})
343+
session.WaitWithDefaultTimeout()
344+
Expect(session).Should(Exit(0))
345+
346+
authInfo := readAuthInfo(authFile)
347+
Expect(authInfo).To(HaveKey(testTarget))
348+
349+
session = podmanTest.Podman([]string{
350+
"push",
351+
"--authfile", authFile,
352+
ALPINE, testTarget,
353+
})
354+
session.WaitWithDefaultTimeout()
355+
Expect(session).Should(Exit(0))
356+
357+
})
358+
359+
It("podman login and logout with repository with fallback", func() {
360+
authFile := filepath.Join(podmanTest.TempDir, "auth.json")
361+
362+
testRepos := []string{
363+
server + "/podmantest",
364+
server,
365+
}
366+
for _, testRepo := range testRepos {
367+
session := podmanTest.Podman([]string{
368+
"login",
369+
"-u", "podmantest",
370+
"-p", "test",
371+
"--authfile", authFile,
372+
testRepo,
373+
})
374+
session.WaitWithDefaultTimeout()
375+
Expect(session).Should(Exit(0))
376+
}
377+
378+
authInfo := readAuthInfo(authFile)
379+
Expect(authInfo).To(HaveKey(testRepos[0]))
380+
Expect(authInfo).To(HaveKey(testRepos[1]))
381+
382+
session := podmanTest.Podman([]string{
383+
"push",
384+
"--authfile", authFile,
385+
ALPINE, testRepos[0] + "/test-image-alpine",
386+
})
387+
session.WaitWithDefaultTimeout()
388+
Expect(session).Should(Exit(0))
389+
390+
session = podmanTest.Podman([]string{
391+
"logout",
392+
"--authfile", authFile,
393+
testRepos[0],
394+
})
395+
session.WaitWithDefaultTimeout()
396+
Expect(session).Should(Exit(0))
397+
398+
session = podmanTest.Podman([]string{
399+
"push",
400+
"--authfile", authFile,
401+
ALPINE, testRepos[0] + "/test-image-alpine",
402+
})
403+
session.WaitWithDefaultTimeout()
404+
Expect(session).Should(Exit(0))
405+
406+
session = podmanTest.Podman([]string{
407+
"logout",
408+
"--authfile", authFile,
409+
testRepos[1],
410+
})
411+
session.WaitWithDefaultTimeout()
412+
Expect(session).Should(Exit(0))
413+
414+
authInfo = readAuthInfo(authFile)
415+
Expect(authInfo).NotTo(HaveKey(testRepos[0]))
416+
Expect(authInfo).NotTo(HaveKey(testRepos[1]))
417+
})
418+
419+
It("podman login with repository invalid arguments", func() {
420+
authFile := filepath.Join(podmanTest.TempDir, "auth.json")
421+
422+
for _, invalidArg := range []string{
423+
"https://" + server + "/podmantest",
424+
server + "/podmantest/image:latest",
425+
} {
426+
session := podmanTest.Podman([]string{
427+
"login",
428+
"-u", "podmantest",
429+
"-p", "test",
430+
"--authfile", authFile,
431+
invalidArg,
432+
})
433+
session.WaitWithDefaultTimeout()
434+
Expect(session).Should(ExitWithError())
435+
}
436+
})
437+
438+
It("podman login and logout with repository push with invalid auth.json credentials", func() {
439+
authFile := filepath.Join(podmanTest.TempDir, "auth.json")
440+
// only `server` contains the correct login data
441+
err := ioutil.WriteFile(authFile, []byte(fmt.Sprintf(`{"auths": {
442+
"%s/podmantest": { "auth": "cG9kbWFudGVzdDp3cm9uZw==" },
443+
"%s": { "auth": "cG9kbWFudGVzdDp0ZXN0" }
444+
}}`, server, server)), 0644)
445+
Expect(err).To(BeNil())
446+
447+
session := podmanTest.Podman([]string{
448+
"push",
449+
"--authfile", authFile,
450+
ALPINE, server + "/podmantest/test-image",
451+
})
452+
session.WaitWithDefaultTimeout()
453+
Expect(session).To(ExitWithError())
454+
455+
session = podmanTest.Podman([]string{
456+
"push",
457+
"--authfile", authFile,
458+
ALPINE, server + "/test-image",
459+
})
460+
session.WaitWithDefaultTimeout()
461+
Expect(session).To(Exit(0))
462+
})
463+
464+
It("podman login and logout with repository pull with wrong auth.json credentials", func() {
465+
authFile := filepath.Join(podmanTest.TempDir, "auth.json")
466+
467+
testTarget := server + "/podmantest/test-alpine"
468+
session := podmanTest.Podman([]string{
469+
"login",
470+
"-u", "podmantest",
471+
"-p", "test",
472+
"--authfile", authFile,
473+
testTarget,
474+
})
475+
session.WaitWithDefaultTimeout()
476+
Expect(session).Should(Exit(0))
477+
478+
session = podmanTest.Podman([]string{
479+
"push",
480+
"--authfile", authFile,
481+
ALPINE, testTarget,
482+
})
483+
session.WaitWithDefaultTimeout()
484+
Expect(session).Should(Exit(0))
485+
486+
// only `server + /podmantest` and `server` have the correct login data
487+
err := ioutil.WriteFile(authFile, []byte(fmt.Sprintf(`{"auths": {
488+
"%s/podmantest/test-alpine": { "auth": "cG9kbWFudGVzdDp3cm9uZw==" },
489+
"%s/podmantest": { "auth": "cG9kbWFudGVzdDp0ZXN0" },
490+
"%s": { "auth": "cG9kbWFudGVzdDp0ZXN0" }
491+
}}`, server, server, server)), 0644)
492+
Expect(err).To(BeNil())
493+
494+
session = podmanTest.Podman([]string{
495+
"pull",
496+
"--authfile", authFile,
497+
server + "/podmantest/test-alpine",
498+
})
499+
session.WaitWithDefaultTimeout()
500+
Expect(session).To(ExitWithError())
501+
})
287502
})

vendor/github.com/containers/common/libimage/copier.go

Lines changed: 7 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/containers/common/libimage/image.go

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/containers/common/libimage/import.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/containers/common/libimage/manifests/manifests.go

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)