Skip to content

Commit

Permalink
mwdeploy: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Universal-Omega authored Sep 12, 2024
1 parent dc54eb4 commit d96227a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
21 changes: 19 additions & 2 deletions modules/mediawiki/files/bin/mwdeploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,24 @@ def non_zero_code(ec: list[int], nolog: bool = True, leave: bool = True) -> bool
return False


def check_up(nolog: bool, Debug: str | None = None, Host: str | None = None, domain: str = 'meta.miraheze.org', verify: bool = True, force: bool = False, port: int = 443) -> bool:
def check_up(nolog: bool, Debug: str | None = None, Host: str | None = None, domain: str = 'meta.miraheze.org', verify: bool = True, force: bool = False, port: int = 443, use_cert: bool = True) -> bool:

def make_request(proto, domain, headers) -> requests.Response:
url = f'{proto}{domain}:{port}/w/api.php?action=query&meta=siteinfo&formatversion=2&format=json'

kwargs = {
'headers': headers,
'verify': verify,
}

if use_cert:
kwargs['cert'] = (
'/etc/ssl/localcerts/mwdeploy.crt',
'/srv/mediawiki-staging/mwdeploy-client-cert.key',
)

return requests.get(url, **kwargs)

if verify is False:
os.environ['PYTHONWARNINGS'] = 'ignore:Unverified HTTPS request'
if not Debug and not Host:
Expand Down Expand Up @@ -217,7 +234,7 @@ def check_up(nolog: bool, Debug: str | None = None, Host: str | None = None, dom
proto = 'https://'
else:
proto = 'http://'
req = requests.get(f'{proto}{domain}:{port}/w/api.php?action=query&meta=siteinfo&formatversion=2&format=json', headers=headers, verify=verify, cert=('/etc/ssl/localcerts/mwdeploy.crt', '/srv/mediawiki-staging/mwdeploy-client-cert.key'))
req = make_request(proto, domain, headers)
if req.status_code == 200 and 'miraheze' in req.text and (Debug is None or Debug in req.headers['X-Served-By']):
up = True
if not up:
Expand Down
4 changes: 2 additions & 2 deletions modules/mediawiki/files/bin/test_mwdeploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,11 @@ def test_check_up_no_debug_host() -> None:

def test_check_up_debug() -> None:
if os.getenv('DEBUG_ACCESS_KEY'):
assert mwdeploy.check_up(nolog=True, Debug='mwtask181')
assert mwdeploy.check_up(nolog=True, Debug='mwtask181', use_cert=False)


def test_check_up_debug_fail() -> None:
assert not mwdeploy.check_up(nolog=True, Debug='mwtask181', domain='httpstat.us/500', force=True)
assert not mwdeploy.check_up(nolog=True, Debug='mwtask181', domain='httpstat.us/500', force=True, use_cert=False)


def test_get_staging_path() -> None:
Expand Down

0 comments on commit d96227a

Please sign in to comment.