Skip to content

Commit b88d545

Browse files
Jami CogswellJami Cogswell
authored andcommitted
added unit tests
1 parent 58d3d89 commit b88d545

File tree

4 files changed

+196
-32
lines changed

4 files changed

+196
-32
lines changed

java/ql/test/query-tests/security/CWE-926/AndroidManifest.xml

Lines changed: 50 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,42 +12,78 @@
1212
android:roundIcon="@mipmap/ic_launcher_round"
1313
android:supportsRtl="true"
1414
android:theme="@style/Theme.HappyBirthday"
15-
tools:targetApi="31"> <!-- test -->
16-
<!-- Safe: category LAUNCHER --> <activity
17-
android:name=".MainActivity">
18-
<intent-filter>
19-
<action android:name="android.intent.action.MAIN" />
15+
tools:targetApi="31">
2016

21-
<category android:name="android.intent.category.LAUNCHER" />
17+
<!-- $ hasImplicitExport --> <activity
18+
android:name=".Activity">
19+
<intent-filter>
20+
<action android:name="android.intent.action.VIEW" />
2221
</intent-filter>
2322
</activity>
2423

25-
<!-- $ hasImplicitExport --> <activity
26-
android:name=".MainActivity">
24+
<!-- $ hasImplicitExport --> <receiver
25+
android:name=".CheckInstall">
2726
<intent-filter>
28-
<action android:name="android.intent.action.MAIN" />
27+
<action android:name="android.intent.action.PACKAGE_INSTALL"/>
28+
2929
</intent-filter>
30-
</activity>
30+
</receiver>
31+
32+
<!-- $ hasImplicitExport --> <service
33+
android:name=".backgroundService">
34+
<intent-filter>
35+
<action android:name="android.intent.action.START_BACKGROUND"/>
36+
37+
</intent-filter>
38+
</service>
39+
40+
<!-- $ hasImplicitExport --> <provider
41+
android:name=".MyCloudProvider">
42+
<intent-filter>
43+
<action android:name="android.intent.action.DOCUMENTS_PROVIDER"/>
44+
45+
</intent-filter>
46+
</service>
3147

3248
<!-- Safe: 'android:exported' explicitly set --> <activity
33-
android:name=".MainActivity"
49+
android:name=".Activity"
3450
android:exported="true">
3551
<intent-filter>
36-
<action android:name="android.intent.action.MAIN" />
52+
<action android:name="android.intent.action.VIEW" />
3753
</intent-filter>
3854
</activity>
3955

4056
<!-- Safe: no intent filter --> <activity
41-
android:name=".MainActivity">
57+
android:name=".Activity">
4258
</activity>
4359

4460
<!-- Safe: has 'permission' attribute --> <activity
45-
android:name=".MainActivity"
61+
android:name=".Activity"
4662
android:permission=".Test">
63+
<intent-filter>
64+
<action android:name="android.intent.action.VIEW" />
65+
</intent-filter>
66+
</activity>
67+
68+
<!-- Safe: 'provider' with read and write permissions set --> <provider
69+
android:name=".MyCloudProvider"
70+
android:readPermission=".TestRead"
71+
android:writePermission=".TestWrite">
72+
<intent-filter>
73+
<action android:name="android.intent.action.DOCUMENTS_PROVIDER"/>
74+
75+
</intent-filter>
76+
</service>
77+
78+
<!-- Safe: has category 'android.intent.category.LAUNCHER' --> <activity
79+
android:name=".Activity">
4780
<intent-filter>
4881
<action android:name="android.intent.action.MAIN" />
82+
83+
<category android:name="android.intent.category.LAUNCHER" />
4984
</intent-filter>
5085
</activity>
86+
5187
</application>
5288

5389
</manifest>

java/ql/test/query-tests/security/CWE-926/ImplicitlyExportedAndroidComponentTest.ql

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import java
2-
import semmle.code.xml.AndroidManifest
2+
import semmle.code.java.security.ImplicitlyExportedAndroidComponent
33
import TestUtilities.InlineExpectationsTest
44

55
class ImplicitlyExportedAndroidComponentTest extends InlineExpectationsTest {
@@ -9,9 +9,11 @@ class ImplicitlyExportedAndroidComponentTest extends InlineExpectationsTest {
99

1010
override predicate hasActualResult(Location location, string element, string tag, string value) {
1111
tag = "hasImplicitExport" and
12-
exists(AndroidComponentXmlElement compElement | compElement.isImplicitlyExported() |
13-
compElement.getLocation() = location and
14-
element = compElement.toString() and
12+
exists(ImplicitlyExportedAndroidComponent impExpAndroidComp |
13+
impExpAndroidComp.isImplicitlyExported()
14+
|
15+
impExpAndroidComp.getLocation() = location and
16+
element = impExpAndroidComp.toString() and
1517
value = ""
1618
)
1719
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools"
4+
package="com.example.happybirthday">
5+
6+
<application
7+
android:allowBackup="true"
8+
android:dataExtractionRules="@xml/data_extraction_rules"
9+
android:fullBackupContent="@xml/backup_rules"
10+
android:icon="@mipmap/ic_launcher"
11+
android:label="@string/app_name"
12+
android:roundIcon="@mipmap/ic_launcher_round"
13+
android:supportsRtl="true"
14+
android:theme="@style/Theme.HappyBirthday"
15+
tools:targetApi="31"
16+
android:permission=".Test">
17+
18+
<!-- Safe: 'application' element has 'permission' attribute --> <activity
19+
android:name=".Activity">
20+
<intent-filter>
21+
<action android:name="android.intent.action.VIEW" />
22+
</intent-filter>
23+
</activity>
24+
25+
<!-- Safe: 'application' element has 'permission' attribute --> <receiver
26+
android:name=".CheckInstall">
27+
<intent-filter>
28+
<action android:name="android.intent.action.PACKAGE_INSTALL"/>
29+
30+
</intent-filter>
31+
</receiver>
32+
33+
<!-- Safe: 'application' element has 'permission' attribute --> <service
34+
android:name=".backgroundService">
35+
<intent-filter>
36+
<action android:name="android.intent.action.START_BACKGROUND"/>
37+
38+
</intent-filter>
39+
</service>
40+
41+
<!-- Safe: 'application' element has 'permission' attribute --> <provider
42+
android:name=".MyCloudProvider">
43+
<intent-filter>
44+
<action android:name="android.intent.action.DOCUMENTS_PROVIDER"/>
45+
46+
</intent-filter>
47+
</service>
48+
49+
<!-- Safe: 'android:exported' explicitly set --> <activity
50+
android:name=".Activity"
51+
android:exported="true">
52+
<intent-filter>
53+
<action android:name="android.intent.action.VIEW" />
54+
</intent-filter>
55+
</activity>
56+
57+
<!-- Safe: no intent filter --> <activity
58+
android:name=".Activity">
59+
</activity>
60+
61+
<!-- Safe: has 'permission' attribute --> <activity
62+
android:name=".Activity"
63+
android:permission=".Test">
64+
<intent-filter>
65+
<action android:name="android.intent.action.VIEW" />
66+
</intent-filter>
67+
</activity>
68+
69+
<!-- Safe: 'provider' with read and write permissions set --> <provider
70+
android:name=".MyCloudProvider"
71+
android:readPermission=".TestRead"
72+
android:writePermission=".TestWrite">
73+
<intent-filter>
74+
<action android:name="android.intent.action.DOCUMENTS_PROVIDER"/>
75+
76+
</intent-filter>
77+
</service>
78+
79+
<!-- Safe: has category 'android.intent.category.LAUNCHER' --> <activity
80+
android:name=".Activity">
81+
<intent-filter>
82+
<action android:name="android.intent.action.MAIN" />
83+
84+
<category android:name="android.intent.category.LAUNCHER" />
85+
</intent-filter>
86+
</activity>
87+
88+
</application>
89+
90+
</manifest>

java/ql/test/query-tests/security/CWE-926/Testbuild/AndroidManifest.xml

Lines changed: 50 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,42 +12,78 @@
1212
android:roundIcon="@mipmap/ic_launcher_round"
1313
android:supportsRtl="true"
1414
android:theme="@style/Theme.HappyBirthday"
15-
tools:targetApi="31"> <!-- test -->
16-
<!-- Safe: category LAUNCHER --> <activity
17-
android:name=".MainActivity">
18-
<intent-filter>
19-
<action android:name="android.intent.action.MAIN" />
15+
tools:targetApi="31">
2016

21-
<category android:name="android.intent.category.LAUNCHER" />
17+
<!-- Safe: in build directory --> <activity
18+
android:name=".Activity">
19+
<intent-filter>
20+
<action android:name="android.intent.action.VIEW" />
2221
</intent-filter>
2322
</activity>
2423

25-
<!-- Safe: in build directory --> <activity
26-
android:name=".MainActivity">
24+
<!-- Safe: in build directory --> <receiver
25+
android:name=".CheckInstall">
2726
<intent-filter>
28-
<action android:name="android.intent.action.MAIN" />
27+
<action android:name="android.intent.action.PACKAGE_INSTALL"/>
28+
2929
</intent-filter>
30-
</activity>
30+
</receiver>
31+
32+
<!-- Safe: in build directory --> <service
33+
android:name=".backgroundService">
34+
<intent-filter>
35+
<action android:name="android.intent.action.START_BACKGROUND"/>
36+
37+
</intent-filter>
38+
</service>
39+
40+
<!-- Safe: in build directory --> <provider
41+
android:name=".MyCloudProvider">
42+
<intent-filter>
43+
<action android:name="android.intent.action.DOCUMENTS_PROVIDER"/>
44+
45+
</intent-filter>
46+
</service>
3147

3248
<!-- Safe: 'android:exported' explicitly set --> <activity
33-
android:name=".MainActivity"
49+
android:name=".Activity"
3450
android:exported="true">
3551
<intent-filter>
36-
<action android:name="android.intent.action.MAIN" />
52+
<action android:name="android.intent.action.VIEW" />
3753
</intent-filter>
3854
</activity>
3955

4056
<!-- Safe: no intent filter --> <activity
41-
android:name=".MainActivity">
57+
android:name=".Activity">
4258
</activity>
4359

4460
<!-- Safe: has 'permission' attribute --> <activity
45-
android:name=".MainActivity"
61+
android:name=".Activity"
4662
android:permission=".Test">
63+
<intent-filter>
64+
<action android:name="android.intent.action.VIEW" />
65+
</intent-filter>
66+
</activity>
67+
68+
<!-- Safe: 'provider' with read and write permissions set --> <provider
69+
android:name=".MyCloudProvider"
70+
android:readPermission=".TestRead"
71+
android:writePermission=".TestWrite">
72+
<intent-filter>
73+
<action android:name="android.intent.action.DOCUMENTS_PROVIDER"/>
74+
75+
</intent-filter>
76+
</service>
77+
78+
<!-- Safe: has category 'android.intent.category.LAUNCHER' --> <activity
79+
android:name=".Activity">
4780
<intent-filter>
4881
<action android:name="android.intent.action.MAIN" />
82+
83+
<category android:name="android.intent.category.LAUNCHER" />
4984
</intent-filter>
5085
</activity>
86+
5187
</application>
5288

5389
</manifest>

0 commit comments

Comments
 (0)