Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test failure for prop_aeson_canonical #247

Open
maralorn opened this issue Nov 16, 2020 · 7 comments
Open

Test failure for prop_aeson_canonical #247

maralorn opened this issue Nov 16, 2020 · 7 comments

Comments

@maralorn
Copy link

When trying to build hackage-security-0.6.0.1 in nixpkgs we get this error:


  Canonical JSON
    prop_roundtrip_canonical:        OK (0.37s)
      +++ OK, passed 100 tests.
    prop_roundtrip_pretty:           OK (0.47s)
      +++ OK, passed 100 tests.
    prop_canonical_pretty:           OK (0.80s)
      +++ OK, passed 100 tests.
    prop_aeson_canonical:            FAIL
      *** Failed! Falsified (after 5 tests and 1 shrink):
      JSObject [("",JSObject [("\SI",JSString "")])]
      Use --quickcheck-replay=74285 to reproduce.

1 out of 16 tests failed (2.39s)

We recently updated a lot of dependencies, so it is hard to tell, what exactly broke this. I can just say, that all dependencies match the version bounds in the cabal file. This is with aeson 1.5.4.1.

Full build log at https://hydra.nixos.org/build/130472285/nixlog/1

@ezzieyguywuf
Copy link

I get the same error trying to build this and run tests on gentoo.

ezzieyguywuf added a commit to ezzieyguywuf/gentoo-haskell that referenced this issue Jan 7, 2021
The tests were failing for two reasons:

1. Old aeson upperbound
2. Failing unit-test in upstream

The failing test is addressed in
this issue](haskell/hackage-security#247)
upstream. The rest of the tests pass using the newer aeson.

Signed-off-by: Wolfgang E. Sanyer <[email protected]>
ezzieyguywuf added a commit to ezzieyguywuf/gentoo-haskell that referenced this issue Jan 7, 2021
The tests were failing for two reasons:

1. Old aeson upperbound
2. Failing unit-test in upstream

The failing test is addressed in
[this issue](haskell/hackage-security#247)
upstream. The rest of the tests pass using the newer aeson.

Signed-off-by: Wolfgang E. Sanyer <[email protected]>
ezzieyguywuf added a commit to ezzieyguywuf/gentoo-haskell that referenced this issue Jan 9, 2021
The tests were failing for two reasons:

1. Old aeson upperbound
2. Failing unit-test in upstream

The failing test is addressed in
[this issue](haskell/hackage-security#247)
upstream. The rest of the tests pass using the newer aeson.

Signed-off-by: Wolfgang E. Sanyer <[email protected]>
ezzieyguywuf added a commit to ezzieyguywuf/gentoo-haskell that referenced this issue Jan 9, 2021
The tests were failing for two reasons:

1. Old aeson upperbound
2. Failing unit-test in upstream

The failing test is addressed in
[this issue](haskell/hackage-security#247)
upstream. The rest of the tests pass using the newer aeson.

Signed-off-by: Wolfgang E. Sanyer <[email protected]>
@ezzieyguywuf
Copy link

I can confirm that this seems to be an issue with the way in which the tests are executed. The following patch, while admittedly a bit of a hack, shows how some minor tweaks to the test code can resolve the issue:

diff --git a/hackage-security/hackage-security.cabal b/hackage-security/hackage-security.cabal
index 1835e09..381ac43 100644
--- a/hackage-security/hackage-security.cabal
+++ b/hackage-security/hackage-security.cabal
@@ -261,8 +261,8 @@ test-suite TestSuite
   build-depends:       tasty            == 1.2.*,
                        tasty-hunit      == 0.10.*,
                        tasty-quickcheck == 0.10.*,
-                       QuickCheck       >= 2.11 && <2.14,
-                       aeson            == 1.4.*,
+                       QuickCheck       >= 2.11,
+                       aeson            >= 1.4,
                        vector           == 0.12.*,
                        unordered-containers >=0.2.8.0 && <0.3,
                        temporary        >= 1.2 && < 1.4
diff --git a/hackage-security/tests/TestSuite/JSON.hs b/hackage-security/tests/TestSuite/JSON.hs
index 5ea2c7f..39e93e2 100644
--- a/hackage-security/tests/TestSuite/JSON.hs
+++ b/hackage-security/tests/TestSuite/JSON.hs
@@ -23,6 +23,9 @@ import Data.String (fromString)
 import qualified Data.Vector as V
 import qualified Data.HashMap.Strict as HM
 
+-- text
+import qualified Data.Text as Text
+
 prop_aeson_canonical, prop_roundtrip_canonical, prop_roundtrip_pretty, prop_canonical_pretty
   :: JSValue -> Bool
 
@@ -48,6 +51,9 @@ canonicalise   (JSArray  vs) = JSArray  [ canonicalise v | v <- vs]
 canonicalise   (JSObject vs) = JSObject [ (k, canonicalise v)
                                         | (k,v) <- sortBy (compare `on` fst) vs ]
 
+sanitizeString :: String -> String
+sanitizeString s = Text.unpack (Text.replace (Text.pack "\\") (Text.pack "\\\\") (Text.pack (show s)))
+
 instance Arbitrary JSValue where
   arbitrary =
     sized $ \sz ->
@@ -55,9 +61,9 @@ instance Arbitrary JSValue where
       [ (1, pure JSNull)
       , (1, JSBool   <$> arbitrary)
       , (2, JSNum    <$> arbitrary)
-      , (2, JSString . getASCIIString <$> arbitrary)
+      , (2, JSString . sanitizeString . getASCIIString <$> arbitrary)
       , (3, JSArray                <$> resize (sz `div` 2) arbitrary)
-      , (3, JSObject . mapFirst getASCIIString .  noDupFields <$> resize (sz `div` 2) arbitrary)
+      , (3, JSObject . mapFirst (sanitizeString . getASCIIString) .  noDupFields <$> resize (sz `div` 2) arbitrary)
       ]
     where
       noDupFields = nubBy (\(x,_) (y,_) -> x==y)

Mikolaj added a commit to Mikolaj/hackage-security that referenced this issue Jan 12, 2022
Mikolaj added a commit to Mikolaj/hackage-security that referenced this issue Jan 12, 2022
Mikolaj added a commit to Mikolaj/hackage-security that referenced this issue Jan 12, 2022
@Mikolaj
Copy link
Member

Mikolaj commented Jan 12, 2022

Hi! Thank you very much for the report and for the patch. I hope this is fixed now.

I'm planning to release a new version of hackage-security RSN. Could you check the current codebase works for you and nothing extremely urgent is missing? Thank you!

@Bodigrim
Copy link
Contributor

It would be nice to support aeson-2.0 in tests:

+#if MIN_VERSION_aeson(2,0,0)
+import qualified Data.Aeson.KeyMap as KM
+#else
 import qualified Data.HashMap.Strict as HM
+#endif
+#if MIN_VERSION_aeson(2,0,0)
+toAeson (JSObject xs) = Object $ KM.fromList [ (fromString k, toAeson v) | (k, v) <- xs ]
+#else
 toAeson (JSObject xs) = Object $ HM.fromList [ (fromString k, toAeson v) | (k, v) <- xs ]
+#endif

@Mikolaj
Copy link
Member

Mikolaj commented Jan 13, 2022

Sure, I'd merge it. Would you create a PR?

@Mikolaj
Copy link
Member

Mikolaj commented Jan 13, 2022

@Bodigrim: thank you for the #258 to support aeson-2.0 in tests. Merged.

@Mikolaj
Copy link
Member

Mikolaj commented Jan 17, 2022

https://hackage.haskell.org/package/hackage-security-0.6.1.0 is released and the test failures are gone. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants