1
+ package org.utbot.instrumentation.security
2
+
3
+ import org.junit.jupiter.api.Assertions.*
4
+ import org.junit.jupiter.api.BeforeEach
5
+ import org.junit.jupiter.api.Test
6
+ import org.junit.jupiter.api.assertThrows
7
+ import org.utbot.instrumentation.process.permissions
8
+ import org.utbot.instrumentation.process.sandbox
9
+ import java.lang.NullPointerException
10
+ import java.security.AccessControlException
11
+ import java.security.AllPermission
12
+ import java.security.BasicPermission
13
+ import java.security.Permission
14
+ import java.util.PropertyPermission
15
+
16
+ class SecurityTest {
17
+
18
+ @BeforeEach
19
+ fun init () {
20
+ permissions {
21
+ + AllPermission ()
22
+ }
23
+ }
24
+
25
+ @Test
26
+ fun `basic security works` () {
27
+ sandbox {
28
+ assertThrows<AccessControlException > {
29
+ System .getProperty(" any" )
30
+ }
31
+ }
32
+ }
33
+
34
+ @Test
35
+ fun `basic permission works` () {
36
+ sandbox(listOf (PropertyPermission (" java.version" , " read" ))) {
37
+ val result = System .getProperty(" java.version" )
38
+ assertNotNull(result)
39
+ assertThrows<AccessControlException > {
40
+ System .setProperty(" any_random_value_key" , " random" )
41
+ }
42
+ }
43
+ }
44
+
45
+ @Test
46
+ fun `null is ok` () {
47
+ val empty = object : BasicPermission (" *" ) {}
48
+ val field = Permission ::class .java.getDeclaredField(" name" )
49
+ field.isAccessible = true
50
+ field.set(empty, null )
51
+ val collection = empty.newPermissionCollection()
52
+ assertThrows<NullPointerException > {
53
+ collection.implies(empty)
54
+ }
55
+ }
56
+
57
+ }
0 commit comments