Fix tests expected responses due to changes in pg11 (#1268)
This commit is contained in:
committed by
Steve Chávez
parent
b53e8932e5
commit
32725f2f35
@@ -374,6 +374,9 @@ pgVersion96 = PgVersion 90600 "9.6"
|
|||||||
pgVersion100 :: PgVersion
|
pgVersion100 :: PgVersion
|
||||||
pgVersion100 = PgVersion 100000 "10"
|
pgVersion100 = PgVersion 100000 "10"
|
||||||
|
|
||||||
|
pgVersion112 :: PgVersion
|
||||||
|
pgVersion112 = PgVersion 110002 "11.2"
|
||||||
|
|
||||||
sourceCTEName :: SqlFragment
|
sourceCTEName :: SqlFragment
|
||||||
sourceCTEName = "pg_source"
|
sourceCTEName = "pg_source"
|
||||||
|
|
||||||
|
|||||||
@@ -11,16 +11,27 @@ import Network.Wai (Application)
|
|||||||
|
|
||||||
import Protolude hiding (get)
|
import Protolude hiding (get)
|
||||||
|
|
||||||
spec :: SpecWith Application
|
import PostgREST.Types (PgVersion, pgVersion112)
|
||||||
spec = describe "authorization" $ do
|
|
||||||
|
spec :: PgVersion -> SpecWith Application
|
||||||
|
spec actualPgVersion = describe "authorization" $ do
|
||||||
let single = ("Accept","application/vnd.pgrst.object+json")
|
let single = ("Accept","application/vnd.pgrst.object+json")
|
||||||
|
|
||||||
it "denies access to tables that anonymous does not own" $
|
it "denies access to tables that anonymous does not own" $
|
||||||
get "/authors_only" `shouldRespondWith` [json| {
|
get "/authors_only" `shouldRespondWith` (
|
||||||
|
if actualPgVersion >= pgVersion112 then
|
||||||
|
[json| {
|
||||||
|
"hint":null,
|
||||||
|
"details":null,
|
||||||
|
"code":"42501",
|
||||||
|
"message":"permission denied for table authors_only"} |]
|
||||||
|
else
|
||||||
|
[json| {
|
||||||
"hint":null,
|
"hint":null,
|
||||||
"details":null,
|
"details":null,
|
||||||
"code":"42501",
|
"code":"42501",
|
||||||
"message":"permission denied for relation authors_only"} |]
|
"message":"permission denied for relation authors_only"} |]
|
||||||
|
)
|
||||||
{ matchStatus = 401
|
{ matchStatus = 401
|
||||||
, matchHeaders = ["WWW-Authenticate" <:> "Bearer"]
|
, matchHeaders = ["WWW-Authenticate" <:> "Bearer"]
|
||||||
}
|
}
|
||||||
@@ -28,11 +39,20 @@ spec = describe "authorization" $ do
|
|||||||
it "denies access to tables that postgrest_test_author does not own" $
|
it "denies access to tables that postgrest_test_author does not own" $
|
||||||
let auth = authHeaderJWT "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoicG9zdGdyZXN0X3Rlc3RfYXV0aG9yIn0.Xod-F15qsGL0WhdOCr2j3DdKuTw9QJERVgoFD3vGaWA" in
|
let auth = authHeaderJWT "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoicG9zdGdyZXN0X3Rlc3RfYXV0aG9yIn0.Xod-F15qsGL0WhdOCr2j3DdKuTw9QJERVgoFD3vGaWA" in
|
||||||
request methodGet "/private_table" [auth] ""
|
request methodGet "/private_table" [auth] ""
|
||||||
`shouldRespondWith` [json| {
|
`shouldRespondWith` (
|
||||||
|
if actualPgVersion >= pgVersion112 then
|
||||||
|
[json| {
|
||||||
|
"hint":null,
|
||||||
|
"details":null,
|
||||||
|
"code":"42501",
|
||||||
|
"message":"permission denied for table private_table"} |]
|
||||||
|
else
|
||||||
|
[json| {
|
||||||
"hint":null,
|
"hint":null,
|
||||||
"details":null,
|
"details":null,
|
||||||
"code":"42501",
|
"code":"42501",
|
||||||
"message":"permission denied for relation private_table"} |]
|
"message":"permission denied for relation private_table"} |]
|
||||||
|
)
|
||||||
{ matchStatus = 403
|
{ matchStatus = 403
|
||||||
, matchHeaders = []
|
, matchHeaders = []
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,8 +21,10 @@ import Network.Wai (Application)
|
|||||||
|
|
||||||
import Protolude hiding (get)
|
import Protolude hiding (get)
|
||||||
|
|
||||||
spec :: SpecWith Application
|
import PostgREST.Types (PgVersion, pgVersion112)
|
||||||
spec = do
|
|
||||||
|
spec :: PgVersion -> SpecWith Application
|
||||||
|
spec actualPgVersion = do
|
||||||
describe "Posting new record" $ do
|
describe "Posting new record" $ do
|
||||||
context "disparate json types" $ do
|
context "disparate json types" $ do
|
||||||
it "accepts disparate json types" $ do
|
it "accepts disparate json types" $ do
|
||||||
@@ -248,14 +250,23 @@ spec = do
|
|||||||
}
|
}
|
||||||
it "fails if more columns are selected" $
|
it "fails if more columns are selected" $
|
||||||
request methodPost "/limited_article_stars?select=article_id,user_id,created_at" [("Prefer", "return=representation")]
|
request methodPost "/limited_article_stars?select=article_id,user_id,created_at" [("Prefer", "return=representation")]
|
||||||
[json| {"article_id": 2, "user_id": 2} |] `shouldRespondWith`
|
[json| {"article_id": 2, "user_id": 2} |] `shouldRespondWith` (
|
||||||
[str|{"hint":null,"details":null,"code":"42501","message":"permission denied for relation limited_article_stars"}|]
|
if actualPgVersion >= pgVersion112 then
|
||||||
|
[str|{"hint":null,"details":null,"code":"42501","message":"permission denied for view limited_article_stars"}|]
|
||||||
|
else
|
||||||
|
[str|{"hint":null,"details":null,"code":"42501","message":"permission denied for relation limited_article_stars"}|]
|
||||||
|
)
|
||||||
{ matchStatus = 401
|
{ matchStatus = 401
|
||||||
, matchHeaders = []
|
, matchHeaders = []
|
||||||
}
|
}
|
||||||
it "fails if select is not specified" $
|
it "fails if select is not specified" $
|
||||||
request methodPost "/limited_article_stars" [("Prefer", "return=representation")]
|
request methodPost "/limited_article_stars" [("Prefer", "return=representation")]
|
||||||
[json| {"article_id": 3, "user_id": 1} |] `shouldRespondWith` [str|{"hint":null,"details":null,"code":"42501","message":"permission denied for relation limited_article_stars"}|]
|
[json| {"article_id": 3, "user_id": 1} |] `shouldRespondWith` (
|
||||||
|
if actualPgVersion >= pgVersion112 then
|
||||||
|
[str|{"hint":null,"details":null,"code":"42501","message":"permission denied for view limited_article_stars"}|]
|
||||||
|
else
|
||||||
|
[str|{"hint":null,"details":null,"code":"42501","message":"permission denied for relation limited_article_stars"}|]
|
||||||
|
)
|
||||||
{ matchStatus = 401
|
{ matchStatus = 401
|
||||||
, matchHeaders = []
|
, matchHeaders = []
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,8 +10,10 @@ import Network.Wai (Application)
|
|||||||
|
|
||||||
import Protolude hiding (get)
|
import Protolude hiding (get)
|
||||||
|
|
||||||
spec :: SpecWith Application
|
import PostgREST.Types (PgVersion, pgVersion112)
|
||||||
spec = describe "json and jsonb operators" $ do
|
|
||||||
|
spec :: PgVersion -> SpecWith Application
|
||||||
|
spec actualPgVersion = describe "json and jsonb operators" $ do
|
||||||
context "Shaping response with select parameter" $ do
|
context "Shaping response with select parameter" $ do
|
||||||
it "obtains a json subfield one level with casting" $
|
it "obtains a json subfield one level with casting" $
|
||||||
get "/complex_items?id=eq.1&select=settings->>foo::json" `shouldRespondWith`
|
get "/complex_items?id=eq.1&select=settings->>foo::json" `shouldRespondWith`
|
||||||
@@ -52,14 +54,28 @@ spec = describe "json and jsonb operators" $ do
|
|||||||
-- this works fine for /rpc/unexistent requests, but for this case a 500 seems more appropriate
|
-- this works fine for /rpc/unexistent requests, but for this case a 500 seems more appropriate
|
||||||
it "fails when a double arrow ->> is followed with a single arrow ->" $ do
|
it "fails when a double arrow ->> is followed with a single arrow ->" $ do
|
||||||
get "/json_arr?select=data->>c->1"
|
get "/json_arr?select=data->>c->1"
|
||||||
`shouldRespondWith` [json|
|
`shouldRespondWith` (
|
||||||
|
if actualPgVersion >= pgVersion112 then
|
||||||
|
[json|
|
||||||
|
{"hint":"No operator matches the given name and argument types. You might need to add explicit type casts.",
|
||||||
|
"details":null,"code":"42883","message":"operator does not exist: text -> integer"} |]
|
||||||
|
else
|
||||||
|
[json|
|
||||||
{"hint":"No operator matches the given name and argument type(s). You might need to add explicit type casts.",
|
{"hint":"No operator matches the given name and argument type(s). You might need to add explicit type casts.",
|
||||||
"details":null,"code":"42883","message":"operator does not exist: text -> integer"} |]
|
"details":null,"code":"42883","message":"operator does not exist: text -> integer"} |]
|
||||||
|
)
|
||||||
{ matchStatus = 404 , matchHeaders = [] }
|
{ matchStatus = 404 , matchHeaders = [] }
|
||||||
get "/json_arr?select=data->>c->b"
|
get "/json_arr?select=data->>c->b"
|
||||||
`shouldRespondWith` [json|
|
`shouldRespondWith` (
|
||||||
|
if actualPgVersion >= pgVersion112 then
|
||||||
|
[json|
|
||||||
|
{"hint":"No operator matches the given name and argument types. You might need to add explicit type casts.",
|
||||||
|
"details":null,"code":"42883","message":"operator does not exist: text -> unknown"} |]
|
||||||
|
else
|
||||||
|
[json|
|
||||||
{"hint":"No operator matches the given name and argument type(s). You might need to add explicit type casts.",
|
{"hint":"No operator matches the given name and argument type(s). You might need to add explicit type casts.",
|
||||||
"details":null,"code":"42883","message":"operator does not exist: text -> unknown"} |]
|
"details":null,"code":"42883","message":"operator does not exist: text -> unknown"} |]
|
||||||
|
)
|
||||||
{ matchStatus = 404 , matchHeaders = [] }
|
{ matchStatus = 404 , matchHeaders = [] }
|
||||||
|
|
||||||
context "with array index" $ do
|
context "with array index" $ do
|
||||||
|
|||||||
+3
-3
@@ -80,12 +80,12 @@ main = do
|
|||||||
[("Feature.PgVersion96Spec", Feature.PgVersion96Spec.spec) | actualPgVersion >= pgVersion96]
|
[("Feature.PgVersion96Spec", Feature.PgVersion96Spec.spec) | actualPgVersion >= pgVersion96]
|
||||||
|
|
||||||
specs = uncurry describe <$> [
|
specs = uncurry describe <$> [
|
||||||
("Feature.AuthSpec" , Feature.AuthSpec.spec)
|
("Feature.AuthSpec" , Feature.AuthSpec.spec actualPgVersion)
|
||||||
, ("Feature.ConcurrentSpec" , Feature.ConcurrentSpec.spec)
|
, ("Feature.ConcurrentSpec" , Feature.ConcurrentSpec.spec)
|
||||||
, ("Feature.CorsSpec" , Feature.CorsSpec.spec)
|
, ("Feature.CorsSpec" , Feature.CorsSpec.spec)
|
||||||
, ("Feature.DeleteSpec" , Feature.DeleteSpec.spec)
|
, ("Feature.DeleteSpec" , Feature.DeleteSpec.spec)
|
||||||
, ("Feature.InsertSpec" , Feature.InsertSpec.spec)
|
, ("Feature.InsertSpec" , Feature.InsertSpec.spec actualPgVersion)
|
||||||
, ("Feature.JsonOperatorSpec" , Feature.JsonOperatorSpec.spec)
|
, ("Feature.JsonOperatorSpec" , Feature.JsonOperatorSpec.spec actualPgVersion)
|
||||||
, ("Feature.QuerySpec" , Feature.QuerySpec.spec)
|
, ("Feature.QuerySpec" , Feature.QuerySpec.spec)
|
||||||
, ("Feature.RpcSpec" , Feature.RpcSpec.spec)
|
, ("Feature.RpcSpec" , Feature.RpcSpec.spec)
|
||||||
, ("Feature.RangeSpec" , Feature.RangeSpec.spec)
|
, ("Feature.RangeSpec" , Feature.RangeSpec.spec)
|
||||||
|
|||||||
Reference in New Issue
Block a user