-
Notifications
You must be signed in to change notification settings - Fork 39
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
rework symlink test #445
Merged
Merged
rework symlink test #445
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1be09d1
rework symlink test
pjfanning 16b3757
add test that uses temp file symbolic link (still not fully working)
pjfanning 594b128
Update FileAndResourceDirectivesSymlinkSpec.scala
pjfanning 18478c9
Update FileAndResourceDirectivesSymlinkSpec.scala
pjfanning File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
...g/apache/pekko/http/scaladsl/server/directives/FileAndResourceDirectivesSymlinkSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* license agreements; and to You under the Apache License, version 2.0: | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* This file is part of the Apache Pekko project, which was derived from Akka. | ||
*/ | ||
|
||
/* | ||
* Copyright (C) 2009-2022 Lightbend Inc. <https://www.lightbend.com> | ||
*/ | ||
|
||
package org.apache.pekko.http.scaladsl.server | ||
package directives | ||
|
||
import java.io.File | ||
import java.nio.file.{ Files, Paths } | ||
|
||
import scala.concurrent.duration._ | ||
|
||
import org.apache.pekko | ||
import pekko.http.scaladsl.testkit.RouteTestTimeout | ||
import pekko.testkit._ | ||
|
||
import org.scalatest.{ BeforeAndAfterAll, Inside, Inspectors } | ||
|
||
class FileAndResourceDirectivesSymlinkSpec extends RoutingSpec | ||
with Inspectors with Inside with BeforeAndAfterAll { | ||
|
||
// need to serve from the src directory, when sbt copies the resource directory over to the | ||
// target directory it will resolve symlinks in the process | ||
val testRoot = new File("http-tests/src/test/resources") | ||
require(testRoot.exists(), s"testRoot was not found at ${testRoot.getAbsolutePath}") | ||
|
||
val tempDir = Files.createTempDirectory("pekko-http-symlink-test") | ||
tempDir.toFile.deleteOnExit() | ||
val dirWithLink = new File(tempDir.toFile, "dirWithLink") | ||
dirWithLink.mkdir() | ||
val symlink = Files.createSymbolicLink( | ||
Paths.get(dirWithLink.getAbsolutePath, "linked-dir"), | ||
new File(testRoot, "subDirectory").toPath.toAbsolutePath) | ||
|
||
override def afterAll(): Unit = { | ||
super.afterAll() | ||
Files.deleteIfExists(symlink) | ||
Files.deleteIfExists(dirWithLink.toPath) | ||
Files.deleteIfExists(tempDir) | ||
} | ||
|
||
// operations touch files, can be randomly hit by slowness | ||
implicit val routeTestTimeout: RouteTestTimeout = RouteTestTimeout(3.seconds.dilated) | ||
|
||
override def testConfigSource = super.testConfigSource ++ """ | ||
pekko.http.routing.range-coalescing-threshold = 1 | ||
""" | ||
|
||
"getFromDirectory" should { | ||
def _getFromDirectory() = getFromDirectory(dirWithLink.getCanonicalPath) | ||
|
||
"not follow symbolic links to find a file" in { | ||
Files.isSymbolicLink(symlink) shouldBe true | ||
EventFilter.warning(pattern = ".* points to a location that is not part of .*", occurrences = 1).intercept { | ||
Get("linked-dir/empty.pdf") ~> _getFromDirectory() ~> check { | ||
handled shouldBe false | ||
/* TODO: resurrect following links under an option | ||
responseAs[String] shouldEqual "123" | ||
mediaType shouldEqual `application/pdf`*/ | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better with Files.path, and yes Winodws is using different separator
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So TIL that Windows has symlinks but only for Windows 10/11. I don't know how this factors into everything, my initial inclination is to disable the test for Windows since this seems to only really be testing behaviour specific to Posix systems.
@He-Pin Can you confirm if the test passes on your machine (assuming all of the Windows related path separator issues have been solved)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is copied from an existing test. The test either works or fails on Windows - either way noone is complaining about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My understanding is that Windows Java installs know how to apply the file path even if it doesn't use Windows idioms.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@He-Pin could you try running
sbt http-tests/test
? It doesn't take that long compared to similar commands in main pekko repo.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@He-Pin I created #446 - is ok to say that you are not blocking this? I would like to get this merged so that I can do an RC2 for the Pekko HTTP 1.0.1 release.