Skip to content
This repository has been archived by the owner on Oct 27, 2021. It is now read-only.

Commit

Permalink
Upgrade to Scala 2.13.4 (#49)
Browse files Browse the repository at this point in the history
* Upgrade scala version

* Adapt to scala 2.13.4 and run `sbt test:scalafmt`
  • Loading branch information
fabsx00 authored Jan 23, 2021
1 parent fe42e3e commit 95840c6
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 25 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name := "batteries"
ThisBuild/organization := "io.joern"
ThisBuild/scalaVersion := "2.13.0"
ThisBuild/scalaVersion := "2.13.4"

enablePlugins(JavaAppPackaging)
enablePlugins(GitVersioning)
Expand Down
2 changes: 1 addition & 1 deletion src/test/scala/io/joern/scanners/c/CopyLoopTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class CopyLoopTests extends Suite {
CopyLoops.isCopyLoop()(cpg).map(_.evidence) match {
case List(List(expr: nodes.Expression)) =>
expr.method.name shouldBe "index_into_dst_array"
case _ => fail
case _ => fail()
}
}

Expand Down
16 changes: 14 additions & 2 deletions src/test/scala/io/joern/scanners/c/CredentialDropTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,20 @@ class CredentialDropTests extends Suite {
"""

"strict order of credential dropping function calls should be observed" in {
CredentialDrop.userCredDrop()(cpg).flatMap(_.evidence).cast[nodes.Call].method.name.toSet shouldBe Set("bad1", "bad3")
CredentialDrop.groupCredDrop()(cpg).flatMap(_.evidence).cast[nodes.Call].method.name.toSet shouldBe Set("bad2")
CredentialDrop
.userCredDrop()(cpg)
.flatMap(_.evidence)
.cast[nodes.Call]
.method
.name
.toSet shouldBe Set("bad1", "bad3")
CredentialDrop
.groupCredDrop()(cpg)
.flatMap(_.evidence)
.cast[nodes.Call]
.method
.name
.toSet shouldBe Set("bad2")
}

}
12 changes: 6 additions & 6 deletions src/test/scala/io/joern/scanners/c/DangerousFunctionsTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class DangerousFunctionsTests extends Suite {
DangerousFunctions.getsUsed()(cpg).map(_.evidence) match {
case List(List(expr: nodes.Expression)) =>
expr.method.name shouldBe "insecure_gets"
case _ => fail
case _ => fail()
}
}

Expand All @@ -96,39 +96,39 @@ class DangerousFunctionsTests extends Suite {
DangerousFunctions.scanfUsed()(cpg).map(_.evidence) match {
case List(List(expr: nodes.Expression)) =>
expr.method.name shouldBe "insecure_scanf"
case _ => fail
case _ => fail()
}
}

"find insecure strncat() function usage" in {
DangerousFunctions.strcatUsed()(cpg).map(_.evidence) match {
case List(List(expr: nodes.Expression)) =>
expr.method.name shouldBe "insecure_strncat_strncpy"
case _ => fail
case _ => fail()
}
}

"find insecure strncpy() function usage" in {
DangerousFunctions.strcpyUsed()(cpg).map(_.evidence) match {
case List(List(expr: nodes.Expression)) =>
expr.method.name shouldBe "insecure_strncat_strncpy"
case _ => fail
case _ => fail()
}
}

"find insecure strtok() function usage" in {
DangerousFunctions.strtokUsed()(cpg).map(_.evidence) match {
case List(List(expr: nodes.Expression)) =>
expr.method.name shouldBe "insecure_strtok"
case _ => fail
case _ => fail()
}
}

"find insecure getwd() function usage" in {
DangerousFunctions.getwdUsed()(cpg).map(_.evidence) match {
case List(List(expr: nodes.Expression)) =>
expr.method.name shouldBe "insecure_getwd"
case _ => fail
case _ => fail()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class HeapBasedOverflowTests extends Suite {
x(cpg).map(_.evidence) match {
case List(List(expr: nodes.Expression)) =>
expr.code shouldBe "memcpy(dst, src, len + 7)"
case _ => fail
case _ => fail()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class IntegerTruncationsTests extends Suite {
case List(result) =>
result.evidence match {
case List(x: nodes.Identifier) => x.method.name shouldBe "vulnerable"
case _ => fail
case _ => fail()
}
case _ => fail
case _ => fail()
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/test/scala/io/joern/scanners/c/MetricsTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -72,47 +72,47 @@ class MetricsTests extends Suite {
Metrics.tooManyParameters(4)(cpg).map(_.evidence) match {
case List(List(method: nodes.Method)) =>
method.name shouldBe "too_many_params"
case _ => fail
case _ => fail()
}
}

"find functions with high cyclomatic complexity" in {
Metrics.tooHighComplexity(4)(cpg).map(_.evidence) match {
case List(List(method: nodes.Method)) =>
method.name shouldBe "high_cyclomatic_complexity"
case _ => fail
case _ => fail()
}
}

"find functions that are long (in terms of line numbers)" in {
Metrics.tooLong(13)(cpg).map(_.evidence) match {
case List(List(method: nodes.Method)) =>
method.name shouldBe "func_with_many_lines"
case _ => fail
case _ => fail()
}
}

"find functions with multiple returns" in {
Metrics.multipleReturns()(cpg).map(_.evidence) match {
case List(List(method: nodes.Method)) =>
method.name shouldBe "func_with_multiple_returns"
case _ => fail
case _ => fail()
}
}

"find functions with high number of loops" in {
Metrics.tooManyLoops(3)(cpg).map(_.evidence) match {
case List(List(method: nodes.Method)) =>
method.name shouldBe "high_number_of_loops"
case _ => fail
case _ => fail()
}
}

"find deeply nested functions" in {
Metrics.tooNested(2)(cpg).map(_.evidence) match {
case List(List(method: nodes.Method)) =>
method.name shouldBe "func_with_nesting_level_of_3"
case _ => fail
case _ => fail()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class NullTerminationTests extends Suite {
case List(x: nodes.Expression) =>
x.method.name shouldBe "bad"
case _ =>
fail
fail()
}
}

Expand Down
14 changes: 9 additions & 5 deletions src/test/scala/io/joern/scanners/c/SignedLeftShiftTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@ class SignedLeftShiftTests extends Suite {
"""

"find signed left shift" in {
SignedLeftShift.signedLeftShift()(cpg).flatMap(_.evidence).map{
case c: nodes.Call =>
c.method.name
case _ => fail
}.toSet shouldBe Set("bad1", "bad2", "bad3")
SignedLeftShift
.signedLeftShift()(cpg)
.flatMap(_.evidence)
.map {
case c: nodes.Call =>
c.method.name
case _ => fail()
}
.toSet shouldBe Set("bad1", "bad2", "bad3")
}

}

0 comments on commit 95840c6

Please sign in to comment.