Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

/robots.txt #356

Merged
merged 1 commit into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class Routes[F[_]: Sync](enableDefaultRedirect: Boolean, service: IService[F]) e
ifTrue = Ok("OK"),
ifFalse = ServiceUnavailable("Service Unavailable")
)

case GET -> Root / "robots.txt" =>
Ok("User-agent: *\nDisallow: /")
}

private val corsRoute = HttpRoutes.of[F] {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright (c) 2023-2023 Snowplow Analytics Ltd. All rights reserved.
*
* This program is licensed to you under the Apache License Version 2.0, and
* you may not use this file except in compliance with the Apache License
* Version 2.0. You may obtain a copy of the Apache License Version 2.0 at
* http://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Apache License Version 2.0 is distributed on an "AS
* IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the Apache License Version 2.0 for the specific language
* governing permissions and limitations there under.
*/
package com.snowplowanalytics.snowplow.collectors.scalastream.it.core

import scala.concurrent.duration._

import org.specs2.mutable.Specification

import cats.effect.IO

import org.http4s.{Method, Request, Uri}

import cats.effect.testing.specs2.CatsEffect

import com.snowplowanalytics.snowplow.collectors.scalastream.it.kinesis.Kinesis
import com.snowplowanalytics.snowplow.collectors.scalastream.it.kinesis.containers._
import com.snowplowanalytics.snowplow.collectors.scalastream.it.Http

class RobotsSpec extends Specification with Localstack with CatsEffect {

override protected val Timeout = 5.minutes

"collector" should {
"respond to /robots.txt with 200 and not emit any event" in {
val testName = "robots"
val streamGood = s"$testName-raw"
val streamBad = s"$testName-bad-1"

Collector.container(
"kinesis/src/it/resources/collector.hocon",
testName,
streamGood,
streamBad
).use { collector =>
val uri = Uri.unsafeFromString(s"http://${collector.host}:${collector.port}/robots.txt")
val request = Request[IO](Method.GET, uri)

for {
response <- Http.response(request)
bodyBytes <- response.body.compile.toList
body = new String(bodyBytes.toArray)
_ <- IO.sleep(10.second)
collectorOutput <- Kinesis.readOutput(streamGood, streamBad)
} yield {
response.status.code must beEqualTo(200)
body must beEqualTo("User-agent: *\nDisallow: /")
collectorOutput.good must beEmpty
collectorOutput.bad must beEmpty
}
}
}
}
}