Skip to content

Commit 87dfc92

Browse files
committed
Add tests for CompilationUnit's subtypes
1 parent e324e4e commit 87dfc92

File tree

3 files changed

+97
-0
lines changed

3 files changed

+97
-0
lines changed

java/ql/test/query-tests/security/CWE-094/GroovyCompilationUnitTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,15 @@ public void doGet(HttpServletRequest request, HttpServletResponse response)
8181
cu.addSource(su);
8282
cu.compile(); // Safe
8383
}
84+
{
85+
JavaAwareCompilationUnit cu = new JavaAwareCompilationUnit();
86+
cu.addSource("test", request.getParameter("source"));
87+
cu.compile(); // $hasGroovyInjection
88+
}
89+
{
90+
JavaStubCompilationUnit cu = new JavaStubCompilationUnit(null, null);
91+
cu.addSource("test", request.getParameter("source"));
92+
cu.compile(); // Safe - JavaStubCompilationUnit only creates stubs
93+
}
8494
}
8595
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more contributor license
3+
* agreements. See the NOTICE file distributed with this work for additional information regarding
4+
* copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
5+
* "License"); you may not use this file except in compliance with the License. You may obtain a
6+
* 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 distributed under the License
11+
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12+
* or implied. See the License for the specific language governing permissions and limitations under
13+
* the License.
14+
*/
15+
package org.codehaus.groovy.tools.javac;
16+
17+
import groovy.lang.GroovyClassLoader;
18+
import org.codehaus.groovy.control.CompilationUnit;
19+
import org.codehaus.groovy.control.CompilerConfiguration;
20+
import java.io.File;
21+
22+
public class JavaAwareCompilationUnit extends CompilationUnit {
23+
public JavaAwareCompilationUnit() {}
24+
25+
public JavaAwareCompilationUnit(final CompilerConfiguration configuration) {}
26+
27+
public JavaAwareCompilationUnit(final CompilerConfiguration configuration,
28+
final GroovyClassLoader groovyClassLoader) {}
29+
30+
public JavaAwareCompilationUnit(final CompilerConfiguration configuration,
31+
final GroovyClassLoader groovyClassLoader, final GroovyClassLoader transformClassLoader) {}
32+
33+
@Override
34+
public void addSources(final String[] paths) {}
35+
36+
@Override
37+
public void addSources(final File[] files) {}
38+
39+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more contributor license
3+
* agreements. See the NOTICE file distributed with this work for additional information regarding
4+
* copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
5+
* "License"); you may not use this file except in compliance with the License. You may obtain a
6+
* 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 distributed under the License
11+
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12+
* or implied. See the License for the specific language governing permissions and limitations under
13+
* the License.
14+
*/
15+
package org.codehaus.groovy.tools.javac;
16+
17+
import groovy.lang.GroovyClassLoader;
18+
import org.codehaus.groovy.control.CompilationFailedException;
19+
import org.codehaus.groovy.control.CompilationUnit;
20+
import org.codehaus.groovy.control.CompilerConfiguration;
21+
import org.codehaus.groovy.control.SourceUnit;
22+
import java.io.File;
23+
import java.net.URL;
24+
25+
public class JavaStubCompilationUnit extends CompilationUnit {
26+
public JavaStubCompilationUnit(final CompilerConfiguration config, final GroovyClassLoader gcl,
27+
File destDir) {}
28+
29+
public JavaStubCompilationUnit(final CompilerConfiguration config, final GroovyClassLoader gcl) {}
30+
31+
public int getStubCount() {
32+
return 0;
33+
}
34+
35+
@Override
36+
public void compile() throws CompilationFailedException {}
37+
38+
@Override
39+
public SourceUnit addSource(final File file) {
40+
return null;
41+
}
42+
43+
@Override
44+
public SourceUnit addSource(URL url) {
45+
return null;
46+
}
47+
48+
}

0 commit comments

Comments
 (0)