1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
{-# LANGUAGE QuasiQuotes #-}
module Network.OAuth.OAuth2.TokenRequestSpec where
import Data.Aeson qualified as Aeson
import Network.OAuth.OAuth2.TokenRequest
import Test.Hspec
import URI.ByteString.QQ
import Prelude hiding (error)
spec :: Spec
spec = do
describe "parseJSON TokenResponseErrorCode" $ do
it "invalid_request" $ do
Aeson.eitherDecode "\"invalid_request\"" `shouldBe` Right InvalidRequest
it "invalid_client" $ do
Aeson.eitherDecode "\"invalid_client\"" `shouldBe` Right InvalidClient
it "invalid_grant" $ do
Aeson.eitherDecode "\"invalid_grant\"" `shouldBe` Right InvalidGrant
it "unauthorized_client" $ do
Aeson.eitherDecode "\"unauthorized_client\"" `shouldBe` Right UnauthorizedClient
it "unsupported_grant_type" $ do
Aeson.eitherDecode "\"unsupported_grant_type\"" `shouldBe` Right UnsupportedGrantType
it "invalid_scope" $ do
Aeson.eitherDecode "\"invalid_scope\"" `shouldBe` Right InvalidScope
it "foo_code" $ do
Aeson.eitherDecode "\"foo_code\"" `shouldBe` Right (UnknownErrorCode "foo_code")
describe "parseJSON TokenResponseError" $ do
it "parse error" $ do
Aeson.eitherDecode "{\"error\": \"invalid_request\"}"
`shouldBe` Right
( TokenResponseError
{ tokenResponseError = InvalidRequest
, tokenResponseErrorDescription = Nothing
, tokenResponseErrorUri = Nothing
}
)
it "parse error_description" $ do
Aeson.eitherDecode "{\"error\": \"invalid_request\", \"error_description\": \"token request error foo1\"}"
`shouldBe` Right
( TokenResponseError
{ tokenResponseError = InvalidRequest
, tokenResponseErrorDescription = Just "token request error foo1"
, tokenResponseErrorUri = Nothing
}
)
it "parse error_uri" $ do
Aeson.eitherDecode "{\"error\": \"invalid_request\", \"error_uri\": \"https://example.com\"}"
`shouldBe` Right
( TokenResponseError
{ tokenResponseError = InvalidRequest
, tokenResponseErrorDescription = Nothing
, tokenResponseErrorUri = Just [uri|https://example.com|]
}
)
|