1+ /*
2+ * Code Pulse: A real-time code coverage testing tool. For more information
3+ * see http://code-pulse.com
4+ *
5+ * Copyright (C) 2017 Applied Visions - http://securedecisions.avi.com
6+ *
7+ * Licensed under the Apache License, Version 2.0 (the "License");
8+ * you may not use this file except in compliance with the License.
9+ * You may obtain a copy of the License at
10+ *
11+ * http://www.apache.org/licenses/LICENSE-2.0
12+ *
13+ * Unless required by applicable law or agreed to in writing, software
14+ * distributed under the License is distributed on an "AS IS" BASIS,
15+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+ * See the License for the specific language governing permissions and
17+ * limitations under the License.
18+ */
19+
20+ package com .secdec .codepulse .data .bytecode .test
21+
22+ import java .io .File
23+ import java .util .zip .{ ZipEntry , ZipFile }
24+ import org .scalatest ._
25+ import org .scalatest .Matchers ._
26+ import com .secdec .codepulse .util .ZipEntryChecker
27+ import com .secdec .codepulse .data .bytecode ._
28+
29+
30+ class JavaSuite extends FunSpec with Matchers {
31+ describe(" Uploaded Java project data" ) {
32+ it(" should be accepted if the archive contains Java classes compiled in Java version < 8" ) {
33+ val file = new ZipFile (getClass.getResource(" java7-compiled.jar" ).getPath)
34+ val entry = file.getEntry(" Main.class" )
35+ val stream = file.getInputStream(entry)
36+
37+ try {
38+ AsmVisitors .parseMethodsFromClass(stream)
39+ }
40+ finally {
41+ stream.close
42+ }
43+ }
44+
45+ it(" should be accepted if the archive contains Java classes compiled in Java version 8" ) {
46+ val file = new ZipFile (getClass.getResource(" java8-compiled.jar" ).getPath)
47+ val entry = file.getEntry(" Main.class" )
48+ val stream = file.getInputStream(entry)
49+
50+ try {
51+ AsmVisitors .parseMethodsFromClass(stream)
52+ }
53+ finally {
54+ stream.close
55+ }
56+ }
57+
58+ it(" should not be accepted if the archive contains Java classes compiled in Java version 9" ) {
59+ val file = new ZipFile (getClass.getResource(" java9-compiled.jar" ).getPath)
60+ val entry = file.getEntry(" Main.class" )
61+ val stream = file.getInputStream(entry)
62+
63+ try {
64+ an [IllegalArgumentException ] should be thrownBy AsmVisitors .parseMethodsFromClass(stream)
65+ }
66+ finally {
67+ stream.close
68+ }
69+ }
70+ }
71+ }
0 commit comments