Exemple #1
0
func (*DiscoverySuite) TestDiscoverAuthorizationURIUnexpectedStatusCode(c *gc.C) {
	sender := mocks.NewSender()
	resp := mocks.NewResponseWithStatus("", http.StatusNotFound)
	sender.AppendResponse(resp)

	client := subscriptions.NewClient()
	client.Sender = sender
	_, err := azureauth.DiscoverAuthorizationURI(client, "subscription_id")
	c.Assert(err, gc.ErrorMatches, "expected unauthorized error response, got 404: .*")
}
Exemple #2
0
func (*DiscoverySuite) TestDiscoverAuthorizationURIMissingHeader(c *gc.C) {
	sender := mocks.NewSender()
	resp := mocks.NewResponseWithStatus("", http.StatusUnauthorized)
	sender.AppendResponse(resp)

	client := subscriptions.NewClient()
	client.Sender = sender
	_, err := azureauth.DiscoverAuthorizationURI(client, "subscription_id")
	c.Assert(err, gc.ErrorMatches, `WWW-Authenticate header not found`)
}
Exemple #3
0
func (*DiscoverySuite) TestDiscoverAuthorizationURIHeaderMismatch(c *gc.C) {
	sender := mocks.NewSender()
	resp := mocks.NewResponseWithStatus("", http.StatusUnauthorized)
	mocks.SetResponseHeaderValues(resp, "WWW-Authenticate", []string{`foo bar baz`})
	sender.AppendResponse(resp)

	client := subscriptions.NewClient()
	client.Sender = sender
	_, err := azureauth.DiscoverAuthorizationURI(client, "subscription_id")
	c.Assert(err, gc.ErrorMatches, `authorization_uri not found in WWW-Authenticate header \("foo bar baz"\)`)
}
Exemple #4
0
func (*DiscoverySuite) TestDiscoverAuthorizationURI(c *gc.C) {
	sender := mocks.NewSender()
	resp := mocks.NewResponseWithStatus("", http.StatusUnauthorized)
	mocks.SetResponseHeaderValues(resp, "WWW-Authenticate", []string{
		`foo bar authorization_uri="https://testing.invalid/meep" baz`,
	})
	sender.AppendResponse(resp)

	client := subscriptions.NewClient()
	client.Sender = sender
	authURI, err := azureauth.DiscoverAuthorizationURI(client, "subscription_id")
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(authURI, jc.DeepEquals, &url.URL{
		Scheme: "https",
		Host:   "testing.invalid",
		Path:   "/meep",
	})
}