Skip to content

Commit

Permalink
make --team-name required
Browse files Browse the repository at this point in the history
do not default to 'main'

[#127219723]
  • Loading branch information
Chris Dutra authored and pilot committed Aug 4, 2016
1 parent 52f8f29 commit 3269297
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 25 deletions.
2 changes: 1 addition & 1 deletion commands/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type LoginCommand struct {
Insecure bool `short:"k" long:"insecure" description:"Skip verification of the endpoint's SSL certificate"`
Username string `short:"u" long:"username" description:"Username for basic auth"`
Password string `short:"p" long:"password" description:"Password for basic auth"`
TeamName string `short:"n" long:"team-name" description:"Team to authenticate with" default:"main"`
TeamName string `short:"n" required:"true" long:"team-name" description:"Team to authenticate with"`
CACert flaghelpers.PathFlag `long:"ca-cert" description:"Path to Concourse PEM-encoded CA certificate file."`
}

Expand Down
19 changes: 12 additions & 7 deletions integration/login_insecure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ var _ = Describe("login -k Command", func() {
),
)

flyCmd = exec.Command(flyPath, "-t", "some-target", "login", "-c", atcServer.URL(), "-k")
flyCmd = exec.Command(flyPath, "-t", "some-target", "login", "-c", atcServer.URL(), "-k", "-n", "main")

var err error
stdin, err = flyCmd.StdinPipe()
Expand Down Expand Up @@ -140,7 +140,7 @@ var _ = Describe("login -k Command", func() {

Context("with -k", func() {
BeforeEach(func() {
otherCmd = exec.Command(flyPath, "-t", "some-target", "login", "-k")
otherCmd = exec.Command(flyPath, "-t", "some-target", "login", "-k", "-n", "main")

var err error
stdin, err = otherCmd.StdinPipe()
Expand Down Expand Up @@ -176,7 +176,7 @@ var _ = Describe("login -k Command", func() {

Context("without -k", func() {
BeforeEach(func() {
otherCmd = exec.Command(flyPath, "-t", "some-target", "login")
otherCmd = exec.Command(flyPath, "-t", "some-target", "login", "-n", "main")
})

It("errors", func() {
Expand All @@ -195,7 +195,7 @@ var _ = Describe("login -k Command", func() {
Context("to new target with invalid SSL without -k", func() {
Context("without --ca-cert", func() {
BeforeEach(func() {
flyCmd = exec.Command(flyPath, "-t", "some-target", "login", "-c", atcServer.URL())
flyCmd = exec.Command(flyPath, "-t", "some-target", "login", "-c", atcServer.URL(), "-n", "main")

var err error
stdin, err = flyCmd.StdinPipe()
Expand Down Expand Up @@ -234,7 +234,12 @@ var _ = Describe("login -k Command", func() {
_, err = caCertFile.WriteString(sslCert)
Expect(err).NotTo(HaveOccurred())

flyCmd = exec.Command(flyPath, "-t", "some-target", "login", "-c", atcServer.URL(), "--ca-cert", caCertFile.Name())
flyCmd = exec.Command(flyPath,
"-t", "some-target", "login",
"-c", atcServer.URL(),
"--ca-cert", caCertFile.Name(),
"-n", "main",
)
stdin, err = flyCmd.StdinPipe()
Expect(err).NotTo(HaveOccurred())

Expand Down Expand Up @@ -343,7 +348,7 @@ var _ = Describe("login -k Command", func() {
),
)

flyCmd = exec.Command(flyPath, "-t", "some-target", "login", "-k")
flyCmd = exec.Command(flyPath, "-t", "some-target", "login", "-k", "-n", "main")

var err error
stdin, err = flyCmd.StdinPipe()
Expand Down Expand Up @@ -384,7 +389,7 @@ var _ = Describe("login -k Command", func() {

Context("without -k", func() {
BeforeEach(func() {
flyCmd = exec.Command(flyPath, "-t", "some-target", "login")
flyCmd = exec.Command(flyPath, "-t", "some-target", "login", "-n", "main")
})

It("errors", func() {
Expand Down
26 changes: 10 additions & 16 deletions integration/login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var _ = Describe("login Command", func() {
ghttp.RespondWithJSONEncoded(200, []atc.AuthMethod{}),
),
)
flyCmd = exec.Command(flyPath, "login", "-c", atcServer.URL())
flyCmd = exec.Command(flyPath, "login", "-c", atcServer.URL(), "-n", "main")
})

It("instructs the user to specify --target", func() {
Expand All @@ -53,23 +53,15 @@ var _ = Describe("login Command", func() {
atcServer = ghttp.NewServer()
})

It("falls back to atc.DefaultTeamName team", func() {
atcServer.AppendHandlers(
infoHandler(),
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/api/v1/teams/main/auth/methods"),
ghttp.RespondWithJSONEncoded(200, []atc.AuthMethod{}),
),
tokenHandler("main"),
)

It("instructs the user to specify --team-name", func() {
flyCmd := exec.Command(flyPath, "-t", "some-target", "login", "-c", atcServer.URL())

sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())

<-sess.Exited
Expect(sess.ExitCode()).To(Equal(0))
Expect(sess.ExitCode()).To(Equal(1))

Expect(sess.Err).To(gbytes.Say("the required flag `-n, --team-name' was not specified"))
})
})

Expand Down Expand Up @@ -142,7 +134,7 @@ var _ = Describe("login Command", func() {

BeforeEach(func() {
atcServer = ghttp.NewServer()
flyCmd = exec.Command(flyPath, "-t", "some-target", "login", "-c", atcServer.URL())
flyCmd = exec.Command(flyPath, "-t", "some-target", "login", "-c", atcServer.URL(), "-n", "main")

var err error
stdin, err = flyCmd.StdinPipe()
Expand All @@ -162,7 +154,7 @@ var _ = Describe("login Command", func() {
"-ldflags", fmt.Sprintf("-X github.com/concourse/fly/version.Version=%s", flyVersion),
)
Expect(err).NotTo(HaveOccurred())
flyCmd = exec.Command(flyPath, "-t", "some-target", "login", "-c", atcServer.URL())
flyCmd = exec.Command(flyPath, "-t", "some-target", "login", "-c", atcServer.URL(), "-n", "main")
stdin, err = flyCmd.StdinPipe()
Expect(err).NotTo(HaveOccurred())

Expand Down Expand Up @@ -355,6 +347,7 @@ var _ = Describe("login Command", func() {
flyCmd = exec.Command(flyPath,
"-t", "some-target",
"login", "-c", atcServer.URL(),
"-n", "main",
"-u", "some_username",
"-p", "some_password",
)
Expand Down Expand Up @@ -474,7 +467,7 @@ var _ = Describe("login Command", func() {
})

It("updates the token", func() {
loginAgainCmd := exec.Command(flyPath, "-t", "some-target", "login")
loginAgainCmd := exec.Command(flyPath, "-t", "some-target", "login", "-n", "main")

secondFlyStdin, err := loginAgainCmd.StdinPipe()
Expect(err).NotTo(HaveOccurred())
Expand Down Expand Up @@ -543,6 +536,7 @@ var _ = Describe("login Command", func() {
flyCmd = exec.Command(flyPath,
"-t", "some-target",
"login", "-c", atcServer.URL(),
"-n", "main",
"-u", "some_username",
"-p", "some_password",
)
Expand Down
2 changes: 1 addition & 1 deletion integration/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ var _ = BeforeEach(func() {
os.Setenv("HOME", homeDir)
}

loginCmd := exec.Command(flyPath, "-t", targetName, "login", "-c", atcServer.URL())
loginCmd := exec.Command(flyPath, "-t", targetName, "login", "-c", atcServer.URL(), "-n", "main")

session, err := gexec.Start(loginCmd, GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())
Expand Down

0 comments on commit 3269297

Please sign in to comment.