From 50fb65ac57c5973ec44c78feb5888ea4443b06d6 Mon Sep 17 00:00:00 2001 From: Chord Date: Fri, 3 Jun 2016 21:47:45 -0400 Subject: [PATCH] Version bump scodec and specs2 Also fix assorted casting errors and improve test case readability --- build.sbt | 8 +-- .../psforever/crypto/CryptoInterface.scala | 6 +-- .../net/psforever/packet/PacketCoding.scala | 2 +- common/src/test/scala/ControlPacketTest.scala | 50 +++++++++---------- .../src/test/scala/CryptoInterfaceTest.scala | 2 +- common/src/test/scala/GamePacketTest.scala | 9 ++-- 6 files changed, 38 insertions(+), 39 deletions(-) diff --git a/build.sbt b/build.sbt index 05fadb80..476a65e7 100644 --- a/build.sbt +++ b/build.sbt @@ -5,11 +5,11 @@ lazy val commonSettings = Seq( scalacOptions := Seq("-unchecked", "-deprecation", "-encoding", "utf8"), resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots", libraryDependencies := Seq( - "com.typesafe.akka" %% "akka-actor" % "2.3.11", + "com.typesafe.akka" %% "akka-actor" % "2.4.4", "com.typesafe.scala-logging" %% "scala-logging" % "3.1.0", - "org.specs2" %% "specs2-core" % "2.3.11" % "test", - "org.scodec" %% "scodec-core" % "1.8.3", - "org.scodec" %% "scodec-akka" % "0.1.0-SNAPSHOT", + "org.specs2" %% "specs2-core" % "3.8.3" % "test", + "org.scodec" %% "scodec-core" % "1.9.0", + "org.scodec" %% "scodec-akka" % "0.1.0", "net.java.dev.jna" % "jna" % "4.2.1", "com.typesafe.akka" %% "akka-slf4j" % "2.4.4", "ch.qos.logback" % "logback-classic" % "1.1.7", diff --git a/common/src/main/scala/net/psforever/crypto/CryptoInterface.scala b/common/src/main/scala/net/psforever/crypto/CryptoInterface.scala index 6863b5b8..5e60d660 100644 --- a/common/src/main/scala/net/psforever/crypto/CryptoInterface.scala +++ b/common/src/main/scala/net/psforever/crypto/CryptoInterface.scala @@ -73,7 +73,7 @@ object CryptoInterface { if(mac1.length != mac2.length) return false - for(i <- 0 until mac1.length) { + for(i <- 0 until mac1.length.toInt) { okay = okay && mac1{i} == mac2{i} } @@ -182,7 +182,7 @@ object CryptoInterface { if(plaintext.length % RC5_BLOCK_SIZE != 0) throw new IllegalArgumentException(s"input must be padded to the nearest $RC5_BLOCK_SIZE byte boundary") - val ciphertext = Array.ofDim[Byte](plaintext.length) + val ciphertext = Array.ofDim[Byte](plaintext.length.toInt) val ret = psLib.RC5_Encrypt(encCryptoHandle, plaintext.toArray, plaintext.length, ciphertext)[Boolean] @@ -196,7 +196,7 @@ object CryptoInterface { if(ciphertext.length % RC5_BLOCK_SIZE != 0) throw new IllegalArgumentException(s"input must be padded to the nearest $RC5_BLOCK_SIZE byte boundary") - val plaintext = Array.ofDim[Byte](ciphertext.length) + val plaintext = Array.ofDim[Byte](ciphertext.length.toInt) val ret = psLib.RC5_Decrypt(decCryptoHandle, ciphertext.toArray, ciphertext.length, plaintext)[Boolean] diff --git a/common/src/main/scala/net/psforever/packet/PacketCoding.scala b/common/src/main/scala/net/psforever/packet/PacketCoding.scala index 103a0514..5a99ab62 100644 --- a/common/src/main/scala/net/psforever/packet/PacketCoding.scala +++ b/common/src/main/scala/net/psforever/packet/PacketCoding.scala @@ -386,7 +386,7 @@ object PacketCoding { // minus 1 because of the actual byte telling of the padding, which always has to be there val paddingNeeded = CryptoInterface.RC5_BLOCK_SIZE - remainder - 1 - val paddingEncoded = uint8L.encode(paddingNeeded).require + val paddingEncoded = uint8L.encode(paddingNeeded.toInt).require val packetWithPadding = packetNoPadding ++ ByteVector.fill(paddingNeeded)(0x00) ++ paddingEncoded.toByteVector diff --git a/common/src/test/scala/ControlPacketTest.scala b/common/src/test/scala/ControlPacketTest.scala index 6189ecd8..5dc9ca20 100644 --- a/common/src/test/scala/ControlPacketTest.scala +++ b/common/src/test/scala/ControlPacketTest.scala @@ -1,8 +1,10 @@ // Copyright (c) 2016 PSForever.net to present import org.specs2.mutable._ +import org.specs2.specification import net.psforever.packet._ import net.psforever.packet.control._ +import org.specs2.specification.core.Fragment import scodec.Attempt.Successful import scodec.bits._ import scodec.codecs.uint16 @@ -27,7 +29,7 @@ class ControlPacketTest extends Specification { g mustEqual 0x276 h mustEqual 0x275 case default => - true mustEqual false + ko } } @@ -52,7 +54,7 @@ class ControlPacketTest extends Specification { e mustEqual 0x275 f mustEqual 0x276 case default => - true mustEqual false + ko } } @@ -86,7 +88,7 @@ class ControlPacketTest extends Specification { subslot mustEqual 0 rest mustEqual string.drop(4) case default => - true mustEqual false + ko } } @@ -94,25 +96,25 @@ class ControlPacketTest extends Specification { val maxSlots = ControlPacketOpcode.SlottedMetaPacket7.id - ControlPacketOpcode.SlottedMetaPacket0.id // create all possible SlottedMetaPackets - for(i <- 0 until maxSlots) { - val subslot = 12323 - val pkt = createMetaPacket(i, subslot, ByteVector.empty) + Fragment.foreach(0 to maxSlots) { i => + "slot " + i ! { + val subslot = 12323 + val pkt = createMetaPacket(i, subslot, ByteVector.empty) - PacketCoding.DecodePacket(pkt).require match { - case SlottedMetaPacket(slot, subslotDecoded, rest) => + PacketCoding.DecodePacket(pkt).require match { + case SlottedMetaPacket(slot, subslotDecoded, rest) => - // XXX: there isn't a simple solution to Slot0 and Slot4 be aliases of each other structurally - // This is probably best left to higher layers - //slot mustEqual i % 4 // this is seen at 0x00A3FBFA - slot mustEqual i - subslotDecoded mustEqual subslot - rest mustEqual ByteVector.empty // empty in this case - case default => - true mustEqual false + // XXX: there isn't a simple solution to Slot0 and Slot4 be aliases of each other structurally + // This is probably best left to higher layers + //slot mustEqual i % 4 // this is seen at 0x00A3FBFA + slot mustEqual i + subslotDecoded mustEqual subslot + rest mustEqual ByteVector.empty // empty in this case + case default => + ko + } } } - - true } "encode" in { @@ -154,19 +156,15 @@ class ControlPacketTest extends Specification { ) "decode" in { - for(i <- strings.indices) { - MultiPacketEx.decode(strings{i}.bits).require.value mustEqual packets{i} + Fragment.foreach(strings.indices) { i => + "test "+i ! { MultiPacketEx.decode(strings{i}.bits).require.value mustEqual packets{i} } } - - true mustEqual true } "encode" in { - for(i <- packets.indices) { - MultiPacketEx.encode(packets{i}).require.toByteVector mustEqual strings{i} + Fragment.foreach(packets.indices) { i => + "test "+i ! { MultiPacketEx.encode(packets{i}).require.toByteVector mustEqual strings{i} } } - - true mustEqual true } } } diff --git a/common/src/test/scala/CryptoInterfaceTest.scala b/common/src/test/scala/CryptoInterfaceTest.scala index 0a01d52a..57377e13 100644 --- a/common/src/test/scala/CryptoInterfaceTest.scala +++ b/common/src/test/scala/CryptoInterfaceTest.scala @@ -102,7 +102,7 @@ class CryptoInterfaceTest extends Specification { hex"b4aea1559444a20b6112a2892de40eac00000000c8aea155b53d187076b79abab59001b600000000" val expected = hex"5aa15de41f5220cf5cca489155e1438c5aa15de4" - val output = CryptoInterface.MD5MAC(key, message, expected.length) + val output = CryptoInterface.MD5MAC(key, message, expected.length.toInt) output mustEqual expected } diff --git a/common/src/test/scala/GamePacketTest.scala b/common/src/test/scala/GamePacketTest.scala index 0a9da083..94689464 100644 --- a/common/src/test/scala/GamePacketTest.scala +++ b/common/src/test/scala/GamePacketTest.scala @@ -24,7 +24,7 @@ class GamePacketTest extends Specification { buildDate mustEqual "" unk mustEqual 0 case default => - true mustEqual false + ko } } @@ -46,7 +46,7 @@ class GamePacketTest extends Specification { serverIp mustEqual "64.37.158.69" serverPort mustEqual 30012 case default => - true mustEqual false + ko } } @@ -79,7 +79,7 @@ class GamePacketTest extends Specification { world.connections{0}.address.getPort mustEqual 30007 world.connections{0}.address.getAddress.toString mustEqual "/64.37.158.69" case default => - true mustEqual false + ko } } @@ -111,7 +111,8 @@ class GamePacketTest extends Specification { //println(pkt) - true mustEqual true + // TODO: actually test something + ok } }