You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2023/09/09 06:42:46 UTC

[groovy] 02/02: GROOVY-11170: Fix edge cases for SecureASTCustomizer (test cases)

This is an automated email from the ASF dual-hosted git repository.

paulk pushed a commit to branch GROOVY_4_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 46773d6c501e553733e25e7d3c1eac4ed7c40124
Author: Paul King <pa...@asert.com.au>
AuthorDate: Sat Sep 9 16:42:32 2023 +1000

    GROOVY-11170: Fix edge cases for SecureASTCustomizer (test cases)
---
 .../customizers/SecureASTCustomizerTest.groovy     | 56 ++++++++++++++++++++++
 1 file changed, 56 insertions(+)

diff --git a/src/test/org/codehaus/groovy/control/customizers/SecureASTCustomizerTest.groovy b/src/test/org/codehaus/groovy/control/customizers/SecureASTCustomizerTest.groovy
index 1edb45998c..befa5f0335 100644
--- a/src/test/org/codehaus/groovy/control/customizers/SecureASTCustomizerTest.groovy
+++ b/src/test/org/codehaus/groovy/control/customizers/SecureASTCustomizerTest.groovy
@@ -525,6 +525,62 @@ final class SecureASTCustomizerTest {
         }
     }
 
+    @Test
+    void testAllowedReceiversMethod() {
+        customizer.allowedReceiversClasses = [Integer.TYPE]
+        def shell = new GroovyShell(configuration)
+        shell.evaluate('''
+            static main(args) {
+                1.plus(1)
+            }
+        ''')
+        assert hasSecurityException {
+            shell.evaluate('''
+                static main(args) {
+                    "string".toUpperCase()
+                }
+            ''')
+        }
+        assert hasSecurityException {
+            shell.evaluate('''
+                static main(args) {
+                    2.0.multiply(4)
+                }
+            ''')
+        }
+    }
+
+    @Test
+    void testAllowedReceiversClass() {
+        customizer.allowedReceiversClasses = [Integer.TYPE]
+        def shell = new GroovyShell(configuration)
+        shell.evaluate('''
+            class Dummy {
+                static main(args) {
+                    1.plus(1)
+                }
+            }
+        ''')
+        assert hasSecurityException {
+            shell.evaluate('''
+                class Dummy {
+                    static main(args) {
+                        "string".toUpperCase()
+                    }
+                }
+            ''')
+        }
+        assert hasSecurityException {
+            shell.evaluate('''
+                class Dummy {
+                    static main(args) {
+                        2.0.multiply(4)
+                    }
+                }
+            ''')
+        }
+    }
+
     @Test
     void testDisallowedReceivers() {
         customizer.disallowedReceiversClasses = [String]