@@ -17,49 +17,51 @@ package scenario
17
17
18
18
import (
19
19
"fmt"
20
+ "path/filepath"
20
21
"strings"
21
22
"time"
22
23
23
24
. "github.com/onsi/ginkgo/v2"
25
+ "oras.land/oras-go/v2"
26
+ "oras.land/oras/test/e2e/internal/testdata/foobar"
24
27
. "oras.land/oras/test/e2e/internal/utils"
25
28
)
26
29
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
+ )
32
33
34
+ var _ = Describe ("Common registry user" , func () {
35
+ When ("not logged in" , func () {
33
36
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 )
50
51
})
51
52
})
52
53
53
54
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 )).
56
58
WithTimeOut (20 * time .Second ).
57
59
MatchContent ("Login Succeeded\n " ).
58
60
MatchErrKeyWords ("WARNING" , "Using --password via the CLI is insecure" , "Use --password-stdin" ).Exec ()
59
61
})
60
62
61
63
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 ) ).
63
65
WithTimeOut (20 * time .Second ).
64
66
WithInput (strings .NewReader ("" )).
65
67
MatchKeyWords ("username:" ).
@@ -68,47 +70,55 @@ var _ = Describe("Common registry user", Ordered, func() {
68
70
})
69
71
70
72
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 ) ).
72
74
WithTimeOut (20 * time .Second ).
73
75
MatchKeyWords ("Username: " , "Password: " ).
74
76
WithInput (strings .NewReader (fmt .Sprintf ("%s\n " , Username ))).ExpectFailure ().Exec ()
75
77
})
76
78
77
79
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 ) ).
79
81
WithTimeOut (20 * time .Second ).
80
82
MatchKeyWords ("Username: " , "Password: " ).
81
83
MatchErrKeyWords ("Error: password required" ).
82
84
WithInput (strings .NewReader (fmt .Sprintf ("%s\n \n " , Username ))).ExpectFailure ().Exec ()
83
85
})
84
86
85
87
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 ) ).
87
89
WithTimeOut (20 * time .Second ).
88
90
MatchKeyWords ("Username: " , "Token: " ).
89
91
WithInput (strings .NewReader ("\n " )).ExpectFailure ().Exec ()
90
92
})
91
93
92
94
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 ) ).
94
96
WithTimeOut (20 * time .Second ).
95
97
MatchKeyWords ("Username: " , "Token: " ).
96
98
MatchErrKeyWords ("Error: token required" ).
97
99
WithInput (strings .NewReader ("\n \n " )).ExpectFailure ().Exec ()
98
100
})
99
101
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 ) ).
102
104
WithTimeOut (20 * time .Second ).
103
105
WithInput (strings .NewReader (fmt .Sprintf ("%s\n %s\n " , Username , Password ))).
104
106
MatchKeyWords ("Username: " , "Password: " , "Login Succeeded\n " ).Exec ()
105
107
})
106
108
})
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
+ })
107
118
})
108
119
109
120
func RunWithoutLogin (args ... string ) {
110
- ORAS (append (args , "--registry-config" , AuthConfigPath )... ).
111
- ExpectFailure ().
121
+ ORAS (args ... ).ExpectFailure ().
112
122
MatchErrKeyWords ("Error:" , "credential required" ).
113
123
WithDescription ("fail without logging in" ).Exec ()
114
124
}
0 commit comments