1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
package test_bindings
import (
"context"
"net/http"
"strings"
"time"
"github.com/containers/podman/v2/pkg/bindings"
"github.com/containers/podman/v2/pkg/bindings/secrets"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gexec"
)
var _ = Describe("Podman secrets", func() {
var (
bt *bindingTest
s *gexec.Session
connText context.Context
err error
)
BeforeEach(func() {
bt = newBindingTest()
bt.RestoreImagesFromCache()
s = bt.startAPIService()
time.Sleep(1 * time.Second)
connText, err = bindings.NewConnection(context.Background(), bt.sock)
Expect(err).To(BeNil())
})
AfterEach(func() {
s.Kill()
bt.cleanup()
})
It("create secret", func() {
r := strings.NewReader("mysecret")
name := "mysecret"
opts := &secrets.CreateOptions{
Name: &name,
}
_, err := secrets.Create(connText, r, opts)
Expect(err).To(BeNil())
// should not be allowed to create duplicate secret name
_, err = secrets.Create(connText, r, opts)
Expect(err).To(Not(BeNil()))
})
It("inspect secret", func() {
r := strings.NewReader("mysecret")
name := "mysecret"
opts := &secrets.CreateOptions{
Name: &name,
}
_, err := secrets.Create(connText, r, opts)
Expect(err).To(BeNil())
data, err := secrets.Inspect(connText, name, nil)
Expect(err).To(BeNil())
Expect(data.Spec.Name).To(Equal(name))
// inspecting non-existent secret should fail
data, err = secrets.Inspect(connText, "notasecret", nil)
code, _ := bindings.CheckResponseCode(err)
Expect(code).To(BeNumerically("==", http.StatusNotFound))
})
It("list secret", func() {
r := strings.NewReader("mysecret")
name := "mysecret"
opts := &secrets.CreateOptions{
Name: &name,
}
_, err := secrets.Create(connText, r, opts)
Expect(err).To(BeNil())
data, err := secrets.List(connText, nil)
Expect(err).To(BeNil())
Expect(data[0].Spec.Name).To(Equal(name))
})
It("list multiple secret", func() {
r := strings.NewReader("mysecret")
name := "mysecret"
opts := &secrets.CreateOptions{
Name: &name,
}
_, err := secrets.Create(connText, r, opts)
Expect(err).To(BeNil())
r2 := strings.NewReader("mysecret2")
name2 := "mysecret2"
opts2 := &secrets.CreateOptions{
Name: &name2,
}
_, err = secrets.Create(connText, r2, opts2)
Expect(err).To(BeNil())
data, err := secrets.List(connText, nil)
Expect(err).To(BeNil())
Expect(len(data)).To(Equal(2))
})
It("list no secrets", func() {
data, err := secrets.List(connText, nil)
Expect(err).To(BeNil())
Expect(len(data)).To(Equal(0))
})
It("remove secret", func() {
r := strings.NewReader("mysecret")
name := "mysecret"
opts := &secrets.CreateOptions{
Name: &name,
}
_, err := secrets.Create(connText, r, opts)
Expect(err).To(BeNil())
err = secrets.Remove(connText, name)
Expect(err).To(BeNil())
// removing non-existent secret should fail
err = secrets.Remove(connText, "nosecret")
Expect(err).To(Not(BeNil()))
code, _ := bindings.CheckResponseCode(err)
Expect(code).To(BeNumerically("==", http.StatusNotFound))
})
})
|