Added more ssh tests (#29)

* Added more tests

* stopped weeds
This commit is contained in:
iko 2020-02-15 14:36:33 +03:00 committed by GitHub
parent 54a5b3b50e
commit 27a120ffe3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 117 deletions

1
.gitignore vendored
View File

@ -20,3 +20,4 @@ cabal.project.local
cabal.project.local~
.HTF/
.ghc.environment.*
*.cabal

View File

@ -1,113 +0,0 @@
cabal-version: 1.12
-- This file has been generated from package.yaml by hpack version 0.31.2.
--
-- see: https://github.com/sol/hpack
--
-- hash: 2b8bf0f1dd722fe9b761b465eeaa17ff976877aa7a5c517e092915bdc90158d7
name: isoparsec
version: 0.1.0.0
description: Please see the README on GitHub at <https://github.com/ilyakooo0/isoparsec#readme>
homepage: https://github.com/ilyakooo0/isoparsec#readme
bug-reports: https://github.com/ilyakooo0/isoparsec/issues
author: Ilya Kostyuchenko
maintainer: ilyakooo0@gmail.com
copyright: 2019 Ilya Kostyuchenko
license: MIT
license-file: LICENSE
build-type: Simple
extra-source-files:
README.md
ChangeLog.md
source-repository head
type: git
location: https://github.com/ilyakooo0/isoparsec
library
exposed-modules:
Control.Arrow.Extra
Control.Arrow.Extra.ArrowChoice
Control.Arrow.Extra.ArrowPlus
Control.Arrow.Extra.ArrowZero
Control.Arrow.Extra.BaseArrow
Control.Arrow.Extra.Orphans
Control.Arrow.Extra.PolyArrow
Control.SemiIso
Control.Tuple.Morph
Data.Isoparsec
Data.Isoparsec.ByteString
Data.Isoparsec.Char
Data.Isoparsec.Chunks
Data.Isoparsec.Cokleisli
Data.Isoparsec.Internal
Data.Isoparsec.Megaparsec
Data.Isoparsec.Printer
Data.Isoparsec.ToIsoparsec
Data.Isoparsec.Tokenable
other-modules:
Control.Prism
hs-source-dirs:
src
default-extensions: AllowAmbiguousTypes ConstraintKinds DataKinds DefaultSignatures DeriveGeneric FlexibleContexts FlexibleInstances FunctionalDependencies GADTs GeneralizedNewtypeDeriving LambdaCase MultiParamTypeClasses OverloadedStrings PatternSynonyms PolyKinds ScopedTypeVariables StandaloneDeriving TupleSections TypeApplications TypeFamilies TypeOperators UndecidableInstances RankNTypes
build-depends:
base >=4.7 && <5
, bytestring
, containers
, megaparsec
, mtl
, profunctors
default-language: Haskell2010
test-suite isoparsec-test
type: exitcode-stdio-1.0
main-is: Spec.hs
other-modules:
Spec.Helper
Spec.JSON
Spec.Megaparsec.BasicNums
Spec.Orphans
Spec.Ssh
Spec.TwoDigits
Control.Arrow.Extra
Control.Arrow.Extra.ArrowChoice
Control.Arrow.Extra.ArrowPlus
Control.Arrow.Extra.ArrowZero
Control.Arrow.Extra.BaseArrow
Control.Arrow.Extra.Orphans
Control.Arrow.Extra.PolyArrow
Control.Prism
Control.SemiIso
Control.Tuple.Morph
Data.Isoparsec
Data.Isoparsec.ByteString
Data.Isoparsec.Char
Data.Isoparsec.Chunks
Data.Isoparsec.Cokleisli
Data.Isoparsec.Internal
Data.Isoparsec.Megaparsec
Data.Isoparsec.Printer
Data.Isoparsec.ToIsoparsec
Data.Isoparsec.Tokenable
Paths_isoparsec
hs-source-dirs:
test
src
default-extensions: AllowAmbiguousTypes ConstraintKinds DataKinds DefaultSignatures DeriveGeneric FlexibleContexts FlexibleInstances FunctionalDependencies GADTs GeneralizedNewtypeDeriving LambdaCase MultiParamTypeClasses OverloadedStrings PatternSynonyms PolyKinds ScopedTypeVariables StandaloneDeriving TupleSections TypeApplications TypeFamilies TypeOperators UndecidableInstances RankNTypes
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends:
QuickCheck
, base >=4.7 && <5
, bytestring
, containers
, hspec
, lens
, megaparsec
, mtl
, profunctors
, tasty
, tasty-hspec
, tasty-quickcheck
, word8
default-language: Haskell2010

View File

@ -1,6 +1,7 @@
module Spec.Helper
( shouldParseBS,
roundtrip,
parseSatisfyBS,
)
where
@ -17,6 +18,31 @@ import Test.Tasty.QuickCheck
import Text.Megaparsec as M
import Prelude as P hiding ((.))
parseSatisfy ::
forall x s.
( ToIsoparsec x s,
Stream s,
Show x,
Show (M.Token s),
Show s,
Isoparsec (Kleisli (Parsec Void s)) s
) =>
s ->
(Either (ParseErrorBundle s Void) x -> Bool) ->
Expectation
parseSatisfy s p = runMegaparsec @Void @s toIsoparsec s `shouldSatisfy` p
parseSatisfyBS ::
forall x.
( ToIsoparsec x ByteString,
Show x,
Isoparsec (Kleisli (Parsec Void ByteString)) ByteString
) =>
ByteString ->
(Either (ParseErrorBundle ByteString Void) x -> Bool) ->
Expectation
parseSatisfyBS = parseSatisfy
shouldParse ::
forall x s.
( ToIsoparsec x s,

View File

@ -9,6 +9,7 @@ where
import Control.Lens.TH
import Data.ByteString as BS
import qualified Data.Char as C
import Data.Either
import Data.Isoparsec
import Data.Isoparsec.ByteString
import GHC.Generics
@ -98,10 +99,9 @@ instance ToIsoparsec Payload ByteString where
&&& auto @SSHString
)
<+> ( _VersionPayload <.> chunk "SSH-2.0-"
&&& ( (tokensWhile (not . flip BS.elem " \n\r") >>> utf8)
&&& ( (chunk " " >>> takeUntil "\r\n" >>^ turn (badKonst ""))
<+> chunk "\r\n"
)
&&& (tokensWhile (`BS.notElem` " \n\r") >>> utf8)
&&& ( (chunk " " >>> takeUntil "\r\n" >>^ turn (badKonst ""))
<+> chunk "\r\n"
)
)
<+> (_IgnorePayload <.> specific IgnoreMsg &&& tokensWhile (const True))
@ -169,7 +169,9 @@ spec :: Spec
spec = do
it "deserialize payload" $ do
"SSH-2.0-TesT\r\n" `shouldParseBS` VersionPayload "TesT"
"SSH-2.0-TesT" `parseSatisfyBS` isLeft @_ @Payload
"SSH-2.0-TesT random comment\r\n" `shouldParseBS` VersionPayload "TesT"
"SSH-2.0-TesT random comment" `parseSatisfyBS` isLeft @_ @Payload
"\x2__" `shouldParseBS` IgnorePayload "__"
"\x5\0\0\0\x6tested" `shouldParseBS` ServiceRequest (SSHString "tested")
it "deserialize packet" $ do