/
service_instance_sharing.go
226 lines (184 loc) · 8.36 KB
/
service_instance_sharing.go
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
package services_test
import (
"encoding/json"
"github.com/cloudfoundry-incubator/cf-test-helpers/cf"
"github.com/cloudfoundry-incubator/cf-test-helpers/helpers"
"github.com/cloudfoundry-incubator/cf-test-helpers/workflowhelpers"
. "github.com/cloudfoundry/cf-acceptance-tests/cats_suite_helpers"
"github.com/cloudfoundry/cf-acceptance-tests/helpers/app_helpers"
"github.com/cloudfoundry/cf-acceptance-tests/helpers/assets"
"github.com/cloudfoundry/cf-acceptance-tests/helpers/random_name"
"github.com/cloudfoundry/cf-acceptance-tests/helpers/services"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gbytes"
. "github.com/onsi/gomega/gexec"
)
var _ = ServiceInstanceSharingDescribe("Service Instance Sharing", func() {
Context("when User A shares a service instance into User B's space", func() {
// Note: user A is admin and user B is regular user
var (
broker services.ServiceBroker
serviceInstanceName string
appName string
userASpaceName string
)
BeforeEach(func() {
broker = services.NewServiceBroker(
random_name.CATSRandomName("BRKR"),
assets.NewAssets().ServiceBroker,
TestSetup,
)
broker.Push(Config)
broker.Configure()
broker.Create()
broker.PublicizePlans()
workflowhelpers.AsUser(TestSetup.AdminUserContext(), Config.DefaultTimeoutDuration(), func() {
orgName := TestSetup.RegularUserContext().Org
target := cf.Cf("target", "-o", orgName).Wait()
Expect(target).To(Exit(0), "failed targeting")
By("Creating a space that only User A can view")
userASpaceName = random_name.CATSRandomName("SPACE")
createSpace := cf.Cf("create-space", userASpaceName, "-o", orgName).Wait()
Expect(createSpace).To(Exit(0), "failed to create space")
target = cf.Cf("target", "-s", userASpaceName).Wait()
Expect(target).To(Exit(0), "failed targeting")
serviceInstanceName = random_name.CATSRandomName("SVIN")
By("Creating a service instance in User A's space")
createService := cf.Cf("create-service", broker.Service.Name, broker.SyncPlans[0].Name, serviceInstanceName).Wait()
Expect(createService).To(Exit(0))
By("Sharing the service instance into User B's space")
userBSpaceName := TestSetup.RegularUserContext().TestSpace.SpaceName()
shareSpace := cf.Cf("share-service", serviceInstanceName, "-s", userBSpaceName).Wait()
Expect(shareSpace).To(Exit(0), "failed to share")
Expect(shareSpace).To(Say("OK"))
})
})
AfterEach(func() {
broker.Destroy()
if appName != "" {
app_helpers.AppReport(appName)
Eventually(cf.Cf("delete", appName, "-f")).Should(Exit(0))
}
if serviceInstanceName != "" {
Expect(cf.Cf("delete-service", serviceInstanceName, "-f").Wait()).To(Exit(0))
}
})
It("allows User B to view the shared service", func() {
workflowhelpers.AsUser(TestSetup.RegularUserContext(), Config.DefaultTimeoutDuration(), func() {
By("Asserting the User B sees the service instance listed in `cf services`")
servicesCmd := cf.Cf("services").Wait()
Expect(servicesCmd).To(Exit(0))
Expect(servicesCmd).To(Say(serviceInstanceName))
By("Asserting the User B sees the service instance in `cf service service-name` output")
serviceCmd := cf.Cf("service", serviceInstanceName).Wait()
Expect(serviceCmd).To(Exit(0))
Expect(serviceCmd).To(Say(serviceInstanceName))
Expect(serviceCmd).To(Say(broker.Service.Name))
Expect(serviceCmd).To(Say("create succeeded"))
})
})
It("allows User A to view share information about the service instance", func() {
By("Asserting User B can bind to the shared service")
workflowhelpers.AsUser(TestSetup.RegularUserContext(), Config.DefaultTimeoutDuration(), func() {
appName = random_name.CATSRandomName("APP")
Expect(cf.Cf("push",
appName,
"-b", Config.GetBinaryBuildpackName(),
"-m", DEFAULT_MEMORY_LIMIT,
"-p", assets.NewAssets().Catnip,
"-c", "./catnip",
"-d", Config.GetAppsDomain()).Wait(Config.CfPushTimeoutDuration())).To(Exit(0))
bindCmd := cf.Cf("bind-service", appName, serviceInstanceName).Wait()
Expect(bindCmd).To(Exit(0))
Expect(bindCmd).To(Say("OK"))
})
workflowhelpers.AsUser(TestSetup.AdminUserContext(), Config.DefaultTimeoutDuration(), func() {
By("Asserting the User A sees the share information for the shared service")
orgName := TestSetup.RegularUserContext().Org
target := cf.Cf("target", "-o", orgName, "-s", userASpaceName).Wait()
Expect(target).To(Exit(0))
sharedToCmd := cf.Cf("service", serviceInstanceName).Wait()
Expect(sharedToCmd).To(Exit(0))
Expect(sharedToCmd).To(Say("shared with spaces"))
})
})
It("allows User B to bind an app to the shared service instance", func() {
workflowhelpers.AsUser(TestSetup.RegularUserContext(), Config.DefaultTimeoutDuration(), func() {
By("Asserting the User B can bind to the shared service")
appName = random_name.CATSRandomName("APP")
Expect(cf.Cf("push",
appName,
"-b", Config.GetBinaryBuildpackName(),
"-m", DEFAULT_MEMORY_LIMIT,
"-p", assets.NewAssets().Catnip,
"-c", "./catnip",
"-d", Config.GetAppsDomain()).Wait(Config.CfPushTimeoutDuration())).To(Exit(0))
bindCmd := cf.Cf("bind-service", appName, serviceInstanceName).Wait()
Expect(bindCmd).To(Exit(0))
Expect(bindCmd).To(Say("OK"))
Expect(cf.Cf("restage", appName).Wait(Config.CfPushTimeoutDuration())).To(Exit(0))
envJSON := helpers.CurlApp(Config, appName, "/env.json")
var envVars map[string]string
json.Unmarshal([]byte(envJSON), &envVars)
Expect(envVars["VCAP_SERVICES"]).To(ContainSubstring("credentials"))
})
})
It("allows User B to unbind an app from the shared service instance", func() {
workflowhelpers.AsUser(TestSetup.RegularUserContext(), Config.DefaultTimeoutDuration(), func() {
By("Asserting User B can bind to the shared service")
appName = random_name.CATSRandomName("APP")
Expect(cf.Cf("push",
appName,
"-b", Config.GetBinaryBuildpackName(),
"-m", DEFAULT_MEMORY_LIMIT,
"-p", assets.NewAssets().Catnip,
"-c", "./catnip",
"-d", Config.GetAppsDomain()).Wait(Config.CfPushTimeoutDuration())).To(Exit(0))
bindCmd := cf.Cf("bind-service", appName, serviceInstanceName).Wait()
Expect(bindCmd).To(Exit(0))
Expect(bindCmd).To(Say("OK"))
Expect(cf.Cf("restage", appName).Wait(Config.CfPushTimeoutDuration())).To(Exit(0))
})
workflowhelpers.AsUser(TestSetup.RegularUserContext(), Config.DefaultTimeoutDuration(), func() {
By("Asserting User B can unbind from the shared service")
unbindCmd := cf.Cf("unbind-service", appName, serviceInstanceName).Wait()
Expect(unbindCmd).To(Exit(0))
Expect(unbindCmd).To(Say("OK"))
})
})
It("allows User A to unshare the service regardless of bindings in target space", func() {
By("Asserting User B can bind to the shared service")
workflowhelpers.AsUser(TestSetup.RegularUserContext(), Config.DefaultTimeoutDuration(), func() {
appName = random_name.CATSRandomName("APP")
Expect(cf.Cf("push",
appName,
"-b", Config.GetBinaryBuildpackName(),
"-m", DEFAULT_MEMORY_LIMIT,
"-p", assets.NewAssets().Catnip,
"-c", "./catnip",
"-d", Config.GetAppsDomain()).Wait(Config.CfPushTimeoutDuration())).To(Exit(0))
bindCmd := cf.Cf("bind-service", appName, serviceInstanceName).Wait()
Expect(bindCmd).To(Exit(0))
Expect(bindCmd).To(Say("OK"))
Expect(cf.Cf("restage", appName).Wait(Config.CfPushTimeoutDuration())).To(Exit(0))
})
By("Unsharing the service as User A")
workflowhelpers.AsUser(TestSetup.AdminUserContext(), Config.DefaultTimeoutDuration(), func() {
orgName := TestSetup.RegularUserContext().Org
target := cf.Cf("target", "-o", orgName, "-s", userASpaceName).Wait()
Expect(target).To(Exit(0))
userBSpaceName := TestSetup.RegularUserContext().TestSpace.SpaceName()
unshareSpace := cf.Cf("unshare-service", serviceInstanceName, "-s", userBSpaceName, "-f").Wait()
Expect(unshareSpace).To(Exit(0))
Expect(unshareSpace).ToNot(Say("errors"))
})
By("Asserting the User B can no longer see the service after it has been unshared")
workflowhelpers.AsUser(TestSetup.RegularUserContext(), Config.DefaultTimeoutDuration(), func() {
spaceCmd := cf.Cf("services").Wait()
Expect(spaceCmd).To(Exit(0))
Expect(spaceCmd).ToNot(Say(serviceInstanceName))
})
})
})
})