system-config/testinfra/test_paste.py
Clark Boylan 32eae01bda Capture lodgeit captchas for verification purposes
This will help us verify the captchas render properly. This has been an
issue with the image library changing APIs.

Depends-On: https://review.opendev.org/c/opendev/lodgeit/+/935712/
Change-Id: I847bbb23776e89b8a74bfd25e6e790cbdae4eda6
2024-11-26 14:43:29 -08:00

70 lines
2.4 KiB
Python

# Copyright 2020 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import requests
from util import take_screenshots
testinfra_hosts = ['paste99.opendev.org']
def test_lodgeit_container_web_listening(host):
paste_http = host.socket("tcp://127.0.0.1:80")
assert paste_http.is_listening
paste_https = host.socket("tcp://127.0.0.1:443")
assert paste_https.is_listening
def test_paste(host):
cmd = host.run('curl https://paste99.opendev.org')
assert 'New Paste' in cmd.stdout
# ensure we paste private by default
assert '<input type="checkbox" name="private" id="private" checked>' \
in cmd.stdout
def test_paste_redirects(host):
# http site should redirect all agents but Pastebinit
r = requests.get('http://paste99.opendev.org', allow_redirects=False)
assert r.status_code == 301
assert r.headers['Location'] == 'https://paste.opendev.org/'
headers = {
'User-Agent': 'Pastebinit v1.2.3'
}
r = requests.get('http://paste99.opendev.org')
assert r.status_code == 200
def test_paste_logo(host):
cmd = host.run('curl https://paste99.opendev.org/assets/opendev.svg')
assert 'image/svg+xml' in cmd.stdout
def test_paste_robots(host):
cmd = host.run('curl https://paste99.opendev.org/robots.txt')
assert 'Disallow: /' in cmd.stdout
def test_paste_screenshots(host):
shots = (
('https://localhost', None, 'paste-main-page.png'),
)
take_screenshots(host, shots)
# Selenium doesn't handle screenshots of pngs, but that is fine we can
# just download and save the png directly into the screenshots dir.
# We disable ssl verification because we're connecting via bridge and
# it doesn't trust the cert.
r = requests.get('https://paste99.opendev.org/_captcha.png', verify=False)
with open('/var/log/screenshots/paste-captcha.png', 'wb') as f:
f.write(r.content)