Implement base64 decode of siteurl
This commit is contained in:
parent
daa4f59faa
commit
ebb87feee6
4 changed files with 16 additions and 5 deletions
|
@ -53,6 +53,7 @@ library:
|
||||||
- scientific
|
- scientific
|
||||||
- jwt
|
- jwt
|
||||||
- containers
|
- containers
|
||||||
|
- base64-bytestring
|
||||||
|
|
||||||
executables:
|
executables:
|
||||||
zgo-backend-exe:
|
zgo-backend-exe:
|
||||||
|
|
|
@ -4,8 +4,12 @@ module WooCommerce where
|
||||||
|
|
||||||
import Data.Aeson
|
import Data.Aeson
|
||||||
import qualified Data.Bson as B
|
import qualified Data.Bson as B
|
||||||
|
import qualified Data.ByteString.Base64 as B64
|
||||||
|
import qualified Data.ByteString.Char8 as C
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
|
import qualified Data.Text.Encoding as E
|
||||||
|
import Data.Text.Encoding.Error (lenientDecode)
|
||||||
import Database.MongoDB
|
import Database.MongoDB
|
||||||
|
|
||||||
-- | Type to represent the WooCommerce token
|
-- | Type to represent the WooCommerce token
|
||||||
|
@ -28,7 +32,12 @@ instance Val WooToken where
|
||||||
o <- B.lookup "owner" d
|
o <- B.lookup "owner" d
|
||||||
t <- B.lookup "token" d
|
t <- B.lookup "token" d
|
||||||
u <- B.lookup "url" 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
|
cast' _ = Nothing
|
||||||
|
|
||||||
-- Database actions
|
-- Database actions
|
||||||
|
|
|
@ -259,7 +259,7 @@ main = do
|
||||||
"/api/auth/"
|
"/api/auth/"
|
||||||
[ ("ownerid", Just "62cca13f5530331e2a900001")
|
[ ("ownerid", Just "62cca13f5530331e2a900001")
|
||||||
, ("token", Just "89bd9d8d69a674e0f467cc8796ed151a")
|
, ("token", Just "89bd9d8d69a674e0f467cc8796ed151a")
|
||||||
, ("siteurl", Just "testyMcTest")
|
, ("siteurl", Just "aHR0cHM6Ly93d3cudGVjcHJvdmFsLmNvbS8")
|
||||||
]
|
]
|
||||||
res <- httpJSON req
|
res <- httpJSON req
|
||||||
getResponseStatus (res :: Response A.Value) `shouldBe` accepted202
|
getResponseStatus (res :: Response A.Value) `shouldBe` accepted202
|
||||||
|
@ -269,7 +269,7 @@ main = do
|
||||||
"/api/auth/"
|
"/api/auth/"
|
||||||
[ ("ownerid", Just "62cca13f5530331e2a97c78e")
|
[ ("ownerid", Just "62cca13f5530331e2a97c78e")
|
||||||
, ("token", Just "89bd9d8d69a674e0f467cc8796000000")
|
, ("token", Just "89bd9d8d69a674e0f467cc8796000000")
|
||||||
, ("siteurl", Just "testyMcTest")
|
, ("siteurl", Just "aHR0cHM6Ly93d3cudGVjcHJvdmFsLmNvbS8")
|
||||||
]
|
]
|
||||||
res <- httpJSON req
|
res <- httpJSON req
|
||||||
getResponseStatus (res :: Response A.Value) `shouldBe` accepted202
|
getResponseStatus (res :: Response A.Value) `shouldBe` accepted202
|
||||||
|
@ -279,7 +279,7 @@ main = do
|
||||||
"/api/auth/"
|
"/api/auth/"
|
||||||
[ ("ownerid", Just "62cca13f5530331e2a97c78e")
|
[ ("ownerid", Just "62cca13f5530331e2a97c78e")
|
||||||
, ("token", Just "89bd9d8d69a674e0f467cc8796ed151a")
|
, ("token", Just "89bd9d8d69a674e0f467cc8796ed151a")
|
||||||
, ("siteurl", Just "testyMcTest")
|
, ("siteurl", Just "aHR0cHM6Ly93d3cudGVjcHJvdmFsLmNvbS8")
|
||||||
]
|
]
|
||||||
res <- httpJSON req
|
res <- httpJSON req
|
||||||
getResponseStatus (res :: Response A.Value) `shouldBe` ok200
|
getResponseStatus (res :: Response A.Value) `shouldBe` ok200
|
||||||
|
@ -289,7 +289,7 @@ main = do
|
||||||
"/api/auth/"
|
"/api/auth/"
|
||||||
[ ("ownerid", Just "62cca13f5530331e2a97c78e")
|
[ ("ownerid", Just "62cca13f5530331e2a97c78e")
|
||||||
, ("token", Just "89bd9d8d69a674e0f467cc8796ed151a")
|
, ("token", Just "89bd9d8d69a674e0f467cc8796ed151a")
|
||||||
, ("siteurl", Just "testyMcTest")
|
, ("siteurl", Just "aHR0cHM6Ly93d3cuZ29vZ2xlLmNvbS8")
|
||||||
]
|
]
|
||||||
res <- httpJSON req
|
res <- httpJSON req
|
||||||
getResponseStatus (res :: Response A.Value) `shouldBe` accepted202
|
getResponseStatus (res :: Response A.Value) `shouldBe` accepted202
|
||||||
|
|
|
@ -45,6 +45,7 @@ library
|
||||||
, aeson
|
, aeson
|
||||||
, array
|
, array
|
||||||
, base >=4.7 && <5
|
, base >=4.7 && <5
|
||||||
|
, base64-bytestring
|
||||||
, bson
|
, bson
|
||||||
, bytestring
|
, bytestring
|
||||||
, configurator
|
, configurator
|
||||||
|
|
Loading…
Reference in a new issue