Skip to content

Commit

Permalink
Strip !_fossa.virtual_! from VSI paths (#1345)
Browse files Browse the repository at this point in the history
  • Loading branch information
jssblck authored Dec 14, 2023
1 parent f26ae90 commit 7797018
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 4 deletions.
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# FOSSA CLI Changelog

## v3.8.28
- VSI: no longer reports paths inside of extracted archives with the `!_fossa.virtual_!` literal [#1345](https://github.com/fossas/fossa-cli/pull/1345)

## v3.8.27
- Maven: Fix a bug that broke maven analysis if the build directory was in a non-standard location ([#1343](https://github.com/fossas/fossa-cli/pull/1343))

Expand Down
8 changes: 5 additions & 3 deletions fourmolu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ let-style: inline
# Docs: https://github.com/fourmolu/fourmolu#language-extensions-dependencies-and-fixities
# If you have issues with operator formatting, usually you can find the right fixity in the haddocks.
fixities:
- infixl 3 <|>
- infix 4 ==
- infixr 3 &&
- infixr 0 $
- infixl 3 <|>
- infixr 3 &&
- infix 4 ==
- infixl 4 <$>, <*>
5 changes: 4 additions & 1 deletion src/App/Fossa/VSI/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,10 @@ instance FromJSON VsiExportedInferencesBody where
parseJSON = withObject "VsiExportedInferencesBody" $ \obj -> do
inferences <- (obj .:? "InferencesByFilePath") .!= KeyMap.empty
parsedVals <- traverse parseJSON inferences
pure . VsiExportedInferencesBody . Map.mapKeys VsiFilePath . KeyMap.toMapText $ parsedVals
pure . VsiExportedInferencesBody . Map.mapKeys (VsiFilePath . stripFossaVirtual) . KeyMap.toMapText $ parsedVals

stripFossaVirtual :: Text -> Text
stripFossaVirtual = Text.replace "!_fossa.virtual_!" ""

data VsiRule = VsiRule
{ vsiRulePath :: VsiRulePath
Expand Down
30 changes: 30 additions & 0 deletions test/App/Fossa/VSI/TypesSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@ inferencesBody =
}
|]

inferencesInArchiveBody :: BS.ByteString
inferencesInArchiveBody =
[r|
{
"InferencesByFilePath": {
"/foo/container.zip!_fossa.virtual_!/bar.h": {
"RawSha256": "YmIwMTg2NTNlOTVlY2U5M2VmMDYwMTQ3YjA0ZjZhYzRkZjhlMzFhZDc1OWFjYmExZWJmMjIwZDVjZTJlM2ZkZQ==",
"ComponentID": "0f4ba6a8-5b3f-436f-8c36-828e7375aef7",
"Locator": "git+github.com/facebook/folly$v2016.08.08.00",
"Confidence": 1
}
}
}
|]

emptyLocatorInference :: BS.ByteString
emptyLocatorInference =
[r|
Expand Down Expand Up @@ -69,6 +84,10 @@ expectedSingleInference :: VsiExportedInferencesBody
expectedSingleInference =
VsiExportedInferencesBody $ Map.fromList singleInference

expectedSingleInferenceInArchive :: VsiExportedInferencesBody
expectedSingleInferenceInArchive =
VsiExportedInferencesBody $ Map.fromList singleInferenceInArchive

singleInference :: [(VsiFilePath, VsiInference)]
singleInference =
[
Expand All @@ -77,6 +96,14 @@ singleInference =
)
]

singleInferenceInArchive :: [(VsiFilePath, VsiInference)]
singleInferenceInArchive =
[
( VsiFilePath "/foo/container.zip/bar.h"
, VsiInference . Just $ Locator "git" "github.com/facebook/folly" "v2016.08.08.00"
)
]

singleRuleExpected :: [VsiRule]
singleRuleExpected = [VsiRule (VsiRulePath "/foo/") (Locator "git" "github.com/facebook/folly" "v2016.08.08.00")]

Expand Down Expand Up @@ -124,6 +151,9 @@ vsiTypesSpec = describe "VSI Types" $ do
it "Parses a VsiExportedInferencesBody" $ do
let body = eitherDecode inferencesBody
body `shouldBe` Right expectedSingleInference
it "Strips 'fossa virtual' from archives" $ do
let body = eitherDecode inferencesInArchiveBody
body `shouldBe` Right expectedSingleInferenceInArchive
it "Accepts an empty string locator" $ do
let body = eitherDecode emptyLocatorInference
body `shouldBe` Right expectedEmptyLocatorInference
Expand Down

0 comments on commit 7797018

Please sign in to comment.