From c9d034f952d1c739d2ec86b920d95db16cadcb5c Mon Sep 17 00:00:00 2001 From: Matvey Aksenov Date: Sat, 28 Mar 2015 10:29:55 +0000 Subject: [PATCH] Fix the encoding of the `present' filter --- ldap-client.cabal | 16 ++++++++++++++++ src/Ldap/Asn1/ToAsn1.hs | 3 ++- test/Ldap/ClientSpec.hs | 21 +++++++++++++++++++++ test/Spec.hs | 1 + 4 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 test/Ldap/ClientSpec.hs create mode 100644 test/Spec.hs diff --git a/ldap-client.cabal b/ldap-client.cabal index dd04107..e90acf5 100644 --- a/ldap-client.cabal +++ b/ldap-client.cabal @@ -41,3 +41,19 @@ library , semigroups >= 0.16 , stm , text + +test-suite spec + default-language: + Haskell2010 + type: + exitcode-stdio-1.0 + hs-source-dirs: + test + main-is: + Spec.hs + other-modules: + Ldap.ClientSpec + build-depends: + base >= 4.7 && < 5 + , hspec + , ldap-client diff --git a/src/Ldap/Asn1/ToAsn1.hs b/src/Ldap/Asn1/ToAsn1.hs index a26a58a..d2b34cf 100644 --- a/src/Ldap/Asn1/ToAsn1.hs +++ b/src/Ldap/Asn1/ToAsn1.hs @@ -201,7 +201,8 @@ instance ToAsn1 Filter where Substrings x -> context 4 (toAsn1 x) GreaterOrEqual x -> context 5 (toAsn1 x) LessOrEqual x -> context 6 (toAsn1 x) - Present x -> context 7 (toAsn1 x) + Present (AttributeDescription (LdapString x)) + -> other Asn1.Context 7 (Text.encodeUtf8 x) ApproxMatch x -> context 8 (toAsn1 x) ExtensibleMatch x -> context 9 (toAsn1 x) diff --git a/test/Ldap/ClientSpec.hs b/test/Ldap/ClientSpec.hs new file mode 100644 index 0000000..c58dafa --- /dev/null +++ b/test/Ldap/ClientSpec.hs @@ -0,0 +1,21 @@ +{-# LANGUAGE OverloadedStrings #-} +module Ldap.ClientSpec (spec) where + +import Data.Monoid ((<>)) +import Test.Hspec + +import Ldap.Client +import qualified Ldap.Client as Ldap + + +spec :: Spec +spec = + context "Example stolen from the LDAP package tests" $ + it "searches the public LDAP server at MIT" $ do + res <- Ldap.with (Plain "scripts.mit.edu") 389 $ \l -> do + res <- Ldap.search l (Dn "ou=People,dc=scripts,dc=mit,dc=edu") + (scope WholeSubtree <> typesOnly True) + (Present (Attr "uid")) + [] + res `shouldSatisfy` (not . null) + res `shouldBe` Right () diff --git a/test/Spec.hs b/test/Spec.hs new file mode 100644 index 0000000..a824f8c --- /dev/null +++ b/test/Spec.hs @@ -0,0 +1 @@ +{-# OPTIONS_GHC -F -pgmF hspec-discover #-}