Skip to content

Commit

Permalink
Merge pull request #1045 from aml-org/r/v6.2.3
Browse files Browse the repository at this point in the history
R/v6.2.3
  • Loading branch information
emilianoascona authored Aug 1, 2024
2 parents ea27fb3 + 1120ab9 commit 57f10bf
Show file tree
Hide file tree
Showing 47 changed files with 260 additions and 73 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package org.mulesoft.als.actions.definition

import amf.core.internal.unsafe.PlatformSecrets
import org.mulesoft.amfintegration.platform.AlsPlatformSecrets
import org.scalatest.flatspec.AsyncFlatSpec
import org.scalatest.matchers.should.Matchers

import scala.concurrent.ExecutionContext

class DefinitionFileTests extends AsyncFlatSpec with Matchers with PlatformSecrets {
class DefinitionFileTests extends AsyncFlatSpec with Matchers with AlsPlatformSecrets {
override val executionContext: ExecutionContext =
scala.concurrent.ExecutionContext.Implicits.global

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@ package org.mulesoft.als.actions.folding

import amf.core.client.common.remote.Content
import amf.core.client.scala.resource.ResourceLoader
import amf.core.internal.unsafe.PlatformSecrets
import org.mulesoft.amfintegration.AmfImplicits.{AmfAnnotationsImp, BaseUnitImp}
import org.mulesoft.amfintegration.amfconfiguration.{
ALSConfigurationState,
EditorConfiguration,
EmptyProjectConfigurationState
}
import org.mulesoft.amfintegration.platform.AlsPlatformSecrets
import org.mulesoft.lsp.feature.folding.FoldingRange
import org.scalatest.flatspec.AsyncFlatSpec
import org.scalatest.matchers.should.Matchers

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.{ExecutionContext, Future}

class FoldingRangesTests extends AsyncFlatSpec with Matchers with PlatformSecrets {
class FoldingRangesTests extends AsyncFlatSpec with Matchers with AlsPlatformSecrets {
override val executionContext: ExecutionContext =
scala.concurrent.ExecutionContext.Implicits.global

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package org.mulesoft.als.actions.links

import amf.core.internal.unsafe.PlatformSecrets
import org.mulesoft.amfintegration.platform.AlsPlatformSecrets
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers

class FindLinksTests extends AnyFlatSpec with Matchers with PlatformSecrets {
class FindLinksTests extends AnyFlatSpec with Matchers with AlsPlatformSecrets {
behavior of "Find Links"

// todo: find a way to test this in a simple way (currently tested in server module)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package org.mulesoft.als.actions.rangeFormatting

import amf.core.internal.unsafe.PlatformSecrets
import org.mulesoft.als.actions.formatting.RangeFormatting
import org.mulesoft.amfintegration.ErrorsCollected
import org.mulesoft.amfintegration.platform.AlsPlatformSecrets
import org.mulesoft.lsp.configuration.FormattingOptions
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
import org.yaml.model.YMap

class FormattingOptionsTest extends AnyFlatSpec with Matchers with PlatformSecrets {
class FormattingOptionsTest extends AnyFlatSpec with Matchers with AlsPlatformSecrets {
behavior of "Formatting Options"

private val baseTest = "my: \n test: lorem ipsum \n\n\n\n\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@ package org.mulesoft.als.actions.selection

import amf.core.client.common.remote.Content
import amf.core.client.scala.resource.ResourceLoader
import amf.core.internal.unsafe.PlatformSecrets
import org.mulesoft.als.common.dtoTypes.Position
import org.mulesoft.amfintegration.AmfImplicits.{AmfAnnotationsImp, BaseUnitImp}
import org.mulesoft.amfintegration.amfconfiguration.{
ALSConfigurationState,
EditorConfiguration,
EmptyProjectConfigurationState
}
import org.mulesoft.amfintegration.platform.AlsPlatformSecrets
import org.mulesoft.lsp.feature.common.{Range, Position => LspPosition}
import org.mulesoft.lsp.feature.selectionRange.SelectionRange
import org.scalatest.flatspec.AsyncFlatSpec
import org.scalatest.matchers.should.Matchers

import scala.concurrent.{ExecutionContext, Future}

class SelectionRangeFinderTest extends AsyncFlatSpec with Matchers with PlatformSecrets {
class SelectionRangeFinderTest extends AsyncFlatSpec with Matchers with AlsPlatformSecrets {
override implicit val executionContext: ExecutionContext = ExecutionContext.Implicits.global

it should "select the range on YAML map" in {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package org.mulesoft.als.configuration

import amf.core.client.platform.resource.ClientResourceLoader
import amf.core.client.scala.resource.ResourceLoader
import amf.core.internal.unsafe.PlatformSecrets
import org.mulesoft.als.common.DirectoryResolver
import org.mulesoft.amfintegration.platform.AlsPlatformSecrets

import scala.concurrent.ExecutionContext.Implicits.global
import scala.scalajs.js
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package org.mulesoft.als.common

import amf.core.internal.unsafe.PlatformSecrets
import org.mulesoft.als.common.URIImplicits._
import org.mulesoft.amfintegration.platform.AlsPlatformSecrets

import scala.concurrent.Future

trait DirectoryResolver extends PlatformSecrets {
trait DirectoryResolver extends AlsPlatformSecrets {
def exists(path: String): Future[Boolean]

def readDir(path: String): Future[Seq[String]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import amf.core.client.scala.parse.AMFSyntaxParsePlugin
import amf.core.client.scala.parse.document.{ParsedDocument, ParserContext, SyamlParsedDocument}
import amf.core.internal.parser.domain.JsonParserFactory
import amf.core.internal.plugins.syntax.SyamlSyntaxParsePlugin
import amf.core.internal.unsafe.PlatformSecrets
import org.yaml.model.{YComment, YDocument, YMap, YNode}
import org.yaml.parser.YamlParser
import amf.core.internal.plugins.syntax.SyamlAMFErrorHandler
import org.mulesoft.amfintegration.platform.AlsPlatformSecrets

object AlsSyamlSyntaxPluginHacked extends AMFSyntaxParsePlugin with PlatformSecrets {
object AlsSyamlSyntaxPluginHacked extends AMFSyntaxParsePlugin with AlsPlatformSecrets {

override def priority: PluginPriority = HighPriority

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import amf.core.client.scala.resource.ResourceLoader
import amf.core.client.scala.{AMFParseResult => AMFParsingResult}
import amf.core.internal.remote.Spec.{AMF, GRAPHQL}
import amf.core.internal.remote.{AmlDialectSpec, Spec}
import amf.core.internal.unsafe.PlatformSecrets
import amf.graphql.client.scala.GraphQLConfiguration
import amf.shapes.client.scala.config.JsonSchemaConfiguration
import amf.shapes.client.scala.model.document.JsonSchemaDocument
Expand All @@ -22,6 +21,7 @@ import org.mulesoft.amfintegration.ValidationProfile
import org.mulesoft.amfintegration.dialect.dialects.ExternalFragmentDialect
import org.mulesoft.amfintegration.dialect.dialects.metadialect.{MetaDialect, VocabularyDialect}
import org.mulesoft.amfintegration.dialect.integration.BaseAlsDialectProvider
import org.mulesoft.amfintegration.platform.AlsPlatformSecrets
import org.yaml.builder.DocBuilder

import scala.concurrent.ExecutionContext.Implicits.global
Expand All @@ -35,7 +35,7 @@ case class ALSConfigurationState(
editorState: EditorConfigurationState,
projectState: ProjectConfigurationState,
editorResourceLoader: Option[ResourceLoader]
) extends PlatformSecrets {
) extends AlsPlatformSecrets {

lazy val amfParseContext: AmfParseContext = AmfParseContext(getAmfConfig(false), this)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import amf.core.client.scala.parse.AMFSyntaxParsePlugin
import amf.core.client.scala.resource.ResourceLoader
import amf.core.client.scala.validation.payload.AMFShapePayloadValidationPlugin
import amf.core.internal.remote.Spec
import amf.core.internal.unsafe.PlatformSecrets
import amf.graphql.client.scala.GraphQLConfiguration
import amf.shapes.client.scala.config.JsonSchemaConfiguration
import org.mulesoft.als.logger.Logger
import org.mulesoft.amfintegration.AmfImplicits.DialectInstanceImp
import org.mulesoft.amfintegration.dialect.integration.BaseAlsDialectProvider
import org.mulesoft.amfintegration.platform.AlsPlatformSecrets
import org.mulesoft.amfintegration.vocabularies.integration.{
AlsVocabularyParsingPlugin,
AlsVocabularyRegistry,
Expand Down Expand Up @@ -144,7 +144,7 @@ object EditorConfigurationState {
EditorConfigurationState(Nil, Nil, Nil, syntaxPlugin = Nil, validationPlugin = Nil)
}

object EditorConfiguration extends PlatformSecrets {
object EditorConfiguration extends AlsPlatformSecrets {
def apply(): EditorConfiguration = withPlatformLoaders(Seq.empty)

def withPlatformLoaders(rls: Seq[ResourceLoader]): EditorConfiguration =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ object ProfileNames {
val GRAPHQL: ProfileName = GraphQLProfile
val GRAPHQL_FEDERATION: ProfileName = GraphQLFederationProfile
val JSONSCHEMA: ProfileName = JsonSchemaProfile
val AVROSCHEMA: ProfileName = AvroSchemaProfile

lazy val specProfiles: Seq[ProfileName] =
Seq(
Expand All @@ -36,7 +37,8 @@ object ProfileNames {
GraphQLProfile,
GraphQLFederationProfile,
GrpcProfile,
JsonSchemaProfile
JsonSchemaProfile,
AvroSchemaProfile
)
}

Expand Down Expand Up @@ -95,6 +97,11 @@ object JsonSchemaProfile extends ProfileName(JsonSchema.id, AMFStyle) {
override def isRaml(): Boolean = false
}

object AvroSchemaProfile extends ProfileName(AvroSchema.id, AMFStyle) {
override def isOas(): Boolean = false
override def isRaml(): Boolean = false
}

object ProfileName {
def unapply(name: String): Option[ProfileName] =
name match {
Expand All @@ -108,6 +115,7 @@ object ProfileName {
case GraphQLProfile.p => Some(GraphQLProfile)
case GraphQLFederationProfile.p => Some(GraphQLFederationProfile)
case JsonSchemaProfile.p => Some(JsonSchemaProfile)
case AvroSchemaProfile.p => Some(AvroSchemaProfile)
case _ => None
}

Expand All @@ -129,6 +137,7 @@ object ProfileName {
case GraphQL.id => GraphQLProfile
case GraphQLFederation.id => GraphQLFederationProfile
case JsonSchema.id => JsonSchemaProfile
case AvroSchema.id => AvroSchemaProfile
case custom => new ProfileName(custom)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package org.mulesoft.amfintegration.platform

import amf.core.client.common.remote.Content
import amf.core.client.scala.resource.ResourceLoader
import amf.core.internal.remote.Platform
import amf.core.internal.unsafe.PlatformBuilder
import org.mulesoft.als.logger.Logger
import org.mulesoft.common.io.FileSystem

import scala.concurrent.{ExecutionContext, Future}
trait AlsPlatformSecrets {
private val internalPlatform: Platform = PlatformBuilder()

val platform: Platform = new Platform {
private def overrideLoaders(implicit executionContext: ExecutionContext): Seq[ResourceLoader] =
internalPlatform.loaders().map(SecuredLoader)

override def name: String = internalPlatform.name

override def findCharInCharSequence(s: CharSequence)(p: Char => Boolean): Option[Char] =
internalPlatform.findCharInCharSequence(s)(p)

override val fs: FileSystem = internalPlatform.fs

override def loaders()(implicit executionContext: ExecutionContext): Seq[ResourceLoader] = overrideLoaders

override def encodeURI(url: String): String = internalPlatform.encodeURI(url)

override def decodeURI(url: String): String = internalPlatform.decodeURI(url)

override def encodeURIComponent(url: String): String = internalPlatform.encodeURIComponent(url)

override def decodeURIComponent(url: String): String = internalPlatform.decodeURIComponent(url)

override def tmpdir(): String = internalPlatform.tmpdir

override def operativeSystem(): String = internalPlatform.operativeSystem

// no idea where this is used, but it is overriden in JvmPlatform and I am afraid to change it
override protected def customValidationLibraryHelperLocation: String =
if (name == "jvm") "classpath:validations/amf_validation.js" else super.customValidationLibraryHelperLocation
}

private case class SecuredLoader(loader: ResourceLoader) extends ResourceLoader {
override def fetch(resource: String): Future[Content] =
loader.fetch(resource)

override def accepts(resource: String): Boolean =
!potentialLeak(resource) && loader.accepts(resource)

private def potentialLeak(resource: String): Boolean =
WindowsLeakRegex(resource.toLowerCase)
}
}

protected object WindowsLeakRegex {
private def checkForLiteral(literal: String, prefix: String)(implicit resource: String): Boolean = {
val regex = s"$prefix/*$literal".r
regex.findPrefixMatchOf(resource).nonEmpty
}

private def doubleCheckLiteral(literal: String)(implicit resource: String): Boolean =
checkForLiteral(literal, "") || checkForLiteral(literal, filePrefix)
def apply(implicit resource: String): Boolean =
doubleCheckLiteral(windowsSMB) || doubleCheckLiteral(windowsSMBEncoded) || checkForLiteral(
unixStyle,
""
) || checkForLiteral(unixStyle, s"$filePrefix//")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.mulesoft.amfintegration

package object platform {
val filePrefix = "file:"
val windowsSMB = "\\\\" // just in case because AMF sometimes tries to re-fetch a URI decoding it
val windowsSMBEncoded = "%5c%5c"
val unixStyle = "//"
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package org.mulesoft.als.common.diff

import amf.core.internal.unsafe.PlatformSecrets
import org.mulesoft.amfintegration.platform.AlsPlatformSecrets
import org.mulesoft.common.io.{AsyncFile, FileSystem}
import org.scalatest.compatible.Assertion

import scala.concurrent.{ExecutionContext, Future}

trait FileAssertionTest extends PlatformSecrets {
trait FileAssertionTest extends AlsPlatformSecrets {

private implicit val executionContext: ExecutionContext = ExecutionContext.Implicits.global

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package org.mulesoft.als.common.dtoTypes

import amf.core.internal.remote.Platform
import amf.core.internal.unsafe.PlatformSecrets
import org.mulesoft.als.common.FileUtils
import org.mulesoft.als.common.URIImplicits._
import org.mulesoft.amfintegration.platform.AlsPlatformSecrets
import org.scalatest.funsuite.AnyFunSuite

class FileUtilsTest extends AnyFunSuite with PlatformSecrets {
class FileUtilsTest extends AnyFunSuite with AlsPlatformSecrets {

private val path = "root/drive/space in folder/file%3A"
private val uri = platform.encodeURI(path) // "root/drive/space%20in%20folder/file%253A"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package org.mulesoft.als.common.objectintree

import amf.aml.client.scala.model.document.Dialect
import amf.aml.internal.metamodel.domain.DialectDomainElementModel
import amf.core.internal.unsafe.PlatformSecrets
import org.mulesoft.als.common.dtoTypes.Position
import org.mulesoft.als.common.{NodeBranchBuilder, ObjectInTree, ObjectInTreeBuilder}
import org.mulesoft.amfintegration.AmfImplicits.BaseUnitImp
Expand All @@ -12,13 +11,14 @@ import org.mulesoft.amfintegration.amfconfiguration.{
EditorConfiguration,
EmptyProjectConfigurationState
}
import org.mulesoft.amfintegration.platform.AlsPlatformSecrets
import org.mulesoft.common.client.lexical.{Position => AmfPosition}
import org.scalatest.compatible.Assertion
import org.scalatest.matchers.should.Matchers

import scala.concurrent.{ExecutionContext, Future}

case class ObjectInTreeBaseTest(instanceFile: String, dialectFile: String) extends PlatformSecrets with Matchers {
case class ObjectInTreeBaseTest(instanceFile: String, dialectFile: String) extends AlsPlatformSecrets with Matchers {
protected def uriTemplate(part: String) = s"file://als-common/shared/src/test/resources/aml/$part"

implicit val ec: ExecutionContext = ExecutionContext.global
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.mulesoft.amfintegration.platform

import org.scalatest.funsuite.AnyFunSuite

class WindowsSMBLeakTest extends AnyFunSuite {

val matches: Set[String] = Set(
"file:%5c%5ctest",
"file:/%5c%5ctest",
"file://%5c%5ctest",
"file:///%5c%5ctest",
"file:////%5c%5ctest",
"file:\\\\test",
"file:/\\\\test",
"file://\\\\test",
"file:///\\\\test",
"\\\\test",
"%5c%5ctest",
"//test",
"file:////test"
)

test("should not match URI without SMB leak") {
assert(!WindowsLeakRegex("file:///test/correct"))
assert(!WindowsLeakRegex("file://test/correct"))
assert(!WindowsLeakRegex("file:/test/correct"))
assert(!WindowsLeakRegex("file:test/correct"))
assert(!WindowsLeakRegex("/test/correct"))
}

matches.foreach { resource =>
test(s"should match $resource") {
assert(WindowsLeakRegex.apply(resource))
}
}
}
Loading

0 comments on commit 57f10bf

Please sign in to comment.