summaryrefslogtreecommitdiff
path: root/src/test/scala/com/tylerstonge/honeypot/ftp/FtpHandlerTest.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/scala/com/tylerstonge/honeypot/ftp/FtpHandlerTest.scala')
-rw-r--r--src/test/scala/com/tylerstonge/honeypot/ftp/FtpHandlerTest.scala48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/test/scala/com/tylerstonge/honeypot/ftp/FtpHandlerTest.scala b/src/test/scala/com/tylerstonge/honeypot/ftp/FtpHandlerTest.scala
new file mode 100644
index 0000000..bc9b799
--- /dev/null
+++ b/src/test/scala/com/tylerstonge/honeypot/ftp/FtpHandlerTest.scala
@@ -0,0 +1,48 @@
+package com.tylerstonge.honeypot.ftp
+
+import akka.actor.{ActorSystem, Props}
+import akka.io.Tcp.{Received, Write}
+import akka.testkit.{ImplicitSender, TestKit}
+import akka.util.ByteString
+import org.scalatest.BeforeAndAfterAll
+import org.scalatest.matchers.should.Matchers
+import org.scalatest.wordspec.AnyWordSpecLike
+
+/**
+ *
+ * @author Tyler St. Onge <tylertstonge@gmail.com>
+ */
+class FtpHandlerTest extends TestKit(ActorSystem("honeypot-system")) with ImplicitSender with AnyWordSpecLike with Matchers with BeforeAndAfterAll {
+
+ override def afterAll: Unit = {
+ TestKit.shutdownActorSystem(system)
+ }
+
+ "An FtpHandler actor" must {
+ "return 331 in response to USER" in {
+ val handler = system.actorOf(Props[FtpHandler])
+ handler ! Received(ByteString("USER anonymous"))
+ val msg = expectMsgType[Write]
+ assert(msg.data.utf8String.startsWith("331"))
+ }
+ "return 230 in response to PASS" in {
+ val handler = system.actorOf(Props[FtpHandler])
+ handler ! Received(ByteString("PASS password"))
+ val msg = expectMsgType[Write]
+ assert(msg.data.utf8String.startsWith("230"))
+ }
+ "return 257 in response to PWD" in {
+ val handler = system.actorOf(Props[FtpHandler])
+ handler ! Received(ByteString("PWD"))
+ val msg = expectMsgType[Write]
+ assert(msg.data.utf8String.startsWith("257"))
+ }
+ "return 221 in response to QUIT" in {
+ val handler = system.actorOf(Props[FtpHandler])
+ handler ! Received(ByteString("quit"))
+ val msg = expectMsgType[Write]
+ assert(msg.data.utf8String.startsWith("221"))
+ }
+ }
+
+}