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")) } } }