def test_get_http_auth_credentials_bad_response(mock): mock.headers = {} mock.url = '' with pytest.raises(DCOSException) as e: http._get_http_auth_credentials(mock) msg = ("Invalid HTTP response: server returned an HTTP 401 response " "with no 'www-authenticate' field") assert e.exconly().split(':', 1)[1].strip() == msg
def test_get_http_auth_credentials_not_supported(mock): mock.headers = {'www-authenticate': 'test'} mock.url = '' with pytest.raises(DCOSException) as e: http._get_http_auth_credentials(mock) msg = ("Server responded with an HTTP 'www-authenticate' field of " "'test', DCOS only supports 'Basic'") assert e.exconly().split(':')[1].strip() == msg
def test_get_http_auth_credentials_good_reponse(auth_mock): m = Mock() m.url = 'http://domain.com' m.headers = {'www-authenticate': 'Basic realm="Restricted"'} auth = HTTPBasicAuth("username", "password") auth_mock.return_value = auth returned_auth = http._get_http_auth_credentials(m) assert returned_auth == auth