Skip to content

Commit

Permalink
Merge pull request #72 from orsinium/add-ca-cert-in-cli
Browse files Browse the repository at this point in the history
Add CA cert in CLI and use responses
  • Loading branch information
traut committed Oct 10, 2019
2 parents 83c9090 + 5cb9b35 commit e973ac6
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 123 deletions.
3 changes: 3 additions & 0 deletions cabby/cli/commons.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ def get_basic_arg_parser():
type=int,
help="HTTP request timeout in seconds")

parser.add_argument(
"--ca-cert", dest="ca_cert", help="CA certificate file")
parser.add_argument("--cert", dest="cert", help="certificate file")
parser.add_argument("--key", dest="key", help="private key file")
parser.add_argument(
Expand Down Expand Up @@ -153,6 +155,7 @@ def run_client(parser, run_func):
verify_ssl = True

client.set_auth(
ca_cert=args.ca_cert,
cert_file=args.cert,
key_file=args.key,
username=args.username,
Expand Down
2 changes: 2 additions & 0 deletions cabby/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,8 @@ def obtain_jwt_token(session, jwt_url, username, password, timeout=None):
stream, headers = request_stream(
session, jwt_url, request_body, timeout, headers)
response_body = stream.read().decode('utf-8')
if not response_body:
raise ValueError("empty response")
response_data = json.loads(response_body)

if 'token' not in response_data:
Expand Down
7 changes: 0 additions & 7 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -1,7 +0,0 @@
[pytest]
addopts =
--verbose
--showlocals
--cov-config .coveragerc
--cov-report term-missing
--cov-report html
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-r requirements.txt
httpretty
responses
pytest
pytest-cov
pytest-pythonpath
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures10.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# flake8: noqa

HOST = 'example.com'
HOST = 'example.locahost'

DISCOVERY_PATH = '/some/discovery/path'
DISCOVERY_URI_HTTP = "http://%s%s" % (HOST, DISCOVERY_PATH)
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures11.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# flake8: noqa

HOST = 'example.com'
HOST = 'example.localhost'

DISCOVERY_PATH = '/some/discovery/path'
DISCOVERY_URI_HTTP = "http://%s%s" % (HOST, DISCOVERY_PATH)
Expand Down
41 changes: 22 additions & 19 deletions tests/test_client10.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@


import pytest
import httpretty
import responses

from libtaxii import messages_10 as tm10

Expand Down Expand Up @@ -30,16 +30,19 @@ def create_client_10(**kwargs):


def register_uri(uri, body, **kwargs):
httpretty.register_uri(
httpretty.POST, uri, body=body,
responses.add(
method=responses.POST,
url=uri,
body=body,
content_type='application/xml',
stream=True,
adding_headers={'X-TAXII-Content-Type': XML_10_BINDING},
**kwargs)


def get_sent_message():
body = httpretty.last_request().body
print(body)
body = responses.calls[-1].request.body
print(repr(body))
return tm10.get_message_from_xml(body)

# Tests
Expand All @@ -59,18 +62,18 @@ def test_no_discovery_path_when_pushing():
client.push(CONTENT, CONTENT_BINDING)


@httpretty.activate
@responses.activate
def test_incorrect_path():

httpretty.register_uri(httpretty.POST, DISCOVERY_URI_HTTP, status=404)
responses.add(responses.POST, DISCOVERY_URI_HTTP, status=404)

client = create_client_10(discovery_path=DISCOVERY_PATH)

with pytest.raises(exc.HTTPError):
client.discover_services()


@httpretty.activate
@responses.activate
def test_discovery():

register_uri(DISCOVERY_URI_HTTP, DISCOVERY_RESPONSE)
Expand All @@ -89,7 +92,7 @@ def test_discovery():
assert type(message) == tm10.DiscoveryRequest


@httpretty.activate
@responses.activate
def test_discovery_https():

register_uri(DISCOVERY_URI_HTTPS, DISCOVERY_RESPONSE)
Expand All @@ -104,7 +107,7 @@ def test_discovery_https():
assert type(message) == tm10.DiscoveryRequest


@httpretty.activate
@responses.activate
def test_collections():

register_uri(FEED_MANAGEMENT_URI, FEED_MANAGEMENT_RESPONSE)
Expand All @@ -130,7 +133,7 @@ def test_collections():
assert type(message) == tm10.FeedInformationRequest


@httpretty.activate
@responses.activate
def test_collections_with_automatic_discovery():

register_uri(DISCOVERY_URI_HTTP, DISCOVERY_RESPONSE)
Expand All @@ -146,7 +149,7 @@ def test_collections_with_automatic_discovery():
assert type(message) == tm10.FeedInformationRequest


@httpretty.activate
@responses.activate
def test_poll():

register_uri(POLL_URI, POLL_RESPONSE)
Expand All @@ -161,7 +164,7 @@ def test_poll():
assert message.feed_name == POLL_FEED


@httpretty.activate
@responses.activate
def test_poll_count_only():

register_uri(POLL_URI, POLL_RESPONSE)
Expand All @@ -172,7 +175,7 @@ def test_poll_count_only():
client.get_content_count(POLL_FEED, uri=POLL_PATH)


@httpretty.activate
@responses.activate
def test_poll_with_subscription():

register_uri(POLL_URI, POLL_RESPONSE)
Expand All @@ -190,7 +193,7 @@ def test_poll_with_subscription():
assert message.subscription_id == SUBSCRIPTION_ID


@httpretty.activate
@responses.activate
def test_poll_with_content_bindings():

register_uri(POLL_URI, POLL_RESPONSE)
Expand Down Expand Up @@ -227,7 +230,7 @@ def test_poll_with_content_bindings():
assert message.content_bindings[0] == binding.id


@httpretty.activate
@responses.activate
def test_subscribe():

register_uri(FEED_MANAGEMENT_URI, SUBSCRIPTION_RESPONSE)
Expand All @@ -248,7 +251,7 @@ def test_subscribe():
assert message.action == tm10.ACT_SUBSCRIBE


@httpretty.activate
@responses.activate
def test_subscribe_with_push():

register_uri(DISCOVERY_URI_HTTP, DISCOVERY_RESPONSE)
Expand Down Expand Up @@ -277,7 +280,7 @@ def test_subscribe_with_push():
assert message.action == tm10.ACT_SUBSCRIBE


@httpretty.activate
@responses.activate
def test_unsubscribe():

register_uri(FEED_MANAGEMENT_URI, SUBSCRIPTION_RESPONSE)
Expand All @@ -300,7 +303,7 @@ def test_unsubscribe():
assert message.action == tm10.ACT_UNSUBSCRIBE


@httpretty.activate
@responses.activate
def test_push():

register_uri(INBOX_URI, INBOX_RESPONSE)
Expand Down
Loading

0 comments on commit e973ac6

Please sign in to comment.