Esempio n. 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: .*")
}
Esempio n. 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`)
}
Esempio n. 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"\)`)
}
Esempio n. 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",
	})
}