Skip to content

Commit ee9289b

Browse files
committed
Run tests with security manager that prohibits reading kotlinx.* props
1 parent 060f93c commit ee9289b

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

kotlinx-coroutines-core/pom.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
<sourceDirectory>src/main/kotlin</sourceDirectory>
3838
<testSourceDirectory>src/test/kotlin</testSourceDirectory>
3939

40+
4041
<plugins>
4142
<plugin>
4243
<artifactId>maven-surefire-plugin</artifactId>
@@ -49,7 +50,7 @@
4950
<configuration>
5051
<forkMode>once</forkMode>
5152
<jvm>${env.JDK_16}/bin/java</jvm>
52-
<argLine>-ea -Xmx1g -Xms1g</argLine>
53+
<argLine>-ea -Xmx1g -Xms1g -Djava.security.manager=kotlinx.coroutines.experimental.TestSecurityManager</argLine>
5354
</configuration>
5455
</execution>
5556
</executions>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright 2016-2017 JetBrains s.r.o.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package kotlinx.coroutines.experimental
18+
19+
import java.security.Permission
20+
21+
class TestSecurityManager : SecurityManager() {
22+
override fun checkPropertyAccess(key: String?) {
23+
if (key?.startsWith("kotlinx.") == true)
24+
throw SecurityException("'$key' property is not allowed")
25+
}
26+
27+
override fun checkPermission(perm: Permission?) {
28+
/* allow everything else */
29+
}
30+
}

0 commit comments

Comments
 (0)