From: fr33domlover <fr33domlo...@rel4tion.org> --- website/Snowdrift.cabal | 12 +++++++----- website/test/AlertsSpec.hs | 6 +++--- website/test/AuthSiteSpec.hs | 8 ++++---- website/test/DiscourseSpec.hs | 35 ++++++++++++++++------------------- website/test/HandlerSpec.hs | 6 +++--- website/test/SampleSpec.hs | 6 +++--- website/test/Spec.hs | 1 - website/test/StripeMock.hs | 2 +- website/test/Tasty.hs | 1 + website/test/TestImport.hs | 4 ++-- 10 files changed, 40 insertions(+), 41 deletions(-) delete mode 100644 website/test/Spec.hs create mode 100644 website/test/Tasty.hs
diff --git a/website/Snowdrift.cabal b/website/Snowdrift.cabal index 1f1ffc5..c7be912 100644 --- a/website/Snowdrift.cabal +++ b/website/Snowdrift.cabal @@ -152,7 +152,7 @@ executable Snowdrift -- test-suite test {{{1 test-suite test type: exitcode-stdio-1.0 - main-is: Spec.hs + main-is: Tasty.hs hs-source-dirs: test ghc-options: -Wall @@ -178,24 +178,26 @@ test-suite test -- build-depends {{{2 build-depends: Snowdrift - -- For htmlHasLink (should move upstream) - , HUnit >= 1.3.1.1 , base , bytestring , classy-prelude , classy-prelude-yesod , cryptonite - , hspec >= 2.0.0 , http-types , memory , persistent , persistent-postgresql , postgresql-simple - , QuickCheck , quickcheck-text , shakespeare , stripe-core , stripe-haskell + , tasty + , tasty-discover + -- For htmlHasLink (should move upstream) + , tasty-hunit + , tasty-hspec + , tasty-quickcheck , text >= 1.2.2.1 , wai-extra , yesod diff --git a/website/test/AlertsSpec.hs b/website/test/AlertsSpec.hs index 62235e8..cf0d9c5 100644 --- a/website/test/AlertsSpec.hs +++ b/website/test/AlertsSpec.hs @@ -1,4 +1,4 @@ -module AlertsSpec (spec) where +module AlertsSpec (spec_alerts) where import TestImport import Alerts @@ -20,8 +20,8 @@ alertSite = LiteApp go withAlertSite :: SpecWith (TestApp LiteApp) -> Spec withAlertSite = before $ pure (alertSite, id) -spec :: Spec -spec = withAlertSite $ +spec_alerts :: Spec +spec_alerts = withAlertSite $ it "adds an alert" $ do get getR htmlCount ".alert" 0 diff --git a/website/test/AuthSiteSpec.hs b/website/test/AuthSiteSpec.hs index e962fce..a251a9e 100644 --- a/website/test/AuthSiteSpec.hs +++ b/website/test/AuthSiteSpec.hs @@ -4,13 +4,13 @@ {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE ViewPatterns #-} {-# OPTIONS_GHC -fno-warn-unused-binds #-} -module AuthSiteSpec (spec) where +module AuthSiteSpec (spec_authSite) where import TestImport hiding (Handler) import Database.Persist.Sql hiding (get) import Database.Persist.Postgresql (pgConnStr) import Network.Wai.Test (SResponse(..)) -import Test.HUnit (assertBool) +import Test.Tasty.HUnit (assertBool) import Yesod hiding (get) import Yesod.Default.Config2 (ignoreEnv, loadYamlSettings) import qualified Data.Text as T @@ -171,8 +171,8 @@ withBob = beforeWith makeBob -- ** The actual tests! -spec :: Spec -spec = mainSpecs >> authRouteSpec +spec_authSite :: Spec +spec_authSite = mainSpecs >> authRouteSpec -- | Having this defined separately is clumsy. It should be moved back into -- the right spot. The problem is that it needs a different value of diff --git a/website/test/DiscourseSpec.hs b/website/test/DiscourseSpec.hs index f00c084..e4cc0b0 100644 --- a/website/test/DiscourseSpec.hs +++ b/website/test/DiscourseSpec.hs @@ -13,30 +13,27 @@ import Crypto.MAC.HMAC (HMAC, hmac) import Data.ByteArray (ByteArray, ByteArrayAccess) import Data.ByteArray.Encoding (Base(Base16, Base64URLUnpadded), convertToBase) import Data.Text.Arbitrary () -import Test.Hspec.QuickCheck (prop) -import Test.QuickCheck (Arbitrary, arbitrary, choose, oneof, vectorOf, NonEmptyList(..)) +import Test.Tasty.QuickCheck (Arbitrary, arbitrary, choose, oneof, vectorOf, NonEmptyList(..)) import qualified Data.ByteString.Char8 as Char8 {-# ANN module ("HLint: ignore Reduce duplication" :: String) #-} -spec :: Spec -spec = do - prop "validateSig" $ \(NonEmpty secret) (NonEmpty payload) -> do - let secret' = pack secret - payload' = pack payload - - validateSig (DiscourseSecret secret') payload' - (base16 (hmac secret' payload' :: HMAC SHA256)) - - prop "parsePayload" $ \(Nonce nonce) (Url url) -> do - let payload = "nonce=" <> nonce <> "&return_sso_url=" <> encodeUtf8 url - parsePayload (base64 payload) - `shouldBe` - Right DiscoursePayload - { dpNonce = nonce - , dpUrl = url - } +prop_validateSig (NonEmpty secret) (NonEmpty payload) = do + let secret' = pack secret + payload' = pack payload + + validateSig (DiscourseSecret secret') payload' + (base16 (hmac secret' payload' :: HMAC SHA256)) + +prop_parsePayload (Nonce nonce) (Url url) = do + let payload = "nonce=" <> nonce <> "&return_sso_url=" <> encodeUtf8 url + parsePayload (base64 payload) + `shouldBe` + Right DiscoursePayload + { dpNonce = nonce + , dpUrl = url + } -- 16 bytes of [0-9A-F] newtype Nonce diff --git a/website/test/HandlerSpec.hs b/website/test/HandlerSpec.hs index 5a537fb..12d9f39 100644 --- a/website/test/HandlerSpec.hs +++ b/website/test/HandlerSpec.hs @@ -1,4 +1,4 @@ -module HandlerSpec (spec) where +module HandlerSpec (spec_handler) where import TestImport @@ -14,8 +14,8 @@ import Network.Wai.Test (SResponse(..)) {-# ANN module ("HLint: ignore Reduce duplication" :: String) #-} -spec :: Spec -spec = withApp $ do +spec_handler :: Spec +spec_handler = withApp $ do describe "getRobotsR" getRobotsSpec describe "getFaviconR" getFaviconSpec describe "getWelcomeR" getWelcomeSpec diff --git a/website/test/SampleSpec.hs b/website/test/SampleSpec.hs index c95170e..35971d6 100644 --- a/website/test/SampleSpec.hs +++ b/website/test/SampleSpec.hs @@ -1,9 +1,9 @@ -module SampleSpec (spec) where +module SampleSpec (spec_sample) where import TestImport -spec :: Spec -spec = withApp $ do +spec_sample :: Spec +spec_sample = withApp $ do describe "various properties" $ do it "/home links to /privacy and /terms" $ do get WelcomeR diff --git a/website/test/Spec.hs b/website/test/Spec.hs deleted file mode 100644 index a824f8c..0000000 --- a/website/test/Spec.hs +++ /dev/null @@ -1 +0,0 @@ -{-# OPTIONS_GHC -F -pgmF hspec-discover #-} diff --git a/website/test/StripeMock.hs b/website/test/StripeMock.hs index 23c5b8a..51ffb86 100644 --- a/website/test/StripeMock.hs +++ b/website/test/StripeMock.hs @@ -9,7 +9,7 @@ import ClassyPrelude.Yesod hiding (method) import Data.Typeable import Web.Stripe import Web.Stripe.Error -import Test.Hspec (shouldBe) +import Test.Tasty.Hspec (shouldBe) data StripeMockEffects = forall a. Typeable (StripeReturn a) diff --git a/website/test/Tasty.hs b/website/test/Tasty.hs new file mode 100644 index 0000000..70c55f5 --- /dev/null +++ b/website/test/Tasty.hs @@ -0,0 +1 @@ +{-# OPTIONS_GHC -F -pgmF tasty-discover #-} diff --git a/website/test/TestImport.hs b/website/test/TestImport.hs index ccce560..a452a66 100644 --- a/website/test/TestImport.hs +++ b/website/test/TestImport.hs @@ -10,14 +10,14 @@ import Database.Persist.Postgresql (pgConnStr, ConnectionString) import Foundation as X import Network.HTTP.Types (Status(..)) import Network.Wai.Test (SResponse(..)) -import Test.Hspec as X +import Test.Tasty.Hspec as X import Yesod.Default.Config2 (ignoreEnv, loadYamlSettings) import Yesod.Test as X import qualified Data.Text.Encoding as T import qualified Database.PostgreSQL.Simple as PG -- For htmlHasLink -import Test.HUnit +import Test.Tasty.HUnit import Yesod.Core import Application (makeFoundation, makeLogWare) -- 1.9.1 _______________________________________________ Dev mailing list Dev@lists.snowdrift.coop https://lists.snowdrift.coop/mailman/listinfo/dev