Implement base64 decode of siteurl

This commit is contained in:
Rene Vergara 2022-11-28 18:35:06 -06:00
parent daa4f59faa
commit ebb87feee6
Signed by: pitmutt
GPG key ID: 65122AD495A7F5B2
4 changed files with 16 additions and 5 deletions

View file

@ -53,6 +53,7 @@ library:
- scientific
- jwt
- containers
- base64-bytestring
executables:
zgo-backend-exe:

View file

@ -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

View file

@ -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

View file

@ -45,6 +45,7 @@ library
, aeson
, array
, base >=4.7 && <5
, base64-bytestring
, bson
, bytestring
, configurator