update tests to be sorted

This commit is contained in:
erev0s 2024-06-02 22:45:38 +03:00
parent f3fd19e761
commit 26aaa01ecb
2 changed files with 36 additions and 60 deletions

View File

@ -1014,7 +1014,7 @@ class APK:
tags = set()
tags.update(xml.findall(".//" + tag_name))
# Sample 4c7d2912ba24e4bf1dab1175ee435f85ec223ac86967fc61a3dacbd1a97ee329
# https://github.com/androguard/androguard/pull/1053
# permission declared using tag <android:uses-permission...
tags.update(xml.findall(".//" + NS_ANDROID + tag_name))
return [

View File

@ -366,6 +366,8 @@ class APKTest(unittest.TestCase):
self.assertTrue(isinstance(activities[0], str), 'activities[0] is not of type str')
def testAPKIntentFilters(self):
from androguard.util import set_log
set_log("ERROR")
a = APK(os.path.join(test_dir, 'data/APK/a2dp.Vol_137.apk'), testzip=True)
activities = a.get_activities()
receivers = a.get_receivers()
@ -375,34 +377,26 @@ class APKTest(unittest.TestCase):
filters = a.get_intent_filters("activity", i)
if len(filters) > 0:
filter_list.append(filters)
self.assertEqual([{'action': ['android.intent.action.MAIN'], 'category': ['android.intent.category.LAUNCHER']}],
filter_list)
filter_list = []
for i in receivers:
filters = a.get_intent_filters("receiver", i)
if len(filters) > 0:
filter_list.append(filters)
for expected in [{
'action': ['android.intent.action.BOOT_COMPLETED', 'android.intent.action.MY_PACKAGE_REPLACED'],
'category': ['android.intent.category.HOME']}, {'action': ['android.appwidget.action.APPWIDGET_UPDATE']}]:
assert expected in filter_list
filter_list = []
for i in services:
filters = a.get_intent_filters("service", i)
if len(filters) > 0:
filter_list.append(filters)
pairs = zip(filter_list, [{
'action': ['android.intent.action.MAIN'],
'category': ['android.intent.category.LAUNCHER']
}, {
'action': [
'android.intent.action.BOOT_COMPLETED',
'android.intent.action.MY_PACKAGE_REPLACED'
],
'category': ['android.intent.category.HOME']
}, {
'action': ['android.appwidget.action.APPWIDGET_UPDATE']
}, {
'action': ['android.service.notification.NotificationListenerService']
}])
self.assertFalse(any(x != y for x, y in pairs))
self.assertEqual(filter_list, [{'action': ['android.service.notification.NotificationListenerService']}])
a = APK(os.path.join(test_dir, 'data/APK/com.test.intent_filter.apk'), testzip=True)
activities = a.get_activities()
activities = a.get_activities()
receivers = a.get_receivers()
services = a.get_services()
@ -411,16 +405,7 @@ class APKTest(unittest.TestCase):
filters = a.get_intent_filters("activity", i)
if len(filters) > 0:
filter_list.append(filters)
for i in receivers:
filters = a.get_intent_filters("receiver", i)
if len(filters) > 0:
filter_list.append(filters)
for i in services:
filters = a.get_intent_filters("service", i)
if len(filters) > 0:
filter_list.append(filters)
pairs = zip(filter_list, [{
for expected in [{
'action': ['android.intent.action.VIEW'],
'category': [
'android.intent.category.APP_BROWSER',
@ -437,37 +422,28 @@ class APKTest(unittest.TestCase):
}, {
'action': ['android.intent.action.MAIN'],
'category': ['android.intent.category.LAUNCHER']
}, {
'action': ['android.intent.action.VIEW'],
'category':
['android.intent.category.DEFAULT', 'android.intent.category.BROWSABLE'],
'data': [{
'scheme': 'testhost',
'host': 'testscheme',
'port': '0301',
'path': '/testpath',
'pathPattern': 'testpattern',
'mimeType': 'text/html'
}]
}, {
'action': ['android.intent.action.RESPOND_VIA_MESSAGE'],
'data': [{
'scheme': 'testhost',
'host': 'testscheme',
'port': '0301',
'path': '/testpath',
'pathPattern': 'testpattern',
'mimeType': 'text/html'
}, {
'scheme': 'testscheme2',
'host': 'testhost2',
'port': '0301',
'path': '/testpath2',
'pathPattern': 'testpattern2',
'mimeType': 'image/png'
}]
}])
self.assertFalse(any(x != y for x, y in pairs))
}]:
assert expected in filter_list
filter_list = []
for i in receivers:
filters = a.get_intent_filters("receiver", i)
if len(filters) > 0:
filter_list.append(filters)
self.assertEqual(filter_list, [{'action': ['android.intent.action.VIEW'],
'category': ['android.intent.category.DEFAULT',
'android.intent.category.BROWSABLE'], 'data': [
{'scheme': 'testhost', 'host': 'testscheme', 'port': '0301', 'path': '/testpath',
'pathPattern': 'testpattern', 'mimeType': 'text/html'}]}])
filter_list = []
for i in services:
filters = a.get_intent_filters("service", i)
if len(filters) > 0:
filter_list.append(filters)
self.assertEqual(filter_list, [{'action': ['android.intent.action.RESPOND_VIA_MESSAGE'], 'data': [
{'scheme': 'testhost', 'host': 'testscheme', 'port': '0301', 'path': '/testpath',
'pathPattern': 'testpattern', 'mimeType': 'text/html'},
{'scheme': 'testscheme2', 'host': 'testhost2', 'port': '0301', 'path': '/testpath2',
'pathPattern': 'testpattern2', 'mimeType': 'image/png'}]}])
def testEffectiveTargetSdkVersion(self):
@ -589,7 +565,7 @@ class APKTest(unittest.TestCase):
def testFeatures(self):
a = APK(os.path.join(test_dir, 'data/APK/com.example.android.tvleanback.apk'))
self.assertListEqual(list(a.get_features()), ["android.hardware.microphone",
self.assertListEqual(sorted(list(a.get_features())), ["android.hardware.microphone",
"android.hardware.touchscreen",
"android.software.leanback"])
self.assertTrue(a.is_androidtv())