diff --git a/package.yaml b/package.yaml index 8a9115b..60ffd59 100644 --- a/package.yaml +++ b/package.yaml @@ -53,6 +53,7 @@ library: - scientific - jwt - containers + - base64-bytestring executables: zgo-backend-exe: diff --git a/src/WooCommerce.hs b/src/WooCommerce.hs index 18eab33..566765d 100644 --- a/src/WooCommerce.hs +++ b/src/WooCommerce.hs @@ -4,8 +4,12 @@ module WooCommerce where import Data.Aeson import qualified Data.Bson as B +import qualified Data.ByteString.Base64 as B64 +import qualified Data.ByteString.Char8 as C import Data.Maybe import qualified Data.Text as T +import qualified Data.Text.Encoding as E +import Data.Text.Encoding.Error (lenientDecode) import Database.MongoDB -- | Type to represent the WooCommerce token @@ -28,7 +32,12 @@ instance Val WooToken where o <- B.lookup "owner" d t <- B.lookup "token" d u <- B.lookup "url" d - Just (WooToken i o t u) + Just + (WooToken + i + o + t + (E.decodeUtf8With lenientDecode . B64.decodeLenient . C.pack <$> u)) cast' _ = Nothing -- Database actions diff --git a/test/Spec.hs b/test/Spec.hs index 15d5aa5..e87364d 100644 --- a/test/Spec.hs +++ b/test/Spec.hs @@ -259,7 +259,7 @@ main = do "/api/auth/" [ ("ownerid", Just "62cca13f5530331e2a900001") , ("token", Just "89bd9d8d69a674e0f467cc8796ed151a") - , ("siteurl", Just "testyMcTest") + , ("siteurl", Just "aHR0cHM6Ly93d3cudGVjcHJvdmFsLmNvbS8") ] res <- httpJSON req getResponseStatus (res :: Response A.Value) `shouldBe` accepted202 @@ -269,7 +269,7 @@ main = do "/api/auth/" [ ("ownerid", Just "62cca13f5530331e2a97c78e") , ("token", Just "89bd9d8d69a674e0f467cc8796000000") - , ("siteurl", Just "testyMcTest") + , ("siteurl", Just "aHR0cHM6Ly93d3cudGVjcHJvdmFsLmNvbS8") ] res <- httpJSON req getResponseStatus (res :: Response A.Value) `shouldBe` accepted202 @@ -279,7 +279,7 @@ main = do "/api/auth/" [ ("ownerid", Just "62cca13f5530331e2a97c78e") , ("token", Just "89bd9d8d69a674e0f467cc8796ed151a") - , ("siteurl", Just "testyMcTest") + , ("siteurl", Just "aHR0cHM6Ly93d3cudGVjcHJvdmFsLmNvbS8") ] res <- httpJSON req getResponseStatus (res :: Response A.Value) `shouldBe` ok200 @@ -289,7 +289,7 @@ main = do "/api/auth/" [ ("ownerid", Just "62cca13f5530331e2a97c78e") , ("token", Just "89bd9d8d69a674e0f467cc8796ed151a") - , ("siteurl", Just "testyMcTest") + , ("siteurl", Just "aHR0cHM6Ly93d3cuZ29vZ2xlLmNvbS8") ] res <- httpJSON req getResponseStatus (res :: Response A.Value) `shouldBe` accepted202 diff --git a/zgo-backend.cabal b/zgo-backend.cabal index 7eb6053..a57aaf1 100644 --- a/zgo-backend.cabal +++ b/zgo-backend.cabal @@ -45,6 +45,7 @@ library , aeson , array , base >=4.7 && <5 + , base64-bytestring , bson , bytestring , configurator