~juju-qa/ubuntu/xenial/juju/xenial-2.0-beta3

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/featuretests/cmd_juju_login_test.go

  • Committer: Martin Packman
  • Date: 2016-03-30 19:31:08 UTC
  • mfrom: (1.1.41)
  • Revision ID: martin.packman@canonical.com-20160330193108-h9iz3ak334uk0z5r
Merge new upstream source 2.0~beta3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2016 Canonical Ltd.
 
2
// Licensed under the AGPLv3, see LICENCE file for details.
 
3
 
 
4
package featuretests
 
5
 
 
6
import (
 
7
        "io"
 
8
        "strings"
 
9
 
 
10
        "github.com/juju/cmd"
 
11
        "github.com/juju/loggo"
 
12
        jc "github.com/juju/testing/checkers"
 
13
        gc "gopkg.in/check.v1"
 
14
 
 
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"
 
19
)
 
20
 
 
21
type cmdLoginSuite struct {
 
22
        jujutesting.JujuConnSuite
 
23
}
 
24
 
 
25
func (s *cmdLoginSuite) run(c *gc.C, stdin io.Reader, args ...string) *cmd.Context {
 
26
        context := testing.Context(c)
 
27
        if stdin != nil {
 
28
                context.Stdin = stdin
 
29
        }
 
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
 
34
        return context
 
35
}
 
36
 
 
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")
 
40
}
 
41
 
 
42
func (s *cmdLoginSuite) TestLoginCommand(c *gc.C) {
 
43
        s.createTestUser(c)
 
44
 
 
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, `
 
48
password: 
 
49
type password again: 
 
50
You are now logged in to "kontroll" as "test@local".
 
51
`[1:])
 
52
 
 
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), "")
 
59
 
 
60
        // We should be able to login with the macaroon.
 
61
        s.run(c, nil, "status")
 
62
}