packages feed

wai-saml2 0.2.1.0 → 0.2.1.1

raw patch · 3 files changed

+111/−2 lines, 3 filesdep +tastydep +tasty-hedgehogdep +tasty-hunit

Dependencies added: tasty, tasty-hedgehog, tasty-hunit, wai-saml2, warp

Files

src/Network/Wai/SAML2.hs view
@@ -13,6 +13,7 @@     -- * Callback-based middleware     --     -- $callbackBasedMiddleware+    Result(..),     saml2Callback,      -- * Vault-based middleware
+ test/Spec.hs view
@@ -0,0 +1,75 @@+--------------------------------------------------------------------------------+-- SAML2 Middleware for WAI                                                   --+--------------------------------------------------------------------------------+-- This source code is licensed under the MIT license found in the LICENSE    --+-- file in the root directory of this source tree.                            --+--------------------------------------------------------------------------------++module Main ( main ) where ++--------------------------------------------------------------------------------++import Control.Concurrent+import Control.Monad.IO.Class++import qualified Data.ByteString as BS+import qualified Data.ByteString.Lazy as LBS+import qualified Data.Vault.Lazy as V+import Data.X509+import Data.X509.File++import Network.HTTP.Types.Status+import Network.Wai+import Network.Wai.Test+import Network.Wai.Handler.Warp+import Network.Wai.SAML2++--------------------------------------------------------------------------------++-- | 'tests' implements the tests.+tests :: Session ()+tests = do+    samlResponse <- liftIO $ BS.readFile "test-data/sample-response"++    let req = (setPath defaultRequest "/sso/assert"){+        requestMethod = "POST",+        requestHeaders = [("Content-Type","application/x-www-form-urlencoded")]+    }++    res <- srequest $ SRequest req (LBS.fromStrict samlResponse)+++    samlResponseWithRs <- liftIO $ BS.readFile "test-data/sample-response-with-rs"++    res <- srequest $ SRequest req (LBS.fromStrict samlResponseWithRs)++    assertStatus 200 res ++-- | 'main' is the main entry point for the test suite.+main :: IO ()+main = do+    -- load private and public keys for the SP and IdP respectively+    [privKey] <- liftIO $ readKeyFile "test-data/sp.pem"+    [pubKey] <- liftIO $ readSignedObject "test-data/idp.pem"++    let (PrivKeyRSA privateKey) = privKey+    let (PubKeyRSA publicKey) = certPubKey $ signedObject $ getSigned pubKey++    -- construct a configuration for the SAML2 middleware; we disable+    -- time validation since it would require us to issue new responses+    -- every time we run the tests+    let config = (saml2Config privateKey publicKey){ +        saml2DisableTimeValidation = True +    }++    -- run the middleware with a basic application on top and execute the+    -- tests against it+    runSession tests $ saml2Vault config $ \req respond -> do +        print $ V.lookup relayStateKey (vault req)+        respond $ case V.lookup errorKey (vault req) of +                Just err -> do +                    responseLBS status400 [] "Invalid request"+                Nothing -> +                    responseLBS status200 [] "Hello World"++--------------------------------------------------------------------------------
wai-saml2.cabal view
@@ -4,10 +4,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: 0ab786ffa39a1a85044697458c860145df0f561c8b7ba0211f4fc6718c81d5ef+-- hash: f63d7b16c92954665cf67b0990eb0619c871dcf428ad23f9674aa34050d6ad9d  name:           wai-saml2-version:        0.2.1.0+version:        0.2.1.1 synopsis:       SAML2 assertion validation as WAI middleware description:    A Haskell library which implements SAML2 assertion validation as WAI middleware category:       Security@@ -61,6 +61,39 @@     , vault >=0.3 && <1     , wai >=3.0 && <4     , wai-extra >=3.0 && <4+    , x509 <2+    , x509-store <2+    , xml-conduit <2+  default-language: Haskell2010++test-suite wai-saml2-tests+  type: exitcode-stdio-1.0+  main-is: Spec.hs+  other-modules:+      Paths_wai_saml2+  hs-source-dirs:+      test+  default-extensions: OverloadedStrings MultiWayIf RecordWildCards FlexibleInstances+  ghc-options: -threaded -rtsopts -with-rtsopts=-N+  build-depends:+      base >=4.8 && <5+    , base64-bytestring >=0.1 && <2+    , bytestring >=0.9 && <0.11+    , c14n >=0.1.0.1 && <1+    , cryptonite <1+    , data-default-class <1+    , http-types <1+    , mtl >=2.2.1 && <3+    , tasty+    , tasty-hedgehog+    , tasty-hunit+    , text <2+    , time >=1.9 && <2+    , vault >=0.3 && <1+    , wai >=3.0 && <4+    , wai-extra >=3.0 && <4+    , wai-saml2+    , warp     , x509 <2     , x509-store <2     , xml-conduit <2