-
Notifications
You must be signed in to change notification settings - Fork 359
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
aea7343
commit 33e991f
Showing
4 changed files
with
61 additions
and
28 deletions.
There are no files selected for viewing
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
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
56 changes: 46 additions & 10 deletions
56
filesystems/blob/src/test/scala/cromwell/filesystems/blob/AzureFileSystemSpec.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 |
---|---|---|
@@ -1,25 +1,61 @@ | ||
package cromwell.filesystems.blob | ||
|
||
import com.azure.core.credential.AzureSasCredential | ||
import com.azure.storage.blob.nio.{AzureFileSystem, AzureFileSystemProvider} | ||
import org.scalatest.flatspec.AnyFlatSpec | ||
import org.scalatest.matchers.should.Matchers | ||
|
||
import java.time.Instant | ||
import java.time.{Duration, Instant} | ||
import java.time.temporal.ChronoUnit | ||
import scala.compat.java8.OptionConverters._ | ||
import scala.jdk.CollectionConverters._ | ||
|
||
class AzureFileSystemSpec extends AnyFlatSpec with Matchers { | ||
val now = Instant.now() | ||
val container = BlobContainerName("testConainer") | ||
val exampleSas = BlobPathBuilderFactorySpec.buildExampleSasToken(now) | ||
val exampleConfig = BlobFileSystemManager.buildConfigMap(exampleSas, container) | ||
val exampleStorageEndpoint = BlobPathBuilderSpec.buildEndpoint("testStorageAccount") | ||
val exampleCombinedEndpoint = BlobFileSystemManager.combinedEnpointContainerUri(exampleStorageEndpoint, container) | ||
|
||
it should "parse an expiration from a sas token" in { | ||
val fiveMinutes: Duration = Duration.of(5, ChronoUnit.MINUTES) | ||
|
||
private def makeFilesystemWithExpiration(expiration: Instant): AzureFileSystem = | ||
makeFilesystemWithCreds(BlobPathBuilderFactorySpec.buildExampleSasToken(expiration)) | ||
|
||
private def makeFilesystemWithCreds(creds: AzureSasCredential): AzureFileSystem = { | ||
val storageEndpoint = BlobPathBuilderSpec.buildEndpoint("testStorageAccount") | ||
val container = BlobContainerName("testContainer") | ||
val combinedEndpoint = BlobFileSystemManager.combinedEnpointContainerUri(storageEndpoint, container) | ||
|
||
val provider = new AzureFileSystemProvider() | ||
val filesystem : AzureFileSystem = provider.newFileSystem(exampleCombinedEndpoint, exampleConfig.asJava).asInstanceOf[AzureFileSystem] | ||
provider.newFileSystem( | ||
combinedEndpoint, | ||
BlobFileSystemManager.buildConfigMap(creds, container).asJava | ||
).asInstanceOf[AzureFileSystem] | ||
} | ||
|
||
it should "parse an expiration from a sas token" in { | ||
val now = Instant.now() | ||
val filesystem : AzureFileSystem = makeFilesystemWithExpiration(now) | ||
filesystem.getExpiry.asScala shouldBe Some(now) | ||
filesystem.getFileStores.asScala.map(_.name()).exists(_ == container.value) shouldBe true | ||
filesystem.getFileStores.asScala.map(_.name()).exists(_ == "testContainer") shouldBe true | ||
} | ||
|
||
it should "not be expired when the token is fresh" in { | ||
val anHourFromNow = Instant.now().plusSeconds(3600) | ||
val filesystem : AzureFileSystem = makeFilesystemWithExpiration(anHourFromNow) | ||
filesystem.isExpired(fiveMinutes) shouldBe false | ||
} | ||
|
||
it should "be expired when we're within the buffer" in { | ||
val threeMinutesFromNow = Instant.now().plusSeconds(180) | ||
val filesystem : AzureFileSystem = makeFilesystemWithExpiration(threeMinutesFromNow) | ||
filesystem.isExpired(fiveMinutes) shouldBe true | ||
} | ||
|
||
it should "be expired when the token is stale" in { | ||
val anHourAgo = Instant.now().minusSeconds(3600) | ||
val filesystem : AzureFileSystem = makeFilesystemWithExpiration(anHourAgo) | ||
filesystem.isExpired(fiveMinutes) shouldBe true | ||
} | ||
|
||
it should "not be expired with public credentials" in { | ||
val fileSystem = makeFilesystemWithCreds(BlobFileSystemManager.PLACEHOLDER_TOKEN) | ||
fileSystem.isExpired(fiveMinutes) shouldBe false | ||
} | ||
} |
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