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

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/provider/azure/auth_test.go

  • Committer: Nicholas Skaggs
  • Date: 2016-09-30 14:39:30 UTC
  • mfrom: (1.8.1)
  • Revision ID: nicholas.skaggs@canonical.com-20160930143930-vwwhrefh6ftckccy
import upstream

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 azure_test
 
5
 
 
6
import (
 
7
        "net/http"
 
8
 
 
9
        "github.com/juju/testing"
 
10
        jc "github.com/juju/testing/checkers"
 
11
        gc "gopkg.in/check.v1"
 
12
 
 
13
        "github.com/juju/juju/cloud"
 
14
        "github.com/juju/juju/environs"
 
15
        "github.com/juju/juju/provider/azure"
 
16
        "github.com/juju/juju/provider/azure/internal/azuretesting"
 
17
)
 
18
 
 
19
type AuthSuite struct {
 
20
        testing.IsolationSuite
 
21
        requests []*http.Request
 
22
}
 
23
 
 
24
var _ = gc.Suite(&AuthSuite{})
 
25
 
 
26
func (s *AuthSuite) TestAuthTokenServicePrincipalSecret(c *gc.C) {
 
27
        spec := environs.CloudSpec{
 
28
                Type:             "azure",
 
29
                Name:             "azure",
 
30
                Region:           "westus",
 
31
                Endpoint:         "https://api.azurestack.local",
 
32
                IdentityEndpoint: "https://graph.azurestack.local",
 
33
                StorageEndpoint:  "https://storage.azurestack.local",
 
34
                Credential:       fakeServicePrincipalCredential(),
 
35
        }
 
36
        senders := azuretesting.Senders{
 
37
                discoverAuthSender(),
 
38
        }
 
39
        token, err := azure.AuthToken(spec, &senders)
 
40
        c.Assert(err, jc.ErrorIsNil)
 
41
        c.Assert(token, gc.NotNil)
 
42
}
 
43
 
 
44
func (s *AuthSuite) TestAuthTokenInteractive(c *gc.C) {
 
45
        spec := environs.CloudSpec{
 
46
                Type:             "azure",
 
47
                Name:             "azure",
 
48
                Region:           "westus",
 
49
                Endpoint:         "https://api.azurestack.local",
 
50
                IdentityEndpoint: "https://graph.azurestack.local",
 
51
                StorageEndpoint:  "https://storage.azurestack.local",
 
52
                Credential:       fakeInteractiveCredential(),
 
53
        }
 
54
        senders := azuretesting.Senders{}
 
55
        _, err := azure.AuthToken(spec, &senders)
 
56
        c.Assert(err, gc.ErrorMatches, `auth-type "interactive" not supported`)
 
57
}
 
58
 
 
59
func fakeInteractiveCredential() *cloud.Credential {
 
60
        cred := cloud.NewCredential("interactive", map[string]string{
 
61
                "subscription-id": fakeSubscriptionId,
 
62
        })
 
63
        return &cred
 
64
}