Skip to content
This repository has been archived by the owner on Aug 1, 2023. It is now read-only.

[WIP] Test for dock-pulp with invalid user certificate #213

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion dockpulp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
from six.moves.urllib.parse import urlparse
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.util.retry import Retry
from OpenSSL.SSL import Error as OpenSSLError
from operator import itemgetter
import multiprocessing

Expand Down Expand Up @@ -158,7 +159,7 @@ def __call__(self, meth, api, **kwargs):
warnings.simplefilter("ignore")
answer = c(url, **kwargs)

except requests.exceptions.SSLError:
except (OpenSSLError, requests.exceptions.SSLError):
if not self.verify:
raise errors.DockPulpLoginError(
'Expired or bad certificate, please re-login')
Expand Down
1 change: 1 addition & 0 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ responses
requests
flexmock
simplejson
pyOpenSSL
38 changes: 32 additions & 6 deletions tests/test_pulp_instance.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

from copy import deepcopy
from datetime import datetime
from dockpulp import Pulp, Crane, RequestsHttpCaller, errors, log
import pytest
import hashlib
import json
import requests
import tarfile
import logging
import subprocess
import tarfile
from copy import deepcopy
from datetime import datetime
from tempfile import NamedTemporaryFile
from textwrap import dedent

import pytest
import requests
from OpenSSL.SSL import Error as OpenSSLError
from flexmock import flexmock
from requests.packages.urllib3.util import Retry

from dockpulp import Pulp, Crane, RequestsHttpCaller, errors, log

log.setLevel(logging.CRITICAL)


Expand Down Expand Up @@ -310,6 +314,28 @@ def test_set_certs(self, pulp, cert, key):
assert pulp.certificate == cert
assert pulp.key == key

@pytest.mark.parametrize('tid, url', [
('111', '/pulp/api/v2/tasks/111/')])
def test_invalid_cert(self, pulp, tid, url):
flexmock(requests.Session)
(requests.Session.should_receive('get').once().and_raise(OpenSSLError))
with pytest.raises(errors.DockPulpLoginError):
pulp.getTask(tid)

@pytest.mark.parametrize('tid, url', [
('111', '/pulp/api/v2/tasks/111/')
])
def test_always_valid_cert(self, pulp, tid, url):
class Answer:
def __init__(self):
self.ok = True
self.json = (lambda: None)
self.status_code = 200

flexmock(requests.Session)
(requests.Session.should_receive('get').once().and_return(Answer()))
pulp.getTask(tid)

@pytest.mark.parametrize('tid, url', [
('111', '/pulp/api/v2/tasks/111/')
])
Expand Down