1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
"""
System tests for authentication functionality
"""
import pytest
from jenkinsapi.utils.requester import Requester
from requests import HTTPError as REQHTTPError
from jenkinsapi.jenkins import Jenkins
def test_normal_authentication(jenkins_admin_admin):
# No problem with the righ user/pass
jenkins_user = Jenkins(
jenkins_admin_admin.baseurl,
jenkins_admin_admin.username,
jenkins_admin_admin.password,
)
assert jenkins_user is not None
# We cannot connect if no user/pass
with pytest.raises(REQHTTPError) as http_excep:
Jenkins(jenkins_admin_admin.baseurl)
assert Requester.AUTH_COOKIE is None
assert http_excep.value.response.status_code == 403
# def test_auth_cookie(jenkins_admin_admin):
# initial_cookie_value = None
# final_cookie_value = "JSESSIONID"
# assert initial_cookie_value == Requester.AUTH_COOKIE
#
# jenkins_admin_admin.use_auth_cookie()
#
# result = Requester.AUTH_COOKIE
# assert result is not None
# assert final_cookie_value in result
#
#
# def test_wrongauth_cookie(jenkins_admin_admin):
# initial_cookie_value = None
# assert initial_cookie_value == Requester.AUTH_COOKIE
#
# jenkins_admin_admin.username = "fakeuser"
# jenkins_admin_admin.password = "fakepass"
#
# with pytest.raises(HTTPError) as http_excep:
# jenkins_admin_admin.use_auth_cookie()
#
# assert Requester.AUTH_COOKIE is None
# assert http_excep.value.code == 401
#
#
# def test_verify_cookie_isworking(jenkins_admin_admin):
# initial_cookie_value = None
# final_cookie_value = "JSESSIONID"
# assert initial_cookie_value == Requester.AUTH_COOKIE
#
# # Remove requester user/pass
# jenkins_admin_admin.requester.username = None
# jenkins_admin_admin.requester.password = None
#
# # Verify that we cannot connect
# with pytest.raises(REQHTTPError) as http_excep:
# jenkins_admin_admin.poll()
#
# assert Requester.AUTH_COOKIE is None
# assert http_excep.value.response.status_code == 403
#
# # Retrieve the auth cookie, we can because we
# # have right values for jenkins_admin_admin.username
# # and jenkins_admin_admin.password
# jenkins_admin_admin.use_auth_cookie()
#
# result = Requester.AUTH_COOKIE
# assert result is not None
# assert final_cookie_value in result
#
# # Verify that we can connect even with no requester user/pass
# # If we have the cookie the requester user/pass is not needed
# jenkins_admin_admin.poll()
|