All checks were successful
Build and deploy / Validate source (push) Successful in 11s
Build and deploy / Integration suite on a real stack (push) Successful in 5m44s
Build and deploy / Secret scan and release gate (push) Successful in 6s
Build and deploy / Publish images (push) Successful in 1m22s
75 lines
3.4 KiB
Python
75 lines
3.4 KiB
Python
"""Published site videos retain their file and expose same-origin captions.
|
|
|
|
Run against the local stack with an internal S3 public endpoint:
|
|
SITE_BASE_URL=http://site SITE_HOST_HEADER=localhost python -m tests.site_video_test
|
|
"""
|
|
from urllib.request import Request, urlopen
|
|
|
|
from app.core import db
|
|
from app.runtime import storage
|
|
from tests.smoke_test import BASE, Client, with_host, wait_scan
|
|
|
|
|
|
VIDEO = b'\x00\x00\x00\x18ftypisom\x00\x00\x00\x00isomiso2'
|
|
CAPTIONS = b'WEBVTT\n\n00:00:00.000 --> 00:00:01.000\nTeste de legenda.\n'
|
|
|
|
|
|
def upload(operator, name, content):
|
|
start = operator.call('/operator/site-videos/uploads', {'name': name, 'size': len(content)})
|
|
uid = start['id']
|
|
url = operator.call(f'/operator/uploads/{uid}/parts/1', {})['url']
|
|
with urlopen(Request(url, data=content, method='PUT'), timeout=30) as response:
|
|
assert response.status == 200
|
|
operator.call(f'/operator/uploads/{uid}/complete', {})
|
|
wait_scan(operator, uid, operator=True)
|
|
return uid
|
|
|
|
|
|
def run():
|
|
client = Client()
|
|
client.call('/session')
|
|
with db.connect() as c:
|
|
assert not c.execute("SELECT 1 FROM dtf_local.site_videos WHERE id='sala'").fetchone(), \
|
|
'The isolated test catalog entry is already configured'
|
|
ids = []
|
|
keys = []
|
|
try:
|
|
client.call('/operator/site-videos/sala', {'enabled': True}, expected=401)
|
|
operator = client.operator_client or Client()
|
|
# Client.call(operator=True) signs in and forwards to its own client.
|
|
client.call('/operator/site-videos', operator=True)
|
|
operator = client.operator_client
|
|
video = upload(operator, 'LOCAL-VIDEO.mp4', VIDEO)
|
|
captions = upload(operator, 'LOCAL-VIDEO.vtt', CAPTIONS)
|
|
ids = [video, captions]
|
|
operator.call('/operator/site-videos/sala', {'upload_id': video,
|
|
'captions_id': captions, 'product': 'file', 'enabled': True})
|
|
published = client.call('/site/videos')['videos']
|
|
entry = next(row for row in published if row['id'] == 'sala')
|
|
assert entry['product'] == 'file'
|
|
assert entry['captions'] == '/api/site/videos/sala/captions'
|
|
with urlopen(entry['src'], timeout=30) as response:
|
|
assert response.read() == VIDEO
|
|
with urlopen(Request(BASE + entry['captions'], headers=with_host()), timeout=30) as response:
|
|
assert response.headers['Content-Type'].startswith('text/vtt')
|
|
assert response.read() == CAPTIONS
|
|
operator.call('/operator/site-videos/sala', {'upload_id': video,
|
|
'captions_id': captions, 'product': 'file', 'enabled': False})
|
|
assert not any(row['id'] == 'sala' for row in client.call('/site/videos')['videos'])
|
|
print('PASS: Gestão publishes a scanned video, signed media and same-origin VTT; hiding removes it from the Site')
|
|
finally:
|
|
with db.connect() as c:
|
|
row = c.execute("DELETE FROM dtf_local.site_videos WHERE id='sala' RETURNING video_key,captions_key").fetchone()
|
|
if row:
|
|
keys.extend(key for key in row.values() if key)
|
|
if ids:
|
|
sources = c.execute('DELETE FROM dtf_local.uploads WHERE id=ANY(%s) RETURNING object_key',
|
|
(ids,)).fetchall()
|
|
keys.extend(row['object_key'] for row in sources)
|
|
for key in keys:
|
|
storage.client.delete_object(Bucket=storage.bucket, Key=key)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
run()
|