Skip to content

Commit

Permalink
Add createHttpServer test
Browse files Browse the repository at this point in the history
  • Loading branch information
kentbull committed Sep 11, 2023
1 parent ecb4fbc commit 267b1e2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/keria/app/agenting.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def setup(name, bran, adminPort, bootPort, base='', httpPort=None, configFile=No
return doers


def createHttpServer(port, app, keypath, certpath, cafilepath):
def createHttpServer(port, app, keypath=None, certpath=None, cafilepath=None):
"""
Create an HTTP or HTTPS server depending on whether TLS key material is present
Expand Down
28 changes: 28 additions & 0 deletions tests/app/test_agenting.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
import shutil

import falcon
import hio
from falcon import testing
from hio.base import doing
from hio.core import http, tcp
from hio.help import decking
from keri import kering
from keri.app import habbing, configing, oobiing
Expand Down Expand Up @@ -347,3 +349,29 @@ def test_oobi_ends(seeder, helpers):
assert result.json == {'oobis': ['http://127.0.0.1:3902/oobi/EHgwVwQT15OJvilVvW57HE4w0-GPs_Stj2OFoAHZSysY/agent'
'/EI7AkI40M11MS7lkTCb10JC9-nDt-tXwQh44OHAFlv_9'],
'role': 'agent'}


class MockServerTls:
def __init__(self, certify, keypath, certpath, cafilepath, port):
pass


class MockHttpServer:
def __init__(self, port, app, servant=None):
self.servant = servant


def test_createHttpServer(monkeypatch):
port = 5632
app = falcon.App()
server = agenting.createHttpServer(port, app)
assert isinstance(server, http.Server)

monkeypatch.setattr(hio.core.tcp, 'ServerTls', MockServerTls)
monkeypatch.setattr(hio.core.http, 'Server', MockHttpServer)

server = agenting.createHttpServer(port, app, keypath='keypath', certpath='certpath',
cafilepath='cafilepath')

assert isinstance(server, MockHttpServer)
assert isinstance(server.servant, MockServerTls)

0 comments on commit 267b1e2

Please sign in to comment.