Skip to content

Commit 773c8f2

Browse files
committed
test(e2e): copying with legacy config file
Signed-off-by: Billy Zha <[email protected]>
1 parent 39eb369 commit 773c8f2

File tree

3 files changed

+47
-37
lines changed

3 files changed

+47
-37
lines changed

test/e2e/internal/utils/exec.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,9 @@ const (
3434
orasBinary = "oras"
3535

3636
// customize your own basic auth file via `htpasswd -cBb <file_name> <user_name> <password>`
37-
Username = "hello"
38-
Password = "oras-test"
39-
AuthConfigPath = "test.config"
40-
DefaultTimeout = 10 * time.Second
37+
Username = "hello"
38+
Password = "oras-test"
39+
DefaultTimeout = 10 * time.Second
4140
// If the command hasn't exited yet, ginkgo session ExitCode is -1
4241
notResponding = -1
4342
)

test/e2e/suite/auth/auth.go

+42-32
Original file line numberDiff line numberDiff line change
@@ -17,49 +17,51 @@ package scenario
1717

1818
import (
1919
"fmt"
20+
"path/filepath"
2021
"strings"
2122
"time"
2223

2324
. "github.com/onsi/ginkgo/v2"
25+
"oras.land/oras-go/v2"
26+
"oras.land/oras/test/e2e/internal/testdata/foobar"
2427
. "oras.land/oras/test/e2e/internal/utils"
2528
)
2629

27-
var _ = Describe("Common registry user", Ordered, func() {
28-
When("logging out", Ordered, func() {
29-
It("should use logout command to logout", func() {
30-
ORAS("logout", ZOTHost, "--registry-config", AuthConfigPath).Exec()
31-
})
30+
var (
31+
LegacyConfigPath = "legacy.config"
32+
)
3233

34+
var _ = Describe("Common registry user", func() {
35+
When("not logged in", func() {
3336
It("should run commands without logging in", func() {
34-
RunWithoutLogin("attach", ZOTHost+"/repo:tag", "-a", "test=true", "--artifact-type", "doc/example")
35-
ORAS("copy", ZOTHost+"/repo:from", ZOTHost+"/repo:to", "--from-registry-config", AuthConfigPath, "--to-registry-config", AuthConfigPath).
36-
ExpectFailure().
37-
MatchErrKeyWords("Error:", "credential required").
38-
WithDescription("fail without logging in").Exec()
39-
RunWithoutLogin("discover", ZOTHost+"/repo:tag")
40-
RunWithoutLogin("push", "-a", "key=value", ZOTHost+"/repo:tag")
41-
RunWithoutLogin("pull", ZOTHost+"/repo:tag")
42-
RunWithoutLogin("manifest", "fetch", ZOTHost+"/repo:tag")
43-
RunWithoutLogin("blob", "delete", ZOTHost+"/repo@sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
44-
RunWithoutLogin("blob", "push", ZOTHost+"/repo", WriteTempFile("blob", "test"))
45-
RunWithoutLogin("tag", ZOTHost+"/repo:tag", "tag1")
46-
RunWithoutLogin("resolve", ZOTHost+"/repo:tag")
47-
RunWithoutLogin("repo", "ls", ZOTHost)
48-
RunWithoutLogin("repo", "tags", RegistryRef(ZOTHost, "repo", ""))
49-
RunWithoutLogin("manifest", "fetch-config", ZOTHost+"/repo:tag")
37+
authConfigPath := filepath.Join(GinkgoT().TempDir(), "auth.config")
38+
RunWithoutLogin("attach", ZOTHost+"/repo:tag", "-a", "test=true", "--artifact-type", "doc/example", "--registry-config", authConfigPath)
39+
RunWithoutLogin("copy", ZOTHost+"/repo:from", ZOTHost+"/repo:to", "--from-registry-config", authConfigPath, "--to-registry-config", authConfigPath)
40+
RunWithoutLogin("discover", ZOTHost+"/repo:tag", "--registry-config", authConfigPath)
41+
RunWithoutLogin("push", "-a", "key=value", ZOTHost+"/repo:tag", "--registry-config", authConfigPath)
42+
RunWithoutLogin("pull", ZOTHost+"/repo:tag", "--registry-config", authConfigPath)
43+
RunWithoutLogin("manifest", "fetch", ZOTHost+"/repo:tag", "--registry-config", authConfigPath)
44+
RunWithoutLogin("blob", "delete", ZOTHost+"/repo@sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "--registry-config", authConfigPath)
45+
RunWithoutLogin("blob", "push", ZOTHost+"/repo", WriteTempFile("blob", "test"), "--registry-config", authConfigPath)
46+
RunWithoutLogin("tag", ZOTHost+"/repo:tag", "tag1", "--registry-config", authConfigPath)
47+
RunWithoutLogin("resolve", ZOTHost+"/repo:tag", "--registry-config", authConfigPath)
48+
RunWithoutLogin("repo", "ls", ZOTHost, "--registry-config", authConfigPath)
49+
RunWithoutLogin("repo", "tags", RegistryRef(ZOTHost, "repo", ""), "--registry-config", authConfigPath)
50+
RunWithoutLogin("manifest", "fetch-config", ZOTHost+"/repo:tag", "--registry-config", authConfigPath)
5051
})
5152
})
5253

5354
When("logging in", func() {
54-
It("should use basic auth", func() {
55-
ORAS("login", ZOTHost, "-u", Username, "-p", Password, "--registry-config", AuthConfigPath).
55+
authConfigName := "auth.config"
56+
It("should succeed to use basic auth", func() {
57+
ORAS("login", ZOTHost, "-u", Username, "-p", Password, "--registry-config", filepath.Join(GinkgoT().TempDir(), authConfigName)).
5658
WithTimeOut(20*time.Second).
5759
MatchContent("Login Succeeded\n").
5860
MatchErrKeyWords("WARNING", "Using --password via the CLI is insecure", "Use --password-stdin").Exec()
5961
})
6062

6163
It("should fail if no username input", func() {
62-
ORAS("login", ZOTHost, "--registry-config", AuthConfigPath).
64+
ORAS("login", ZOTHost, "--registry-config", filepath.Join(GinkgoT().TempDir(), authConfigName)).
6365
WithTimeOut(20 * time.Second).
6466
WithInput(strings.NewReader("")).
6567
MatchKeyWords("username:").
@@ -68,47 +70,55 @@ var _ = Describe("Common registry user", Ordered, func() {
6870
})
6971

7072
It("should fail if no password input", func() {
71-
ORAS("login", ZOTHost, "--registry-config", AuthConfigPath).
73+
ORAS("login", ZOTHost, "--registry-config", filepath.Join(GinkgoT().TempDir(), authConfigName)).
7274
WithTimeOut(20*time.Second).
7375
MatchKeyWords("Username: ", "Password: ").
7476
WithInput(strings.NewReader(fmt.Sprintf("%s\n", Username))).ExpectFailure().Exec()
7577
})
7678

7779
It("should fail if password is empty", func() {
78-
ORAS("login", ZOTHost, "--registry-config", AuthConfigPath).
80+
ORAS("login", ZOTHost, "--registry-config", filepath.Join(GinkgoT().TempDir(), authConfigName)).
7981
WithTimeOut(20*time.Second).
8082
MatchKeyWords("Username: ", "Password: ").
8183
MatchErrKeyWords("Error: password required").
8284
WithInput(strings.NewReader(fmt.Sprintf("%s\n\n", Username))).ExpectFailure().Exec()
8385
})
8486

8587
It("should fail if no token input", func() {
86-
ORAS("login", ZOTHost, "--registry-config", AuthConfigPath).
88+
ORAS("login", ZOTHost, "--registry-config", filepath.Join(GinkgoT().TempDir(), authConfigName)).
8789
WithTimeOut(20*time.Second).
8890
MatchKeyWords("Username: ", "Token: ").
8991
WithInput(strings.NewReader("\n")).ExpectFailure().Exec()
9092
})
9193

9294
It("should fail if token is empty", func() {
93-
ORAS("login", ZOTHost, "--registry-config", AuthConfigPath).
95+
ORAS("login", ZOTHost, "--registry-config", filepath.Join(GinkgoT().TempDir(), authConfigName)).
9496
WithTimeOut(20*time.Second).
9597
MatchKeyWords("Username: ", "Token: ").
9698
MatchErrKeyWords("Error: token required").
9799
WithInput(strings.NewReader("\n\n")).ExpectFailure().Exec()
98100
})
99101

100-
It("should use prompted input", func() {
101-
ORAS("login", ZOTHost, "--registry-config", AuthConfigPath).
102+
It("should succeed to use prompted input", func() {
103+
ORAS("login", ZOTHost, "--registry-config", filepath.Join(GinkgoT().TempDir(), authConfigName)).
102104
WithTimeOut(20*time.Second).
103105
WithInput(strings.NewReader(fmt.Sprintf("%s\n%s\n", Username, Password))).
104106
MatchKeyWords("Username: ", "Password: ", "Login Succeeded\n").Exec()
105107
})
106108
})
109+
110+
When("using legacy config", func() {
111+
It("should succeed to copy", func() {
112+
src := RegistryRef(ZOTHost, ArtifactRepo, foobar.Tag)
113+
dst := RegistryRef(ZOTHost, fmt.Sprintf("command/auth/%d/copy", GinkgoRandomSeed()), foobar.Tag)
114+
foobarStates := append(foobar.ImageLayerStateKeys, foobar.ManifestStateKey, foobar.ImageConfigStateKey(oras.MediaTypeUnknownConfig))
115+
ORAS("cp", src, dst, "-v", "--from-registry-config", LegacyConfigPath, "--to-registry-config", LegacyConfigPath).MatchStatus(foobarStates, true, len(foobarStates)).Exec()
116+
})
117+
})
107118
})
108119

109120
func RunWithoutLogin(args ...string) {
110-
ORAS(append(args, "--registry-config", AuthConfigPath)...).
111-
ExpectFailure().
121+
ORAS(args...).ExpectFailure().
112122
MatchErrKeyWords("Error:", "credential required").
113123
WithDescription("fail without logging in").Exec()
114124
}

test/e2e/suite/command/custom_header.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package command
1717

1818
import (
1919
"fmt"
20+
"path/filepath"
2021

2122
. "github.com/onsi/ginkgo/v2"
2223
"oras.land/oras/test/e2e/internal/testdata/foobar"
@@ -80,7 +81,7 @@ var _ = Describe("1.1 registry users:", func() {
8081
MatchRequestHeaders(FoobarHeader, AbHeader).Exec()
8182
})
8283
It("login", func() {
83-
ORAS("login", Host, "-u", Username, "-p", Password, "--registry-config", AuthConfigPath,
84+
ORAS("login", Host, "-u", Username, "-p", Password, "--registry-config", filepath.Join(GinkgoT().TempDir(), "test.config"),
8485
"-H", FoobarHeaderInput, "-H", AbHeaderInput).
8586
MatchRequestHeaders(FoobarHeader, AbHeader).Exec()
8687
})

0 commit comments

Comments
 (0)