github.com/jghiloni/cli@v6.28.1-0.20170628223758-0ce05fe032a2+incompatible/integration/isolated/unbind_security_group_command_test.go (about) 1 package isolated 2 3 import ( 4 "net/http" 5 6 "code.cloudfoundry.org/cli/integration/helpers" 7 . "github.com/onsi/ginkgo" 8 . "github.com/onsi/gomega" 9 . "github.com/onsi/gomega/gbytes" 10 . "github.com/onsi/gomega/gexec" 11 . "github.com/onsi/gomega/ghttp" 12 ) 13 14 var _ = Describe("unbind-security-group command", func() { 15 var ( 16 orgName string 17 secGroupName string 18 someSecurityGroup helpers.SecurityGroup 19 spaceName string 20 ) 21 22 BeforeEach(func() { 23 orgName = helpers.NewOrgName() 24 secGroupName = helpers.NewSecGroupName() 25 spaceName = helpers.NewSpaceName() 26 27 helpers.LoginCF() 28 }) 29 30 Describe("help", func() { 31 Context("when --help flag is set", func() { 32 It("Displays command usage to output", func() { 33 session := helpers.CF("unbind-security-group", "--help") 34 Eventually(session.Out).Should(Say("NAME:")) 35 Eventually(session.Out).Should(Say("\\s+unbind-security-group - Unbind a security group from a space")) 36 Eventually(session.Out).Should(Say("USAGE:")) 37 Eventually(session.Out).Should(Say("\\s+cf unbind-security-group SECURITY_GROUP ORG SPACE \\[--lifecycle \\(running \\| staging\\)\\]")) 38 Eventually(session.Out).Should(Say("TIP: Changes require an app restart \\(for running\\) or restage \\(for staging\\) to apply to existing applications\\.")) 39 Eventually(session.Out).Should(Say("OPTIONS:")) 40 Eventually(session.Out).Should(Say("\\s+--lifecycle Lifecycle phase the group applies to \\(Default: running\\)")) 41 Eventually(session.Out).Should(Say("SEE ALSO:")) 42 Eventually(session.Out).Should(Say("\\s+apps, restart, security-groups")) 43 Eventually(session).Should(Exit(0)) 44 }) 45 }) 46 }) 47 48 Context("when the lifecycle flag is invalid", func() { 49 It("outputs a message and usage", func() { 50 session := helpers.CF("unbind-security-group", secGroupName, "some-org", "--lifecycle", "invalid") 51 Eventually(session.Err).Should(Say("Incorrect Usage: Invalid value `invalid' for option `--lifecycle'. Allowed values are: running or staging")) 52 Eventually(session.Out).Should(Say("USAGE:")) 53 Eventually(session).Should(Exit(1)) 54 }) 55 }) 56 57 Context("when the lifecycle flag has no argument", func() { 58 It("outputs a message and usage", func() { 59 session := helpers.CF("unbind-security-group", secGroupName, "some-org", "--lifecycle") 60 Eventually(session.Err).Should(Say("Incorrect Usage: expected argument for flag `--lifecycle'")) 61 Eventually(session.Out).Should(Say("USAGE:")) 62 Eventually(session).Should(Exit(1)) 63 }) 64 }) 65 66 Context("when the environment is not setup correctly", func() { 67 Context("when no API endpoint is set", func() { 68 BeforeEach(func() { 69 helpers.UnsetAPI() 70 }) 71 72 It("fails with no API endpoint set message", func() { 73 session := helpers.CF("unbind-security-group", secGroupName) 74 Eventually(session.Out).Should(Say("FAILED")) 75 Eventually(session.Err).Should(Say("No API endpoint set. Use 'cf login' or 'cf api' to target an endpoint.")) 76 Eventually(session).Should(Exit(1)) 77 }) 78 }) 79 80 Context("when not logged in", func() { 81 BeforeEach(func() { 82 helpers.LogoutCF() 83 }) 84 85 It("fails with not logged in message", func() { 86 session := helpers.CF("unbind-security-group", secGroupName) 87 Eventually(session.Out).Should(Say("FAILED")) 88 Eventually(session.Err).Should(Say("Not logged in. Use 'cf login' to log in.")) 89 Eventually(session).Should(Exit(1)) 90 }) 91 }) 92 93 Context("when no org is targeted and no org is specified on the command line", func() { 94 BeforeEach(func() { 95 helpers.ClearTarget() 96 }) 97 98 It("fails with no org targeted error", func() { 99 session := helpers.CF("unbind-security-group", secGroupName) 100 Eventually(session.Out).Should(Say("FAILED")) 101 Eventually(session.Err).Should(Say("No org targeted, use 'cf target -o ORG' to target an org.")) 102 Eventually(session).Should(Exit(1)) 103 }) 104 }) 105 106 Context("when no space is targeted and no space is specified on the command line", func() { 107 BeforeEach(func() { 108 helpers.ClearTarget() 109 helpers.CreateOrg(orgName) 110 helpers.TargetOrg(orgName) 111 }) 112 113 It("fails with no space targeted error", func() { 114 session := helpers.CF("unbind-security-group", secGroupName) 115 Eventually(session.Out).Should(Say("FAILED")) 116 Eventually(session.Err).Should(Say("No space targeted, use 'cf target -s SPACE' to target a space.")) 117 Eventually(session).Should(Exit(1)) 118 }) 119 }) 120 }) 121 122 Context("when the server's API version is too low", func() { 123 var server *Server 124 125 BeforeEach(func() { 126 server = NewTLSServer() 127 server.AppendHandlers( 128 CombineHandlers( 129 VerifyRequest(http.MethodGet, "/v2/info"), 130 RespondWith(http.StatusOK, `{"api_version":"2.34.0"}`), 131 ), 132 CombineHandlers( 133 VerifyRequest(http.MethodGet, "/v2/info"), 134 RespondWith(http.StatusOK, `{"api_version":"2.34.0"}`), 135 ), 136 ) 137 Eventually(helpers.CF("api", server.URL(), "--skip-ssl-validation")).Should(Exit(0)) 138 }) 139 140 AfterEach(func() { 141 server.Close() 142 }) 143 144 It("reports an error with a minimum-version message", func() { 145 session := helpers.CF("unbind-security-group", secGroupName, orgName, spaceName, "--lifecycle", "staging") 146 147 Eventually(session.Err).Should(Say("Lifecycle value 'staging' requires CF API version 2\\.68\\.0\\ or higher. Your target is 2\\.34\\.0\\.")) 148 Eventually(session).Should(Exit(1)) 149 }) 150 }) 151 152 Context("when the input is invalid", func() { 153 Context("when the security group is not provided", func() { 154 It("fails with an incorrect usage message and displays help", func() { 155 session := helpers.CF("unbind-security-group") 156 Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `SECURITY_GROUP` was not provided")) 157 Eventually(session.Out).Should(Say("USAGE:")) 158 Eventually(session).Should(Exit(1)) 159 }) 160 }) 161 162 Context("when the space is not provided", func() { 163 It("fails with an incorrect usage message and displays help", func() { 164 session := helpers.CF("unbind-security-group", secGroupName, "some-org") 165 Eventually(session.Err).Should(Say("Incorrect Usage: the required arguments `SECURITY_GROUP`, `ORG`, and `SPACE` were not provided")) 166 Eventually(session.Out).Should(Say("USAGE:")) 167 Eventually(session).Should(Exit(1)) 168 }) 169 }) 170 }) 171 172 Context("when the security group doesn't exist", func() { 173 BeforeEach(func() { 174 helpers.CreateOrgAndSpace(orgName, spaceName) 175 }) 176 177 It("fails with a 'security group not found' message", func() { 178 session := helpers.CF("unbind-security-group", "some-other-security-group", orgName, spaceName) 179 Eventually(session.Out).Should(Say("FAILED")) 180 Eventually(session.Err).Should(Say("Security group 'some-other-security-group' not found\\.")) 181 Eventually(session).Should(Exit(1)) 182 }) 183 }) 184 185 Context("when the security group exists", func() { 186 BeforeEach(func() { 187 someSecurityGroup = helpers.NewSecurityGroup(secGroupName, "tcp", "127.0.0.1", "8443", "some-description") 188 someSecurityGroup.Create() 189 }) 190 191 AfterEach(func() { 192 someSecurityGroup.Delete() 193 }) 194 195 Context("when the org doesn't exist", func() { 196 It("fails with an 'org not found' message", func() { 197 session := helpers.CF("unbind-security-group", secGroupName, "some-other-org", "some-other-space") 198 Eventually(session.Out).Should(Say("FAILED")) 199 Eventually(session.Err).Should(Say("Organization 'some-other-org' not found\\.")) 200 Eventually(session).Should(Exit(1)) 201 }) 202 }) 203 204 Context("when the org exists", func() { 205 var username string 206 207 BeforeEach(func() { 208 username, _ = helpers.GetCredentials() 209 210 helpers.CreateOrg(orgName) 211 helpers.TargetOrg(orgName) 212 }) 213 214 Context("when the space doesn't exist", func() { 215 It("fails with a 'space not found' message", func() { 216 session := helpers.CF("unbind-security-group", secGroupName, orgName, "some-other-space") 217 Eventually(session.Out).Should(Say("FAILED")) 218 Eventually(session.Err).Should(Say("Space 'some-other-space' not found\\.")) 219 Eventually(session).Should(Exit(1)) 220 }) 221 }) 222 223 Context("when the space exists", func() { 224 BeforeEach(func() { 225 helpers.CreateSpace(spaceName) 226 }) 227 228 Context("when the space isn't bound to the security group in any lifecycle", func() { 229 It("successfully runs the command", func() { 230 session := helpers.CF("unbind-security-group", secGroupName, orgName, spaceName) 231 Eventually(session.Out).Should(Say("Unbinding security group %s from org %s / space %s as %s\\.\\.\\.", secGroupName, orgName, spaceName, username)) 232 Eventually(session.Out).Should(Say("OK")) 233 Eventually(session.Out).Should(Say("TIP: Changes require an app restart \\(for running\\) or restage \\(for staging\\) to apply to existing applications\\.")) 234 Eventually(session).Should(Exit(0)) 235 }) 236 }) 237 238 Context("when a space is bound to a security group in the running lifecycle", func() { 239 BeforeEach(func() { 240 Eventually(helpers.CF("bind-security-group", secGroupName, orgName, spaceName)).Should(Exit(0)) 241 }) 242 243 Context("when the lifecycle flag is not set", func() { 244 Context("when the org and space are not provided", func() { 245 BeforeEach(func() { 246 helpers.TargetOrgAndSpace(orgName, spaceName) 247 }) 248 249 It("successfully unbinds the space from the security group", func() { 250 session := helpers.CF("unbind-security-group", secGroupName) 251 Eventually(session.Out).Should(Say("Unbinding security group %s from org %s / space %s as %s\\.\\.\\.", secGroupName, orgName, spaceName, username)) 252 Eventually(session.Out).Should(Say("OK")) 253 Eventually(session.Out).Should(Say("TIP: Changes require an app restart \\(for running\\) or restage \\(for staging\\) to apply to existing applications\\.")) 254 Eventually(session).Should(Exit(0)) 255 }) 256 }) 257 258 Context("when the org and space are provided", func() { 259 BeforeEach(func() { 260 helpers.ClearTarget() 261 }) 262 263 It("successfully unbinds the space from the security group", func() { 264 session := helpers.CF("unbind-security-group", secGroupName, orgName, spaceName) 265 Eventually(session.Out).Should(Say("Unbinding security group %s from org %s / space %s as %s\\.\\.\\.", secGroupName, orgName, spaceName, username)) 266 Eventually(session.Out).Should(Say("OK")) 267 Eventually(session.Out).Should(Say("TIP: Changes require an app restart \\(for running\\) or restage \\(for staging\\) to apply to existing applications\\.")) 268 Eventually(session).Should(Exit(0)) 269 }) 270 }) 271 }) 272 273 Context("when the lifecycle flag is running", func() { 274 Context("when the org and space are not provided", func() { 275 BeforeEach(func() { 276 helpers.TargetOrgAndSpace(orgName, spaceName) 277 }) 278 279 It("successfully unbinds the space from the security group", func() { 280 session := helpers.CF("unbind-security-group", secGroupName, "--lifecycle", "running") 281 Eventually(session.Out).Should(Say("Unbinding security group %s from org %s / space %s as %s\\.\\.\\.", secGroupName, orgName, spaceName, username)) 282 Eventually(session.Out).Should(Say("OK")) 283 Eventually(session.Out).Should(Say("TIP: Changes require an app restart \\(for running\\) or restage \\(for staging\\) to apply to existing applications\\.")) 284 Eventually(session).Should(Exit(0)) 285 }) 286 }) 287 288 Context("when the org and space are provided", func() { 289 BeforeEach(func() { 290 helpers.ClearTarget() 291 }) 292 293 It("successfully unbinds the space from the security group", func() { 294 session := helpers.CF("unbind-security-group", secGroupName, orgName, spaceName, "--lifecycle", "running") 295 Eventually(session.Out).Should(Say("Unbinding security group %s from org %s / space %s as %s\\.\\.\\.", secGroupName, orgName, spaceName, username)) 296 Eventually(session.Out).Should(Say("OK")) 297 Eventually(session.Out).Should(Say("TIP: Changes require an app restart \\(for running\\) or restage \\(for staging\\) to apply to existing applications\\.")) 298 Eventually(session).Should(Exit(0)) 299 }) 300 }) 301 }) 302 303 Context("when the lifecycle flag is staging", func() { 304 Context("when the org and space are not provided", func() { 305 BeforeEach(func() { 306 helpers.TargetOrgAndSpace(orgName, spaceName) 307 }) 308 309 It("displays an error and exits 1", func() { 310 session := helpers.CF("unbind-security-group", secGroupName, "--lifecycle", "staging") 311 Eventually(session.Out).Should(Say("Unbinding security group %s from org %s / space %s as %s\\.\\.\\.", secGroupName, orgName, spaceName, username)) 312 Eventually(session.Out).Should(Say("OK")) 313 Eventually(session.Err).Should(Say("Security group %s not bound to this space for lifecycle phase 'staging'\\.", secGroupName)) 314 Eventually(session).Should(Exit(0)) 315 }) 316 }) 317 318 Context("when the org and space are provided", func() { 319 BeforeEach(func() { 320 helpers.ClearTarget() 321 }) 322 323 It("displays an error and exits 1", func() { 324 session := helpers.CF("unbind-security-group", secGroupName, orgName, spaceName, "--lifecycle", "staging") 325 Eventually(session.Out).Should(Say("Unbinding security group %s from org %s / space %s as %s\\.\\.\\.", secGroupName, orgName, spaceName, username)) 326 Eventually(session.Out).Should(Say("OK")) 327 Eventually(session.Err).Should(Say("Security group %s not bound to this space for lifecycle phase 'staging'\\.", secGroupName)) 328 Eventually(session).Should(Exit(0)) 329 }) 330 }) 331 }) 332 }) 333 334 Context("when a space is bound to a security group in the staging lifecycle", func() { 335 BeforeEach(func() { 336 Eventually(helpers.CF("bind-security-group", secGroupName, orgName, spaceName, "--lifecycle", "staging")).Should(Exit(0)) 337 }) 338 339 Context("when the lifecycle flag is not set", func() { 340 Context("when the org and space are not provided", func() { 341 BeforeEach(func() { 342 helpers.TargetOrgAndSpace(orgName, spaceName) 343 }) 344 345 It("displays an error and exits 1", func() { 346 session := helpers.CF("unbind-security-group", secGroupName) 347 Eventually(session.Out).Should(Say("Unbinding security group %s from org %s / space %s as %s\\.\\.\\.", secGroupName, orgName, spaceName, username)) 348 Eventually(session.Out).Should(Say("OK")) 349 Eventually(session.Err).Should(Say("Security group %s not bound to this space for lifecycle phase 'running'\\.", secGroupName)) 350 Eventually(session).Should(Exit(0)) 351 }) 352 }) 353 354 Context("when the org and space are provided", func() { 355 BeforeEach(func() { 356 helpers.ClearTarget() 357 }) 358 359 It("displays an error and exits 1", func() { 360 session := helpers.CF("unbind-security-group", secGroupName, orgName, spaceName) 361 Eventually(session.Out).Should(Say("Unbinding security group %s from org %s / space %s as %s\\.\\.\\.", secGroupName, orgName, spaceName, username)) 362 Eventually(session.Out).Should(Say("OK")) 363 Eventually(session.Err).Should(Say("Security group %s not bound to this space for lifecycle phase 'running'\\.", secGroupName)) 364 Eventually(session).Should(Exit(0)) 365 }) 366 }) 367 }) 368 369 Context("when the lifecycle flag is running", func() { 370 Context("when the org and space are not provided", func() { 371 BeforeEach(func() { 372 helpers.TargetOrgAndSpace(orgName, spaceName) 373 }) 374 375 It("displays an error and exits 1", func() { 376 session := helpers.CF("unbind-security-group", secGroupName, "--lifecycle", "running") 377 Eventually(session.Out).Should(Say("Unbinding security group %s from org %s / space %s as %s\\.\\.\\.", secGroupName, orgName, spaceName, username)) 378 Eventually(session.Out).Should(Say("OK")) 379 Eventually(session.Err).Should(Say("Security group %s not bound to this space for lifecycle phase 'running'\\.", secGroupName)) 380 Eventually(session).Should(Exit(0)) 381 }) 382 }) 383 384 Context("when the org and space are provided", func() { 385 BeforeEach(func() { 386 helpers.ClearTarget() 387 }) 388 389 It("displays an error and exits 1", func() { 390 session := helpers.CF("unbind-security-group", secGroupName, orgName, spaceName, "--lifecycle", "running") 391 Eventually(session.Out).Should(Say("Unbinding security group %s from org %s / space %s as %s\\.\\.\\.", secGroupName, orgName, spaceName, username)) 392 Eventually(session.Out).Should(Say("OK")) 393 Eventually(session.Err).Should(Say("Security group %s not bound to this space for lifecycle phase 'running'\\.", secGroupName)) 394 Eventually(session).Should(Exit(0)) 395 }) 396 }) 397 }) 398 399 Context("when the lifecycle flag is staging", func() { 400 Context("when the org and space are not provided", func() { 401 BeforeEach(func() { 402 helpers.TargetOrgAndSpace(orgName, spaceName) 403 }) 404 405 It("successfully unbinds the space from the security group", func() { 406 session := helpers.CF("unbind-security-group", secGroupName, "--lifecycle", "staging") 407 Eventually(session.Out).Should(Say("Unbinding security group %s from org %s / space %s as %s\\.\\.\\.", secGroupName, orgName, spaceName, username)) 408 Eventually(session.Out).Should(Say("OK")) 409 Eventually(session.Out).Should(Say("TIP: Changes require an app restart \\(for running\\) or restage \\(for staging\\) to apply to existing applications\\.")) 410 Eventually(session).Should(Exit(0)) 411 }) 412 }) 413 414 Context("when the org and space are provided", func() { 415 BeforeEach(func() { 416 helpers.ClearTarget() 417 }) 418 419 It("successfully unbinds the space from the security group", func() { 420 session := helpers.CF("unbind-security-group", secGroupName, orgName, spaceName, "--lifecycle", "staging") 421 Eventually(session.Out).Should(Say("Unbinding security group %s from org %s / space %s as %s\\.\\.\\.", secGroupName, orgName, spaceName, username)) 422 Eventually(session.Out).Should(Say("OK")) 423 Eventually(session.Out).Should(Say("TIP: Changes require an app restart \\(for running\\) or restage \\(for staging\\) to apply to existing applications\\.")) 424 Eventually(session).Should(Exit(0)) 425 }) 426 }) 427 }) 428 }) 429 }) 430 }) 431 }) 432 })