Skip to content

Commit

Permalink
GROOVY-11170: Fix edge cases for SecureASTCustomizer (test cases)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulk-asert committed Sep 11, 2023
1 parent 5e8e09f commit ef238e1
Showing 1 changed file with 56 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit ef238e1

Please sign in to comment.