github.com/axw/juju@v0.0.0-20161005053422-4bd6544d08d4/provider/azure/auth_test.go (about)

     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  }