Skip to content

Commit

Permalink
add GelfHttpsHandler tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chilledornaments committed Aug 18, 2020
1 parent e4f97bd commit e6eb91d
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 5 deletions.
19 changes: 19 additions & 0 deletions tests/config/bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,29 @@ TLS_INPUT='{
"global": true
}'

HTTPS_INPUT='{
"title": "https",
"configuration": {
"bind_address": "0.0.0.0",
"port": 12205,
"tls_cert_file": "/usr/share/graylog/data/cert.pem",
"tls_client_auth": "disabled",
"tls_client_auth_cert_file": "",
"tls_enable": true,
"tls_key_file": "/usr/share/graylog/data/key.pem",
"tls_key_password": "secret"
},
"type": "org.graylog2.inputs.gelf.http.GELFHttpInput",
"global": true
}'

curl -u admin:admin "$API_URL/search/universal/relative?query=test&range=5&fields=message" > /dev/null

curl -u admin:admin -X "POST" -H "Content-Type: application/json" -H "X-Requested-By: cli" -d "${TCP_INPUT}" "$INPUTS_URL"
curl -u admin:admin -X "POST" -H "Content-Type: application/json" -H "X-Requested-By: cli" -d "${UDP_INPUT}" "$INPUTS_URL"
curl -u admin:admin -X "POST" -H "Content-Type: application/json" -H "X-Requested-By: cli" -d "${HTTP_INPUT}" "$INPUTS_URL"
curl -u admin:admin -X "POST" -H "Content-Type: application/json" -H "X-Requested-By: cli" -d "${TLS_INPUT}" "$INPUTS_URL"
curl -u admin:admin -X "POST" -H "Content-Type: application/json" -H "X-Requested-By: cli" -d "${HTTPS_INPUT}" "$INPUTS_URL"

sleep 10

Expand All @@ -61,4 +78,6 @@ sleep 10
for _ in {1..5}; do
curl -X "POST" -H "Content-Type: application/json" "http://localhost:12203/gelf" -p0 -d '{"short_message": "warm-up", "host": "localhost"}'
sleep 1
curl -k -X "POST" -H "Content-Type: application/json" "https://localhost:12205/gelf" -p0 -d '{"short_message": "warm-up", "host": "localhost"}'
sleep 1
done
1 change: 1 addition & 0 deletions tests/config/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ services:
- "12202:12202/udp"
- "12203:12203"
- "12204:12204/tcp"
- "12205:12205/tcp"
3 changes: 2 additions & 1 deletion tests/test_common_fields.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import socket
import pytest
import mock
from pygelf import GelfTcpHandler, GelfUdpHandler, GelfHttpHandler, GelfTlsHandler
from pygelf import GelfTcpHandler, GelfUdpHandler, GelfHttpHandler, GelfTlsHandler, GelfHttpsHandler
from tests.helper import logger, get_unique_message, log_warning, log_exception


Expand All @@ -16,6 +16,7 @@
GelfHttpHandler(host='127.0.0.1', port=12203),
GelfHttpHandler(host='127.0.0.1', port=12203, compress=False),
GelfTlsHandler(host='127.0.0.1', port=12204),
GelfHttpsHandler(host='127.0.0.1', port=12205, validate=False),
# GelfTlsHandler(host='127.0.0.1', port=12204, validate=True, ca_certs='tests/config/cert.pem'),
])
def handler(request):
Expand Down
3 changes: 2 additions & 1 deletion tests/test_dynamic_fields.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
import pytest
from pygelf import GelfTcpHandler, GelfUdpHandler, GelfHttpHandler, GelfTlsHandler
from pygelf import GelfTcpHandler, GelfUdpHandler, GelfHttpHandler, GelfTlsHandler, GelfHttpsHandler
from tests.helper import get_unique_message, log_warning


Expand All @@ -19,6 +19,7 @@ def filter(self, record):
GelfHttpHandler(host='127.0.0.1', port=12203, include_extra_fields=True),
GelfHttpHandler(host='127.0.0.1', port=12203, compress=False, include_extra_fields=True),
GelfTlsHandler(host='127.0.0.1', port=12204, include_extra_fields=True),
GelfHttpsHandler(host='127.0.0.1', port=12205, validate=False, include_extra_fields=True),
# GelfTlsHandler(host='127.0.0.1', port=12204, validate=True, ca_certs='tests/config/cert.pem', include_extra_fields=True),
])
def handler(request):
Expand Down
7 changes: 6 additions & 1 deletion tests/test_handler_specific.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from pygelf import GelfTlsHandler
from pygelf import GelfTlsHandler, GelfHttpsHandler


def test_tls_handler_init():
Expand All @@ -8,3 +8,8 @@ def test_tls_handler_init():

with pytest.raises(ValueError):
GelfTlsHandler(host='127.0.0.1', port=12204, keyfile='/dev/null')


def test_https_handler_init():
with pytest.raises(ValueError):
GelfHttpsHandler(host='127.0.0.1', port=12205, validate=True)
4 changes: 3 additions & 1 deletion tests/test_queuehandler_support.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
import pytest
import mock
from pygelf import GelfTcpHandler, GelfUdpHandler, GelfHttpHandler, GelfTlsHandler
from pygelf import GelfTcpHandler, GelfUdpHandler, GelfHttpHandler, GelfTlsHandler, GelfHttpsHandler
from tests.helper import logger, get_unique_message, log_exception


Expand All @@ -12,7 +12,9 @@
GelfHttpHandler(host='127.0.0.1', port=12203),
GelfHttpHandler(host='127.0.0.1', port=12203, compress=False),
GelfTlsHandler(host='127.0.0.1', port=12204),
GelfHttpsHandler(host='127.0.0.1', port=12205, validate=False),
# GelfTlsHandler(host='127.0.0.1', port=12204, validate=True, ca_certs='tests/config/cert.pem'),
# GelfHttpsHandler(host='127.0.0.1', port=12205, validate=True, ca_certs='tests/config/cert.pem')
])
def handler(request):
return request.param
Expand Down
3 changes: 2 additions & 1 deletion tests/test_static_fields.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from pygelf import GelfTcpHandler, GelfUdpHandler, GelfHttpHandler, GelfTlsHandler
from pygelf import GelfTcpHandler, GelfUdpHandler, GelfHttpHandler, GelfTlsHandler, GelfHttpsHandler
from tests.helper import logger, get_unique_message, log_warning


Expand All @@ -24,6 +24,7 @@
GelfHttpHandler(host='127.0.0.1', port=12203, static_fields=STATIC_FIELDS, _ozzy='billie jean'),
GelfHttpHandler(host='127.0.0.1', port=12203, compress=False, static_fields=STATIC_FIELDS, _ozzy='billie jean'),
GelfTlsHandler(host='127.0.0.1', port=12204, static_fields=STATIC_FIELDS),
GelfHttpsHandler(host='127.0.0.1', port=12205, validate=False, static_fields=STATIC_FIELDS, _ozzy='billie jean')
# GelfTlsHandler(host='127.0.0.1', port=12204, validate=True, ca_certs='tests/config/cert.pem', static_fields=STATIC_FIELDS, _ozzy='billie jean'),
])
def handler(request):
Expand Down

0 comments on commit e6eb91d

Please sign in to comment.