Skip to content
This repository was archived by the owner on Oct 15, 2021. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions amo2kinto/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def write_addons_items(xml_tree, records, app_id, api_ver=3):
emItem.set('id', item['guid'])

for field in ['name', 'os']:
if field in item:
if field in item and item[field]:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these dicts? Can you use get?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I guess I can. I don't know why the functional test if failling though.

emItem.set(field, item[field])

build_version_range(emItem, item, app_id)
Expand Down Expand Up @@ -172,17 +172,17 @@ def add_plugin_item(pluginItems, item, version, tA=None, app_id=None,
blockID=item.get('blockID', item['id']))

for field in ['name', 'os', 'xpcomabi']:
if field in item:
if field in item and item[field]:
entry.set(field, item[field])

for xml_field in ['name', 'filename', 'description']:
json_field = 'match%s' % xml_field.capitalize()
if json_field in item:
if json_field in item and item[json_field]:
etree.SubElement(entry, 'match',
name=xml_field,
exp=item[json_field])

if 'infoURL' in item:
if 'infoURL' in item and item['infoURL']:
infoURL = etree.SubElement(entry, 'infoURL')
infoURL.text = item['infoURL']

Expand Down Expand Up @@ -285,7 +285,7 @@ def write_gfx_items(xml_tree, records, app_id, api_ver=3):
fields = ['os', 'vendor', 'feature', 'featureStatus',
'driverVersion', 'driverVersionComparator']
for field in fields:
if field in item:
if field in item and item[field]:
node = etree.SubElement(entry, field)
node.text = item[field]

Expand Down
105 changes: 91 additions & 14 deletions amo2kinto/tests/test_exporter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import mock
import unittest
from copy import deepcopy
from lxml import etree
from six import StringIO

Expand Down Expand Up @@ -85,14 +86,53 @@ def test_addon_record():
""".decode('utf-8')


def test_addons_record_with_empty_name_and_os():
xml_tree = etree.Element(
'blocklist',
xmlns="http://www.mozilla.org/2006/addons-blocklist",
lastupdate='1459262434336'
)

data = deepcopy(ADDONS_DATA)
data['name'] = ''
data['os'] = ''

exporter.write_addons_items(xml_tree, [data],
constants.FIREFOX_APPID)
result = etree.tostring(
etree.ElementTree(xml_tree),
pretty_print=True,
xml_declaration=True,
encoding='UTF-8').decode('utf-8')

assert result == b"""<?xml version='1.0' encoding='UTF-8'?>
<blocklist lastupdate="1459262434336" \
xmlns="http://www.mozilla.org/2006/addons-blocklist">
<emItems>
<emItem blockID="i454" id="sqlmoz@facebook.com">
<prefs>
<pref>test.blocklist</pref>
</prefs>
<versionRange minVersion="0" maxVersion="*" severity="3">
<targetApplication id="{ec8030f7-c20a-464f-9b0e-13a3a9e97384}">
<versionRange maxVersion="3.6.*" minVersion="3.6"/>
</targetApplication>
</versionRange>
<versionRange minVersion="0" maxVersion="*"/>
</emItem>
</emItems>
</blocklist>
""".decode('utf-8')


def test_addon_record_with_no_version_range_info():
xml_tree = etree.Element(
'blocklist',
xmlns="http://www.mozilla.org/2006/addons-blocklist",
lastupdate='1459262434336'
)

data = ADDONS_DATA.copy()
data = deepcopy(ADDONS_DATA)
data['versionRange'] = []

exporter.write_addons_items(xml_tree, [data],
Expand Down Expand Up @@ -125,7 +165,7 @@ def test_addon_record_with_no_targetApplication_info():
lastupdate='1459262434336'
)

data = ADDONS_DATA.copy()
data = deepcopy(ADDONS_DATA)
data['name'] = "Mozilla Service Pack (malware)"
data['os'] = "WINNT"
data['versionRange'] = [{
Expand Down Expand Up @@ -167,7 +207,7 @@ def test_addon_record_with_no_targetApplication_matching():
lastupdate='1459262434336'
)

data = ADDONS_DATA.copy()
data = deepcopy(ADDONS_DATA)
data['versionRange'] = [{
"targetApplication": [
{"guid": "{some-other-application}",
Expand Down Expand Up @@ -203,7 +243,7 @@ def test_addon_record_group_by_blockID():
lastupdate='1459262434336'
)

data = ADDONS_DATA.copy()
data = deepcopy(ADDONS_DATA)
data['versionRange'] = [{
"targetApplication": [
{"guid": constants.FIREFOX_APPID,
Expand All @@ -215,7 +255,7 @@ def test_addon_record_group_by_blockID():
"severity": 3
}]

data2 = ADDONS_DATA.copy()
data2 = deepcopy(ADDONS_DATA)
data2['blockID'] = 'i586'
data2['versionRange'] = [{
"targetApplication": [
Expand Down Expand Up @@ -334,6 +374,43 @@ def test_plugin_record():
""".decode('utf-8')


def test_plugin_record_with_empty_name_description_os_and_filename():
xml_tree = etree.Element(
'blocklist',
xmlns="http://www.mozilla.org/2006/addons-blocklist",
lastupdate='1459262434336'
)

data = deepcopy(PLUGIN_DATA)
data['matchName'] = ''
data['matchFilename'] = ''
data['matchDescription'] = ''
data['os'] = ''
data['infoURL'] = ''

exporter.write_plugin_items(xml_tree, [data],
constants.FIREFOX_APPID,
api_ver=2)

result = etree.tostring(
etree.ElementTree(xml_tree),
pretty_print=True,
xml_declaration=True,
encoding='UTF-8').decode('utf-8')

assert result == b"""<?xml version='1.0' encoding='UTF-8'?>
<blocklist lastupdate="1459262434336" \
xmlns="http://www.mozilla.org/2006/addons-blocklist">
<pluginItems>
<pluginItem blockID="p26">
<versionRange maxVersion="4.1.10328.0" minVersion="0" severity="0" \
vulnerabilitystatus="1"/>
</pluginItem>
</pluginItems>
</blocklist>
""".decode('utf-8')


def test_plugin_record_with_api_version_2():
xml_tree = etree.Element(
'blocklist',
Expand Down Expand Up @@ -375,7 +452,7 @@ def test_plugin_record_with_api_version_2_with_no_guid():
lastupdate='1459262434336'
)

data = PLUGIN_DATA.copy()
data = deepcopy(PLUGIN_DATA)
data['versionRange'] = [{
"targetApplication": [],
"minVersion": "0",
Expand Down Expand Up @@ -417,7 +494,7 @@ def test_plugin_record_with_api_version_2_with_no_guid_and_no_vulnerability():
lastupdate='1459262434336'
)

data = PLUGIN_DATA.copy()
data = deepcopy(PLUGIN_DATA)
data['versionRange'] = [{
"targetApplication": [],
"minVersion": "0",
Expand Down Expand Up @@ -457,7 +534,7 @@ def test_plugin_record_with_api_version_2_with_no_guid_and_severity_only():
lastupdate='1459262434336'
)

data = PLUGIN_DATA.copy()
data = deepcopy(PLUGIN_DATA)
data['versionRange'] = [{
"targetApplication": [],
"severity": 1
Expand Down Expand Up @@ -496,7 +573,7 @@ def test_plugin_record_with_api_version_2_with_no_guid_and_severity_0():
lastupdate='1459262434336'
)

data = PLUGIN_DATA.copy()
data = deepcopy(PLUGIN_DATA)
data['versionRange'] = [{
"targetApplication": [],
"severity": 0
Expand Down Expand Up @@ -535,7 +612,7 @@ def test_plugin_record_with_api_version_2_with_guid_and_no_min_max_version():
lastupdate='1459262434336'
)

data = PLUGIN_DATA.copy()
data = deepcopy(PLUGIN_DATA)
data['versionRange'] = [{
"targetApplication": [
{"guid": constants.FIREFOX_APPID,
Expand Down Expand Up @@ -579,7 +656,7 @@ def test_plugin_record_with_api_version_2_with_guid_and_empty_versionRange():
lastupdate='1459262434336'
)

data = PLUGIN_DATA.copy()
data = deepcopy(PLUGIN_DATA)
data['versionRange'] = [{
"targetApplication": [
{"guid": constants.FIREFOX_APPID,
Expand Down Expand Up @@ -621,7 +698,7 @@ def test_plugin_record_with_api_version_2_with_related_version():
lastupdate='1459262434336'
)

data = PLUGIN_DATA.copy()
data = deepcopy(PLUGIN_DATA)
data['versionRange'] = [{
"targetApplication": [
{"guid": constants.FIREFOX_APPID,
Expand Down Expand Up @@ -665,7 +742,7 @@ def test_plugin_record_with_no_targetApplication_info():
lastupdate='1459262434336'
)

data = PLUGIN_DATA.copy()
data = deepcopy(PLUGIN_DATA)
data['name'] = "Yahoo Application State Plugin"
data['os'] = "WINNT"
data['xpcomabi'] = "test"
Expand Down Expand Up @@ -711,7 +788,7 @@ def test_plugin_record_with_no_targetApplication_matching():
lastupdate='1459262434336'
)

data = PLUGIN_DATA.copy()
data = deepcopy(PLUGIN_DATA)
data['versionRange'] = [{
"targetApplication": [
{"guid": "{some-other-application}",
Expand Down