package net.usebox.gemini.server import org.apache.pekko import pekko.util.ByteString import org.scalatest.flatspec.AnyFlatSpec import org.scalatest.matchers.should.Matchers class ServerSpec extends AnyFlatSpec with Matchers { behavior of "decodeUTF8" it should "return right on valid UTF-8 codes" in { Server(TestData.conf) .decodeUTF8(ByteString("vĂ¡lid UTF-8")) shouldBe Symbol( "right" ) } it should "return left on invalid UTF-8 codes" in { Server(TestData.conf) .decodeUTF8(ByteString(Array(0xc3.toByte, 0x28.toByte))) shouldBe Symbol( "left" ) } behavior of "handleReq" it should "return bad request on empty URLs" in { Server(TestData.conf) .handleReq("", "127.0.0.1") should be( a[BadRequest] ) } it should "return bad request for invalid URLs" in { Server(TestData.conf) .handleReq("gemini://localhost/ invalid", "127.0.0.1") should be( a[BadRequest] ) } it should "return bad request on URLs with no scheme" in { Server(TestData.conf) .handleReq("//localhost/", "127.0.0.1") should be(a[BadRequest]) } it should "return proxy request refused on port mismatch" in { Server(TestData.conf) .handleReq("gemini://localhost:8080/", "127.0.0.1") should be( a[ProxyRequestRefused] ) } it should "return proxy request refused when port not provided and configured port is not default" in { Server(TestData.conf.copy(port = 8080)) .handleReq("gemini://localhost/", "127.0.0.1") should be( a[ProxyRequestRefused] ) } it should "return success when port is provided and matches configured port (not default)" in { Server(TestData.conf.copy(port = 8080)) .handleReq("gemini://localhost:8080/", "127.0.0.1") should be(a[Success]) } it should "return proxy request refused for non gemini schemes" in { Server(TestData.conf) .handleReq("https://localhost/", "127.0.0.1") should be( a[ProxyRequestRefused] ) } }