github.com/chenbh/concourse/v6@v6.4.2/fly/integration/set_team_test.go (about) 1 package integration_test 2 3 import ( 4 "fmt" 5 "github.com/chenbh/concourse/v6/atc" 6 "github.com/onsi/ginkgo" 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 "io" 13 "net/http" 14 "os/exec" 15 ) 16 17 var _ = Describe("Fly CLI", func() { 18 var ( 19 flyCmd *exec.Cmd 20 cmdParams []string 21 ) 22 23 JustBeforeEach(func() { 24 params := append([]string{"-t", targetName, "set-team", "--team-name", "venture"}, cmdParams...) 25 flyCmd = exec.Command(flyPath, params...) 26 }) 27 28 yes := func(stdin io.Writer) { 29 fmt.Fprintf(stdin, "y\n") 30 } 31 32 no := func(stdin io.Writer) { 33 fmt.Fprintf(stdin, "n\n") 34 } 35 36 Context("using a config file", func() { 37 Describe("config validation", func() { 38 Describe("no auth", func() { 39 Context("auth config is missing auth for role", func() { 40 BeforeEach(func() { 41 cmdParams = []string{"-c", "fixtures/team_config_no_auth_for_role.yml"} 42 }) 43 44 It("discard role with missing auth", func() { 45 sess, err := gexec.Start(flyCmd, ginkgo.GinkgoWriter, ginkgo.GinkgoWriter) 46 Expect(err).ToNot(HaveOccurred()) 47 48 Eventually(sess.Out).Should(gbytes.Say("setting team: venture")) 49 50 Eventually(sess.Out).Should(gbytes.Say("role member:")) 51 Eventually(sess.Out).Should(gbytes.Say("users:")) 52 Eventually(sess.Out).Should(gbytes.Say("- local:some-user")) 53 Eventually(sess.Out).Should(gbytes.Say("groups:")) 54 Eventually(sess.Out).Should(gbytes.Say("none")) 55 Eventually(sess.Out).Should(gbytes.Say("role owner:")) 56 Eventually(sess.Out).Should(gbytes.Say("users:")) 57 Eventually(sess.Out).Should(gbytes.Say("- local:some-admin")) 58 Eventually(sess.Out).Should(gbytes.Say("groups:")) 59 Eventually(sess.Out).Should(gbytes.Say("none")) 60 61 Eventually(sess.Out).ShouldNot(gbytes.Say("role viewer:")) 62 63 Eventually(sess).Should(gexec.Exit(1)) 64 }) 65 }) 66 67 Context("auth config contains empty user", func() { 68 BeforeEach(func() { 69 cmdParams = []string{"-c", "fixtures/team_config_empty_users.yml"} 70 }) 71 72 It("discard role with no user and group", func() { 73 sess, err := gexec.Start(flyCmd, ginkgo.GinkgoWriter, ginkgo.GinkgoWriter) 74 Expect(err).ToNot(HaveOccurred()) 75 Eventually(sess.Out).Should(gbytes.Say("setting team: venture")) 76 77 Eventually(sess.Out).Should(gbytes.Say("role owner:")) 78 Eventually(sess.Out).Should(gbytes.Say("users:")) 79 Eventually(sess.Out).Should(gbytes.Say("- local:some-admin")) 80 Eventually(sess.Out).Should(gbytes.Say("groups:")) 81 Eventually(sess.Out).Should(gbytes.Say("none")) 82 83 Eventually(sess.Out).ShouldNot(gbytes.Say("role viewer:")) 84 85 Eventually(sess).Should(gexec.Exit(1)) 86 }) 87 }) 88 }) 89 }) 90 91 Describe("Display", func() { 92 Context("Setting local auth", func() { 93 BeforeEach(func() { 94 cmdParams = []string{"-c", "fixtures/team_config_with_local_auth.yml"} 95 }) 96 97 It("shows the users configured for local auth for a given role", func() { 98 sess, err := gexec.Start(flyCmd, ginkgo.GinkgoWriter, ginkgo.GinkgoWriter) 99 Expect(err).ToNot(HaveOccurred()) 100 101 Eventually(sess.Out).Should(gbytes.Say("setting team: venture")) 102 103 Eventually(sess.Out).Should(gbytes.Say("role member:")) 104 Eventually(sess.Out).Should(gbytes.Say("users:")) 105 Eventually(sess.Out).Should(gbytes.Say("- local:some-member")) 106 Eventually(sess.Out).Should(gbytes.Say("groups:")) 107 Eventually(sess.Out).Should(gbytes.Say("none")) 108 109 Eventually(sess.Out).Should(gbytes.Say("role owner:")) 110 Eventually(sess.Out).Should(gbytes.Say("users:")) 111 Eventually(sess.Out).Should(gbytes.Say("- local:some-owner")) 112 Eventually(sess.Out).Should(gbytes.Say("groups:")) 113 Eventually(sess.Out).Should(gbytes.Say("none")) 114 115 Eventually(sess.Out).Should(gbytes.Say("role viewer:")) 116 Eventually(sess.Out).Should(gbytes.Say("users:")) 117 Eventually(sess.Out).Should(gbytes.Say("- local:some-viewer")) 118 Eventually(sess.Out).Should(gbytes.Say("groups:")) 119 Eventually(sess.Out).Should(gbytes.Say("none")) 120 121 Eventually(sess).Should(gexec.Exit(1)) 122 }) 123 }) 124 125 Context("Setting github auth", func() { 126 BeforeEach(func() { 127 cmdParams = []string{"-c", "fixtures/team_config_with_github_auth.yml"} 128 }) 129 130 It("shows the users and groups configured for github for a given role", func() { 131 sess, err := gexec.Start(flyCmd, ginkgo.GinkgoWriter, ginkgo.GinkgoWriter) 132 Expect(err).ToNot(HaveOccurred()) 133 134 Eventually(sess.Out).Should(gbytes.Say("setting team: venture")) 135 136 Eventually(sess.Out).Should(gbytes.Say("role member:")) 137 Eventually(sess.Out).Should(gbytes.Say("users:")) 138 Eventually(sess.Out).Should(gbytes.Say("- github:some-user")) 139 Eventually(sess.Out).Should(gbytes.Say("groups:")) 140 Eventually(sess.Out).Should(gbytes.Say("none")) 141 142 Eventually(sess.Out).Should(gbytes.Say("role owner:")) 143 Eventually(sess.Out).Should(gbytes.Say("users:")) 144 Eventually(sess.Out).Should(gbytes.Say("none")) 145 Eventually(sess.Out).Should(gbytes.Say("groups:")) 146 Eventually(sess.Out).Should(gbytes.Say("- github:some-other-org")) 147 148 Eventually(sess.Out).Should(gbytes.Say("role viewer:")) 149 Eventually(sess.Out).Should(gbytes.Say("users:")) 150 Eventually(sess.Out).Should(gbytes.Say("- github:some-github-user")) 151 Eventually(sess.Out).Should(gbytes.Say("groups:")) 152 Eventually(sess.Out).Should(gbytes.Say("- github:some-org:some-team")) 153 154 Eventually(sess).Should(gexec.Exit(1)) 155 }) 156 }) 157 158 Context("Setting cf auth", func() { 159 BeforeEach(func() { 160 cmdParams = []string{"-c", "fixtures/team_config_with_cf_auth.yml"} 161 }) 162 163 It("shows the users and groups configured for cf auth for a given role", func() { 164 sess, err := gexec.Start(flyCmd, ginkgo.GinkgoWriter, ginkgo.GinkgoWriter) 165 Expect(err).ToNot(HaveOccurred()) 166 167 Eventually(sess.Out).Should(gbytes.Say("setting team: venture")) 168 169 Eventually(sess.Out).Should(gbytes.Say("role member:")) 170 Eventually(sess.Out).Should(gbytes.Say("users:")) 171 Eventually(sess.Out).Should(gbytes.Say("- cf:some-member")) 172 Eventually(sess.Out).Should(gbytes.Say("groups:")) 173 Eventually(sess.Out).Should(gbytes.Say("- cf:some-org:some-space:developer")) 174 175 Eventually(sess.Out).Should(gbytes.Say("role owner:")) 176 Eventually(sess.Out).Should(gbytes.Say("users:")) 177 Eventually(sess.Out).Should(gbytes.Say("- cf:some-admin")) 178 Eventually(sess.Out).Should(gbytes.Say("groups:")) 179 Eventually(sess.Out).Should(gbytes.Say("- cf:some-org")) 180 Eventually(sess.Out).Should(gbytes.Say("- cf:some-org:some-space:manager")) 181 Eventually(sess.Out).Should(gbytes.Say("- cf:some-guid")) 182 183 Eventually(sess.Out).Should(gbytes.Say("role viewer:")) 184 Eventually(sess.Out).Should(gbytes.Say("users:")) 185 Eventually(sess.Out).Should(gbytes.Say("none")) 186 Eventually(sess.Out).Should(gbytes.Say("groups:")) 187 Eventually(sess.Out).Should(gbytes.Say("- cf:some-org:some-other-space")) 188 Eventually(sess.Out).Should(gbytes.Say("- cf:some-org:some-space:developer")) 189 Eventually(sess.Out).Should(gbytes.Say("- cf:some-org:some-space:auditor")) 190 Eventually(sess.Out).Should(gbytes.Say("- cf:some-guid")) 191 192 Eventually(sess).Should(gexec.Exit(1)) 193 }) 194 }) 195 196 Context("Setting ldap auth", func() { 197 BeforeEach(func() { 198 cmdParams = []string{"-c", "fixtures/team_config_with_ldap_auth.yml"} 199 }) 200 201 It("shows the users and groups configured for ldap auth for a given role", func() { 202 sess, err := gexec.Start(flyCmd, ginkgo.GinkgoWriter, ginkgo.GinkgoWriter) 203 Expect(err).ToNot(HaveOccurred()) 204 205 Eventually(sess.Out).Should(gbytes.Say("setting team: venture")) 206 207 Eventually(sess.Out).Should(gbytes.Say("role member:")) 208 Eventually(sess.Out).Should(gbytes.Say("users:")) 209 Eventually(sess.Out).Should(gbytes.Say("- ldap:some-user")) 210 Eventually(sess.Out).Should(gbytes.Say("groups:")) 211 Eventually(sess.Out).Should(gbytes.Say("none")) 212 213 Eventually(sess.Out).Should(gbytes.Say("role owner:")) 214 Eventually(sess.Out).Should(gbytes.Say("users:")) 215 Eventually(sess.Out).Should(gbytes.Say("- ldap:some-admin")) 216 Eventually(sess.Out).Should(gbytes.Say("groups:")) 217 Eventually(sess.Out).Should(gbytes.Say("- ldap:some-other-group")) 218 219 Eventually(sess.Out).Should(gbytes.Say("role viewer:")) 220 Eventually(sess.Out).Should(gbytes.Say("users:")) 221 Eventually(sess.Out).Should(gbytes.Say("none")) 222 Eventually(sess.Out).Should(gbytes.Say("groups:")) 223 Eventually(sess.Out).Should(gbytes.Say("- ldap:some-group")) 224 225 Eventually(sess).Should(gexec.Exit(1)) 226 }) 227 }) 228 229 Context("Setting generic oauth", func() { 230 BeforeEach(func() { 231 cmdParams = []string{"-c", "fixtures/team_config_with_generic_oauth.yml"} 232 }) 233 234 It("shows the groups configured for generic oauth for a given role", func() { 235 sess, err := gexec.Start(flyCmd, ginkgo.GinkgoWriter, ginkgo.GinkgoWriter) 236 Expect(err).ToNot(HaveOccurred()) 237 238 Eventually(sess.Out).Should(gbytes.Say("setting team: venture")) 239 240 Eventually(sess.Out).Should(gbytes.Say("role member:")) 241 Eventually(sess.Out).Should(gbytes.Say("users:")) 242 Eventually(sess.Out).Should(gbytes.Say("- oauth:some-user")) 243 Eventually(sess.Out).Should(gbytes.Say("groups:")) 244 Eventually(sess.Out).Should(gbytes.Say("none")) 245 246 Eventually(sess.Out).Should(gbytes.Say("role owner:")) 247 Eventually(sess.Out).Should(gbytes.Say("users:")) 248 Eventually(sess.Out).Should(gbytes.Say("- oauth:some-admin")) 249 Eventually(sess.Out).Should(gbytes.Say("groups:")) 250 Eventually(sess.Out).Should(gbytes.Say("- oauth:some-other-group")) 251 252 Eventually(sess.Out).Should(gbytes.Say("role viewer:")) 253 Eventually(sess.Out).Should(gbytes.Say("users:")) 254 Eventually(sess.Out).Should(gbytes.Say("none")) 255 Eventually(sess.Out).Should(gbytes.Say("groups:")) 256 Eventually(sess.Out).Should(gbytes.Say("- oauth:some-group")) 257 258 Eventually(sess).Should(gexec.Exit(1)) 259 }) 260 }) 261 262 Context("Setting auth with empty values", func() { 263 BeforeEach(func() { 264 cmdParams = []string{"-c", "fixtures/team_config_empty_values.yml"} 265 }) 266 267 It("shows the users and groups configured for a given role", func() { 268 sess, err := gexec.Start(flyCmd, ginkgo.GinkgoWriter, ginkgo.GinkgoWriter) 269 Expect(err).ToNot(HaveOccurred()) 270 271 Eventually(sess.Out).Should(gbytes.Say("setting team: venture")) 272 273 Eventually(sess.Out).Should(gbytes.Say("role member:")) 274 Eventually(sess.Out).Should(gbytes.Say("users:")) 275 Eventually(sess.Out).Should(gbytes.Say("none")) 276 Eventually(sess.Out).Should(gbytes.Say("groups:")) 277 Eventually(sess.Out).Should(gbytes.Say("- github:some-org")) 278 279 Eventually(sess.Out).Should(gbytes.Say("role owner:")) 280 Eventually(sess.Out).Should(gbytes.Say("users:")) 281 Eventually(sess.Out).Should(gbytes.Say("- local:some-admin")) 282 Eventually(sess.Out).Should(gbytes.Say("groups:")) 283 Eventually(sess.Out).Should(gbytes.Say("none")) 284 285 Eventually(sess.Out).Should(gbytes.Say("role viewer:")) 286 Eventually(sess.Out).Should(gbytes.Say("users:")) 287 Eventually(sess.Out).Should(gbytes.Say("- local:some-viewer")) 288 Eventually(sess.Out).Should(gbytes.Say("groups:")) 289 Eventually(sess.Out).Should(gbytes.Say("none")) 290 291 Eventually(sess).Should(gexec.Exit(1)) 292 }) 293 }) 294 }) 295 296 Describe("confirmation", func() { 297 BeforeEach(func() { 298 cmdParams = []string{"-c", "fixtures/team_config.yml"} 299 }) 300 301 Context("when the user presses y/yes", func() { 302 BeforeEach(func() { 303 confirmHandlers() 304 }) 305 306 It("exits 0", func() { 307 stdin, err := flyCmd.StdinPipe() 308 Expect(err).NotTo(HaveOccurred()) 309 310 sess, err := gexec.Start(flyCmd, ginkgo.GinkgoWriter, ginkgo.GinkgoWriter) 311 Expect(err).ToNot(HaveOccurred()) 312 313 Eventually(sess).Should(gbytes.Say(`apply team configuration\? \[yN\]: `)) 314 yes(stdin) 315 316 Eventually(sess).Should(gexec.Exit(0)) 317 }) 318 }) 319 320 Context("when the user presses n/no", func() { 321 It("exits 1", func() { 322 stdin, err := flyCmd.StdinPipe() 323 Expect(err).NotTo(HaveOccurred()) 324 325 sess, err := gexec.Start(flyCmd, ginkgo.GinkgoWriter, ginkgo.GinkgoWriter) 326 Expect(err).ToNot(HaveOccurred()) 327 328 Eventually(sess).Should(gbytes.Say(`apply team configuration\? \[yN\]: `)) 329 no(stdin) 330 331 Eventually(sess.Err).Should(gbytes.Say("bailing out")) 332 Eventually(sess).Should(gexec.Exit(1)) 333 }) 334 }) 335 }) 336 337 Describe("sending", func() { 338 BeforeEach(func() { 339 cmdParams = []string{"-c", "fixtures/team_config_mixed.yml"} 340 341 atcServer.AppendHandlers( 342 ghttp.CombineHandlers( 343 ghttp.VerifyRequest("PUT", "/api/v1/teams/venture"), 344 ghttp.VerifyJSON(`{ 345 "auth": { 346 "owner":{ 347 "users": [ 348 "github:some-github-user", 349 "local:some-admin" 350 ], 351 "groups": [ 352 "oauth:some-oauth-group" 353 ] 354 }, 355 "member":{ 356 "users": [ 357 "local:some-user" 358 ], 359 "groups": [] 360 }, 361 "viewer":{ 362 "users": [ 363 "local:some-viewer" 364 ], 365 "groups": [] 366 } 367 } 368 }`), 369 ghttp.RespondWithJSONEncoded(http.StatusCreated, atc.Team{ 370 Name: "venture", 371 ID: 8, 372 }), 373 ), 374 ) 375 }) 376 377 It("sends the expected request", func() { 378 stdin, err := flyCmd.StdinPipe() 379 Expect(err).NotTo(HaveOccurred()) 380 381 sess, err := gexec.Start(flyCmd, ginkgo.GinkgoWriter, ginkgo.GinkgoWriter) 382 Expect(err).ToNot(HaveOccurred()) 383 384 Eventually(sess).Should(gbytes.Say(`apply team configuration\? \[yN\]: `)) 385 yes(stdin) 386 387 Eventually(sess).Should(gexec.Exit(0)) 388 }) 389 390 It("Outputs created for new team", func() { 391 stdin, err := flyCmd.StdinPipe() 392 Expect(err).NotTo(HaveOccurred()) 393 394 sess, err := gexec.Start(flyCmd, ginkgo.GinkgoWriter, ginkgo.GinkgoWriter) 395 Expect(err).ToNot(HaveOccurred()) 396 397 Eventually(sess).Should(gbytes.Say(`apply team configuration\? \[yN\]: `)) 398 yes(stdin) 399 400 Eventually(sess.Out).Should(gbytes.Say("team created")) 401 402 Eventually(sess).Should(gexec.Exit(0)) 403 }) 404 }) 405 406 Describe("handling server response", func() { 407 BeforeEach(func() { 408 cmdParams = []string{"-c", "fixtures/team_config_mixed.yml"} 409 }) 410 411 Context("when the server returns 500", func() { 412 BeforeEach(func() { 413 atcServer.AppendHandlers( 414 ghttp.CombineHandlers( 415 ghttp.VerifyRequest("PUT", "/api/v1/teams/venture"), 416 ghttp.VerifyJSON(`{ 417 "auth": { 418 "owner":{ 419 "users": [ 420 "github:some-github-user", 421 "local:some-admin" 422 ], 423 "groups": [ 424 "oauth:some-oauth-group" 425 ] 426 }, 427 "member":{ 428 "users": [ 429 "local:some-user" 430 ], 431 "groups": [] 432 }, 433 "viewer":{ 434 "users": [ 435 "local:some-viewer" 436 ], 437 "groups": [] 438 } 439 } 440 }`), 441 ghttp.RespondWith(http.StatusInternalServerError, "sorry bro"), 442 ), 443 ) 444 }) 445 446 It("reports the error", func() { 447 stdin, err := flyCmd.StdinPipe() 448 Expect(err).NotTo(HaveOccurred()) 449 450 sess, err := gexec.Start(flyCmd, ginkgo.GinkgoWriter, ginkgo.GinkgoWriter) 451 Expect(err).ToNot(HaveOccurred()) 452 453 Eventually(sess).Should(gbytes.Say(`apply team configuration\? \[yN\]: `)) 454 yes(stdin) 455 456 Eventually(sess.Err).Should(gbytes.Say("sorry bro")) 457 458 Eventually(sess).Should(gexec.Exit(1)) 459 }) 460 }) 461 }) 462 }) 463 464 Context("using command line args", func() { 465 Describe("flag validation", func() { 466 Describe("no auth", func() { 467 Context("auth flag not provided", func() { 468 BeforeEach(func() { 469 cmdParams = []string{} 470 }) 471 472 It("returns an error", func() { 473 sess, err := gexec.Start(flyCmd, ginkgo.GinkgoWriter, ginkgo.GinkgoWriter) 474 Expect(err).ToNot(HaveOccurred()) 475 Eventually(sess.Err).Should(gbytes.Say("auth config for the team does not have users and groups configured")) 476 Eventually(sess).Should(gexec.Exit(1)) 477 }) 478 }) 479 480 Context("empty auth values provided", func() { 481 BeforeEach(func() { 482 cmdParams = []string{"--local-user", ""} 483 }) 484 485 It("returns an error", func() { 486 sess, err := gexec.Start(flyCmd, ginkgo.GinkgoWriter, ginkgo.GinkgoWriter) 487 Expect(err).ToNot(HaveOccurred()) 488 Eventually(sess.Err).Should(gbytes.Say("auth config for the team does not have users and groups configured")) 489 Eventually(sess).Should(gexec.Exit(1)) 490 }) 491 }) 492 493 Context("empty auth file is provided", func() { 494 BeforeEach(func() { 495 cmdParams = []string{"-c", "fixtures/team_config_empty.yml"} 496 }) 497 498 It("returns an error", func() { 499 sess, err := gexec.Start(flyCmd, ginkgo.GinkgoWriter, ginkgo.GinkgoWriter) 500 Expect(err).ToNot(HaveOccurred()) 501 Eventually(sess.Err).Should(gbytes.Say("auth config for the team must not be empty")) 502 Eventually(sess).Should(gexec.Exit(1)) 503 }) 504 }) 505 }) 506 }) 507 508 Describe("Display", func() { 509 Context("Setting local auth", func() { 510 BeforeEach(func() { 511 cmdParams = []string{"--local-user", "brock-samson"} 512 }) 513 514 It("shows the users configured for local auth", func() { 515 sess, err := gexec.Start(flyCmd, ginkgo.GinkgoWriter, ginkgo.GinkgoWriter) 516 Expect(err).ToNot(HaveOccurred()) 517 518 Eventually(sess.Out).Should(gbytes.Say("setting team: venture")) 519 Eventually(sess.Out).Should(gbytes.Say("role owner:")) 520 Eventually(sess.Out).Should(gbytes.Say("users:")) 521 Eventually(sess.Out).Should(gbytes.Say("- local:brock-samson")) 522 Eventually(sess.Out).Should(gbytes.Say("groups:")) 523 Eventually(sess.Out).Should(gbytes.Say("none")) 524 525 Eventually(sess).Should(gexec.Exit(1)) 526 }) 527 }) 528 529 Context("Setting cf auth", func() { 530 BeforeEach(func() { 531 cmdParams = []string{"--cf-org", "myorg-1", "--cf-space", "myorg-2:myspace", "--cf-user", "my-username", "--cf-space-guid", "myspace-guid"} 532 }) 533 534 It("shows the users and groups configured for cf auth", func() { 535 sess, err := gexec.Start(flyCmd, ginkgo.GinkgoWriter, ginkgo.GinkgoWriter) 536 Expect(err).ToNot(HaveOccurred()) 537 538 Eventually(sess.Out).Should(gbytes.Say("setting team: venture")) 539 Eventually(sess.Out).Should(gbytes.Say("role owner:")) 540 Eventually(sess.Out).Should(gbytes.Say("users:")) 541 Eventually(sess.Out).Should(gbytes.Say("- cf:my-username")) 542 Eventually(sess.Out).Should(gbytes.Say("groups:")) 543 Eventually(sess.Out).Should(gbytes.Say("- cf:myorg-1")) 544 Eventually(sess.Out).Should(gbytes.Say("- cf:myorg-2:myspace")) 545 Eventually(sess.Out).Should(gbytes.Say("- cf:myspace-guid")) 546 547 Eventually(sess).Should(gexec.Exit(1)) 548 }) 549 }) 550 551 Context("Setting ldap auth", func() { 552 BeforeEach(func() { 553 cmdParams = []string{"--ldap-group", "my-group", "--ldap-user", "my-username"} 554 }) 555 556 It("shows the users and groups configured for ldap auth", func() { 557 sess, err := gexec.Start(flyCmd, ginkgo.GinkgoWriter, ginkgo.GinkgoWriter) 558 Expect(err).ToNot(HaveOccurred()) 559 560 Eventually(sess.Out).Should(gbytes.Say("setting team: venture")) 561 Eventually(sess.Out).Should(gbytes.Say("role owner:")) 562 Eventually(sess.Out).Should(gbytes.Say("users:")) 563 Eventually(sess.Out).Should(gbytes.Say("- ldap:my-username")) 564 Eventually(sess.Out).Should(gbytes.Say("groups:")) 565 Eventually(sess.Out).Should(gbytes.Say("- ldap:my-group")) 566 567 Eventually(sess).Should(gexec.Exit(1)) 568 }) 569 }) 570 571 Context("Setting generic oauth", func() { 572 BeforeEach(func() { 573 cmdParams = []string{ 574 "--oauth-group", "cool-scope-name", 575 } 576 }) 577 578 It("shows the groups configured for generic oauth", func() { 579 sess, err := gexec.Start(flyCmd, ginkgo.GinkgoWriter, ginkgo.GinkgoWriter) 580 Expect(err).ToNot(HaveOccurred()) 581 582 Eventually(sess.Out).Should(gbytes.Say("setting team: venture")) 583 Eventually(sess.Out).Should(gbytes.Say("role owner:")) 584 Eventually(sess.Out).Should(gbytes.Say("users:")) 585 Eventually(sess.Out).Should(gbytes.Say("none")) 586 Eventually(sess.Out).Should(gbytes.Say("groups:")) 587 Eventually(sess.Out).Should(gbytes.Say("- oauth:cool-scope-name")) 588 589 Eventually(sess).Should(gexec.Exit(1)) 590 }) 591 }) 592 593 Context("Setting auth with empty arguments", func() { 594 BeforeEach(func() { 595 cmdParams = []string{"--oauth-group", "", "--github-team", "samson-org:samson-team", "--github-user", ""} 596 }) 597 598 It("ignores empty arguments", func() { 599 sess, err := gexec.Start(flyCmd, ginkgo.GinkgoWriter, ginkgo.GinkgoWriter) 600 Expect(err).ToNot(HaveOccurred()) 601 602 Eventually(sess.Out).Should(gbytes.Say("setting team: venture")) 603 Eventually(sess.Out).Should(gbytes.Say("role owner:")) 604 Eventually(sess.Out).Should(gbytes.Say("users:")) 605 Eventually(sess.Out).Should(gbytes.Say("none")) 606 Eventually(sess.Out).Should(gbytes.Say("groups:")) 607 Eventually(sess.Out).Should(gbytes.Say("- github:samson-org:samson-team")) 608 609 Eventually(sess).Should(gexec.Exit(1)) 610 }) 611 }) 612 }) 613 614 Describe("confirmation", func() { 615 BeforeEach(func() { 616 cmdParams = []string{"--local-user", "brock-samson"} 617 }) 618 619 Context("when the user presses y/yes", func() { 620 BeforeEach(func() { 621 confirmHandlers() 622 }) 623 624 It("exits 0", func() { 625 stdin, err := flyCmd.StdinPipe() 626 Expect(err).NotTo(HaveOccurred()) 627 628 sess, err := gexec.Start(flyCmd, ginkgo.GinkgoWriter, ginkgo.GinkgoWriter) 629 Expect(err).ToNot(HaveOccurred()) 630 631 Eventually(sess).Should(gbytes.Say(`apply team configuration\? \[yN\]: `)) 632 yes(stdin) 633 634 Eventually(sess).Should(gexec.Exit(0)) 635 }) 636 }) 637 638 Context("when the user presses n/no", func() { 639 It("exits 1", func() { 640 stdin, err := flyCmd.StdinPipe() 641 Expect(err).NotTo(HaveOccurred()) 642 643 sess, err := gexec.Start(flyCmd, ginkgo.GinkgoWriter, ginkgo.GinkgoWriter) 644 Expect(err).ToNot(HaveOccurred()) 645 646 Eventually(sess).Should(gbytes.Say(`apply team configuration\? \[yN\]: `)) 647 no(stdin) 648 649 Eventually(sess.Err).Should(gbytes.Say("bailing out")) 650 Eventually(sess).Should(gexec.Exit(1)) 651 }) 652 }) 653 }) 654 655 Describe("sending", func() { 656 BeforeEach(func() { 657 cmdParams = []string{ 658 "--local-user", "brock-obama", 659 "--github-org", "obama-org", 660 "--github-team", "samson-org:venture-team", 661 "--github-user", "lisa", 662 "--github-user", "frank", 663 } 664 665 atcServer.AppendHandlers( 666 ghttp.CombineHandlers( 667 ghttp.VerifyRequest("PUT", "/api/v1/teams/venture"), 668 ghttp.VerifyJSON(`{ 669 "auth": { 670 "owner":{ 671 "users": [ 672 "github:lisa", 673 "github:frank", 674 "local:brock-obama" 675 ], 676 "groups": [ 677 "github:obama-org", 678 "github:samson-org:venture-team" 679 ] 680 } 681 } 682 }`), 683 ghttp.RespondWithJSONEncoded(http.StatusCreated, atc.Team{ 684 Name: "venture", 685 ID: 8, 686 }), 687 ), 688 ) 689 }) 690 691 It("sends the expected request", func() { 692 stdin, err := flyCmd.StdinPipe() 693 Expect(err).NotTo(HaveOccurred()) 694 695 sess, err := gexec.Start(flyCmd, ginkgo.GinkgoWriter, ginkgo.GinkgoWriter) 696 Expect(err).ToNot(HaveOccurred()) 697 698 Eventually(sess).Should(gbytes.Say(`apply team configuration\? \[yN\]: `)) 699 yes(stdin) 700 701 Eventually(sess).Should(gexec.Exit(0)) 702 }) 703 704 It("Outputs created for new team", func() { 705 stdin, err := flyCmd.StdinPipe() 706 Expect(err).NotTo(HaveOccurred()) 707 708 sess, err := gexec.Start(flyCmd, ginkgo.GinkgoWriter, ginkgo.GinkgoWriter) 709 Expect(err).ToNot(HaveOccurred()) 710 711 Eventually(sess).Should(gbytes.Say(`apply team configuration\? \[yN\]: `)) 712 yes(stdin) 713 714 Eventually(sess.Out).Should(gbytes.Say("team created")) 715 716 Eventually(sess).Should(gexec.Exit(0)) 717 }) 718 }) 719 720 Describe("handling server response", func() { 721 BeforeEach(func() { 722 cmdParams = []string{"--local-user", "brock-obama"} 723 }) 724 725 Context("when the server returns 500", func() { 726 BeforeEach(func() { 727 atcServer.AppendHandlers( 728 ghttp.CombineHandlers( 729 ghttp.VerifyRequest("PUT", "/api/v1/teams/venture"), 730 ghttp.VerifyJSON(`{ 731 "auth": { 732 "owner":{ 733 "users": [ 734 "local:brock-obama" 735 ], 736 "groups": [] 737 } 738 } 739 }`), 740 ghttp.RespondWith(http.StatusInternalServerError, "sorry bro"), 741 ), 742 ) 743 }) 744 745 It("reports the error", func() { 746 stdin, err := flyCmd.StdinPipe() 747 Expect(err).NotTo(HaveOccurred()) 748 749 sess, err := gexec.Start(flyCmd, ginkgo.GinkgoWriter, ginkgo.GinkgoWriter) 750 Expect(err).ToNot(HaveOccurred()) 751 752 Eventually(sess).Should(gbytes.Say(`apply team configuration\? \[yN\]: `)) 753 yes(stdin) 754 755 Eventually(sess.Err).Should(gbytes.Say("sorry bro")) 756 757 Eventually(sess).Should(gexec.Exit(1)) 758 }) 759 }) 760 }) 761 }) 762 }) 763 764 func confirmHandlers() { 765 atcServer.AppendHandlers( 766 ghttp.CombineHandlers( 767 ghttp.VerifyRequest("PUT", "/api/v1/teams/venture"), 768 ghttp.RespondWithJSONEncoded(http.StatusCreated, atc.Team{ 769 Name: "venture", 770 ID: 8, 771 }), 772 ), 773 ) 774 }