-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: collect evidence of security tests from our repo
CHANGELOG_BEGIN CHANGELOG_END
- Loading branch information
1 parent
50ea92f
commit d2c5667
Showing
5 changed files
with
122 additions
and
0 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
load("//bazel_tools:haskell.bzl", "da_haskell_binary") | ||
|
||
da_haskell_binary( | ||
name = "evidence-security", | ||
srcs = glob(["src/**/*.hs"]), | ||
hackage_deps = [ | ||
"base", | ||
"containers", | ||
"extra", | ||
"filepath", | ||
"split", | ||
], | ||
src_strip_prefix = "src", | ||
visibility = ["//visibility:public"], | ||
deps = [], | ||
) |
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,98 @@ | ||
-- Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
-- SPDX-License-Identifier: Apache-2.0 | ||
|
||
module Main (main) where | ||
|
||
import Data.List (intercalate) | ||
import Data.List.Extra (trim,groupOn) | ||
import Data.Map (Map) | ||
import qualified Data.Map as Map (fromList,toList) | ||
import Data.List.Split (splitOn) | ||
|
||
main :: IO () | ||
main = do | ||
print ("**Evidence Security**"::String) | ||
rawLines <- getRawGitGrepOutput | ||
let parsed = map parseLine rawLines | ||
let errs = [ err | Left err <- parsed ] | ||
let lines = [ line | Right line <- parsed ] | ||
let collated = collateLines lines | ||
print errs | ||
print collated | ||
-- NICK: check all catagories are covered | ||
pure () | ||
|
||
-- NICK: document what is going on here, and the magic comment format | ||
|
||
newtype Collated = Collated (Map Catagory [Description]) | ||
|
||
data Err = FailedToParseLine | UnknownCatagory String deriving Show | ||
|
||
data Line = Line { cat :: Catagory, desc :: Description } | ||
|
||
data Description = Description | ||
{ filename:: FilePath | ||
, lineno:: Int | ||
, freeText:: String | ||
} | ||
|
||
data Catagory = Authorization | Privacy | Semantics | Performance | ||
deriving (Eq,Ord) | ||
|
||
-- NICK: read from file on stdin (or maybe directly produce the raw data) | ||
getRawGitGrepOutput :: IO [String] | ||
getRawGitGrepOutput = pure | ||
[ "daml-lf/engine/src/test/scala/com/digitalasset/daml/lf/engine/AuthPropagationSpec.scala:// SECURITY_TEST: Authorization: Engine level tests for _authorization_ check." | ||
, "daml-lf/engine/src/test/scala/com/digitalasset/daml/lf/engine/AuthPropagationSpec.scala: // SECURITY_TEST: Authorization: Exercise within exercise: No implicit authorization from outer exercise." | ||
|
||
, "daml-lf/engine/src/test/scala/com/digitalasset/daml/lf/engine/AuthorizationSpec.scala:// SECURITY_TEST: Authorization: Unit test _authorization_ computations in: `CheckAuthorization`." | ||
, "daml-lf/engine/src/test/scala/com/digitalasset/daml/lf/engine/BlindingSpec.scala:// SECURITY_TEST: Privacy: Unit test _blinding_ computation: `Blinding.blind`." | ||
] | ||
|
||
parseLine :: String -> Either Err Line | ||
parseLine string = do | ||
let sep = ":" | ||
case splitOn sep string of | ||
filename : _magicComment_ : tag : rest -> do | ||
case catagoryFromTag (trim tag) of | ||
Nothing -> Left (UnknownCatagory (trim tag)) | ||
Just cat -> do | ||
let lineno = 42 -- NICK: need in raw data | ||
let freeText = trim (intercalate sep rest) | ||
let desc = Description {filename,lineno,freeText} | ||
let line = Line {cat,desc} | ||
Right line | ||
_ -> | ||
Left FailedToParseLine | ||
|
||
collateLines :: [Line] -> Collated | ||
collateLines lines = | ||
Collated $ Map.fromList | ||
[ (cat, [ desc | Line{desc} <- group ]) | ||
| group@(Line{cat}:_) <- groupOn (\Line{cat} -> cat) lines | ||
] | ||
|
||
catagoryFromTag :: String -> Maybe Catagory | ||
catagoryFromTag = \case | ||
"Authorization" -> Just Authorization | ||
"Privacy" -> Just Privacy | ||
"Semantics" -> Just Semantics | ||
"Performance" -> Just Performance | ||
_ -> Nothing | ||
|
||
instance Show Collated where | ||
show (Collated m) = | ||
unlines [ unlines ((show cat ++ ":") : map show descs) | ||
| (cat,descs) <- Map.toList m | ||
] | ||
|
||
instance Show Description where | ||
show Description{filename,lineno,freeText} = | ||
"- " ++ freeText ++ " (" ++ filename ++ ":" ++ show lineno ++ ")" | ||
|
||
instance Show Catagory where | ||
show = \case | ||
Authorization -> "Authorization" | ||
Privacy -> "Privacy" | ||
Semantics -> "Semantics" | ||
Performance -> "Performance" |