def test_consumer_should_reuse_existant_key(tmpdir): plain_dir = tmpdir.join('plain') hlsclient.consumer.consume(M3U8_SERVER + '/live/low.m3u8', str(plain_dir)) encrypted_dir = tmpdir.join('encrypted') new_key = crypto.create_key('low.bin') os.makedirs(str(encrypted_dir.join('live'))) crypto.save_new_key(new_key, str(encrypted_dir.join('live'))) hlsclient.consumer.consume(M3U8_SERVER + '/live/low.m3u8', str(encrypted_dir), True) plain = plain_dir.join('live').join('low1.ts').read() encrypted = encrypted_dir.join('live').join('low1.ts').read() m3u8_content = encrypted_dir.join('live').join('low.m3u8').read() assert encrypted_dir.join('live').join("low.bin").check() assert 'URI="low.bin"' in m3u8_content assert "#EXT-X-VERSION:2" in m3u8_content assert plain == crypto.decrypt(encrypted, new_key)
def test_save_new_key_should_create_iv_file_with_right_content(tmpdir): fake_key = crypto.get_key("fake_key.bin", str(tmpdir)) fake_key.iv.iv = "rsrs" crypto.save_new_key(fake_key, str(tmpdir)) assert 'rsrs' == tmpdir.join('fake_key.iv').read()
def test_key_generated_by_consumer_should_be_saved_on_right_path(tmpdir): fake_key = crypto.get_key("fake_key.bin", str(tmpdir)) crypto.save_new_key(fake_key, str(tmpdir)) assert tmpdir.join("fake_key.bin") in tmpdir.listdir() assert tmpdir.join("fake_key.iv") in tmpdir.listdir()