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

Commit

Permalink
[WIP] test_pulp: Test for dock-pulp with invalid user certificate
Browse files Browse the repository at this point in the history
If user provides invalid certificate, dock-pulp fails with traceback.
This change fixes this behaviour and adds tests for such scenario.

Signed-off-by: Katarina Bulkova <[email protected]>
  • Loading branch information
Katarina Bulkova committed Apr 30, 2021
1 parent 3b7e96f commit cd7cdb6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
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
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

0 comments on commit cd7cdb6

Please sign in to comment.