ldap-client/test/Ldap/Client/BindSpec.hs
2016-12-27 17:02:07 +00:00

42 lines
1.3 KiB
Haskell
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{-# LANGUAGE CPP #-}
{-# LANGUAGE OverloadedStrings #-}
module Ldap.Client.BindSpec (spec) where
#if __GLASGOW_HASKELL__ < 710
import Data.Monoid (mempty)
#endif
import Test.Hspec
import qualified Ldap.Asn1.Type as Ldap.Type
import Ldap.Client as Ldap
import SpecHelper (locally)
spec :: Spec
spec = do
it "binds as admin" $ do
res <- locally $ \l ->
Ldap.bind l (Dn "cn=admin") (Password "secret")
res `shouldBe` Right ()
it "tries to bind as admin with the wrong password, unsuccessfully" $ do
res <- locally $ \l ->
Ldap.bind l (Dn "cn=admin") (Password "public")
res `shouldBe` Left
(Ldap.ResponseError
(Ldap.ResponseErrorCode
(Ldap.Type.BindRequest 3
(Ldap.Type.LdapDn (Ldap.Type.LdapString "cn=admin"))
(Ldap.Type.Simple "public"))
Ldap.InvalidCredentials
(Dn "cn=admin")
"InvalidCredentialsError"))
it "binds as pikachu" $ do
res <- locally $ \l -> do
Ldap.bind l (Dn "cn=admin") (Password "secret")
[Ldap.SearchEntry udn _]
<- Ldap.search l (Dn "o=localhost") mempty (Attr "cn" := "pikachu") []
Ldap.bind l udn (Password "i-choose-you")
res `shouldBe` Right ()