From 747b6af76b23650756811d896bf76b4331419784 Mon Sep 17 00:00:00 2001 From: "Tyler St. Onge" Date: Sat, 25 Jul 2020 22:38:14 -0400 Subject: refine ftp component and add configuration capabilities --- .../tylerstonge/honeypot/ftp/FtpHandlerTest.scala | 48 ++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/test/scala/com/tylerstonge/honeypot/ftp/FtpHandlerTest.scala (limited to 'src/test') 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 + */ +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")) + } + } + +} -- cgit v1.1