def test_get_http_auth_bad_response(mock): mock.headers = {} mock.url = '' with pytest.raises(DCOSException) as e: http._get_http_auth(mock, url=urlparse(''), auth_scheme='') 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_not_supported(mock): mock.headers = {'www-authenticate': 'test'} mock.url = '' with pytest.raises(DCOSException) as e: http._get_http_auth(mock, url=urlparse(''), auth_scheme='foo') 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_acl(auth_mock): m = Mock() m.url = 'http://domain.com' m.headers = {'www-authenticate': 'acsjwt"'} auth_mock.return_value = ("username", "password") returned_auth = http._get_http_auth(m, urlparse(m.url), "acsjwt") assert type(returned_auth) == http.DCOSAcsAuth
def test_get_http_auth_credentials_acl(req_mock, auth_mock): m = Mock() m.url = 'http://domain.com' m.headers = {'www-authenticate': 'acsjwt"'} auth_mock.return_value = ("username", "password") req_mock.status_code = 404 returned_auth = http._get_http_auth(m, urlparse(m.url), "acsjwt") assert type(returned_auth) == http.DCOSAcsAuth
def test_get_http_auth_credentials_basic(auth_mock): m = Mock() m.url = 'http://domain.com' m.headers = {'www-authenticate': 'Basic realm="Restricted"'} auth_mock.return_value = ("username", "password") returned_auth = http._get_http_auth(m, urlparse(m.url), "basic") assert type(returned_auth) == HTTPBasicAuth assert returned_auth.username == "username" assert returned_auth.password == "password"
def test_get_http_auth_credentials_basic(auth_mock): m = Mock() m.url = 'http://domain.com' m.headers = {'www-authenticate': 'Basic realm="Restricted"'} auth_mock.return_value = ("username", "password") returned_auth = http._get_http_auth(m, urlparse(m.url), "basic") assert type(returned_auth) == HTTPBasicAuth assert returned_auth.username == "username" assert returned_auth.password == "password"