1
// Copyright 2016 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
11
"github.com/juju/loggo"
12
jc "github.com/juju/testing/checkers"
13
gc "gopkg.in/check.v1"
15
"github.com/juju/juju/cmd/juju/commands"
16
jujutesting "github.com/juju/juju/juju/testing"
17
"github.com/juju/juju/jujuclient"
18
"github.com/juju/juju/testing"
21
type cmdLoginSuite struct {
22
jujutesting.JujuConnSuite
25
func (s *cmdLoginSuite) run(c *gc.C, stdin io.Reader, args ...string) *cmd.Context {
26
context := testing.Context(c)
30
command := commands.NewJujuCommand(context)
31
c.Assert(testing.InitCommand(command, args), jc.ErrorIsNil)
32
c.Assert(command.Run(context), jc.ErrorIsNil)
33
loggo.RemoveWriter("warning") // remove logger added by main command
37
func (s *cmdLoginSuite) createTestUser(c *gc.C) {
38
s.run(c, nil, "add-user", "test", "--models", "admin")
39
s.run(c, strings.NewReader("hunter2\nhunter2\n"), "change-user-password", "test")
42
func (s *cmdLoginSuite) TestLoginCommand(c *gc.C) {
45
context := s.run(c, strings.NewReader("hunter2\nhunter2\n"), "login", "test")
46
c.Assert(testing.Stdout(context), gc.Equals, "")
47
c.Assert(testing.Stderr(context), gc.Equals, `
50
You are now logged in to "kontroll" as "test@local".
53
// We should have a macaroon, but no password, in the client store.
54
store := jujuclient.NewFileClientStore()
55
accountDetails, err := store.AccountByName("kontroll", "test@local")
56
c.Assert(err, jc.ErrorIsNil)
57
c.Assert(accountDetails.Password, gc.Equals, "")
58
c.Assert(accountDetails.Macaroon, gc.Not(gc.Equals), "")
60
// We should be able to login with the macaroon.
61
s.run(c, nil, "status")