diff --git a/postgrest.cabal b/postgrest.cabal index 63840ec09..04a4e324b 100644 --- a/postgrest.cabal +++ b/postgrest.cabal @@ -222,6 +222,7 @@ test-suite spec Feature.Auth.NoJwtSecretSpec Feature.ConcurrentSpec Feature.CorsSpec + Feature.HttpHeaderSpec Feature.ExtraSearchPathSpec Feature.NoSuperuserSpec Feature.ObservabilitySpec diff --git a/test/io/__snapshots__/test_cli/test_schema_cache_snapshot[dbRoutines].yaml b/test/io/__snapshots__/test_cli/test_schema_cache_snapshot[dbRoutines].yaml index f6b66bba6..52dfbdcc4 100644 --- a/test/io/__snapshots__/test_cli/test_schema_cache_snapshot[dbRoutines].yaml +++ b/test/io/__snapshots__/test_cli/test_schema_cache_snapshot[dbRoutines].yaml @@ -196,23 +196,6 @@ pdSchema: public pdVolatility: Volatile -- - qiName: custom_vary_hdr - qiSchema: public - - - pdDescription: null - pdFuncSettings: [] - pdHasVariadic: false - pdName: custom_vary_hdr - pdParams: [] - pdReturnType: - contents: - contents: - qiName: void - qiSchema: pg_catalog - tag: Scalar - tag: Single - pdSchema: public - pdVolatility: Volatile - - - qiName: get_postgres_version qiSchema: public - - pdDescription: null diff --git a/test/io/fixtures/schema.sql b/test/io/fixtures/schema.sql index 85c1d274a..445e0b9dd 100644 --- a/test/io/fixtures/schema.sql +++ b/test/io/fixtures/schema.sql @@ -259,13 +259,6 @@ create or replace function notify_pgrst() returns void as $$ notify pgrst; $$ language sql; - -create or replace function custom_vary_hdr() returns void as $$ - begin - perform set_config('response.headers', '[{"Vary": "X-Test-Accept"}]', false); - end -$$ language plpgsql; - create or replace function get_work_mem() returns text as $$ select current_setting('work_mem', true); $$ language sql; diff --git a/test/io/test_io.py b/test/io/test_io.py index e771eeef3..d03198945 100644 --- a/test/io/test_io.py +++ b/test/io/test_io.py @@ -2087,26 +2087,6 @@ def test_client_error_verbosity_config(defaultenv): } -def test_vary_custom_header_set(defaultenv): - "Test default Vary header value is overridden in pre-request database function" - - env = {**defaultenv, "PGRST_DB_PRE_REQUEST": "custom_vary_hdr"} - - with run(env=env) as postgrest: - response = postgrest.session.get("/projects") - - assert response.headers["Vary"] == "X-Test-Accept" - - -def test_vary_default_header_set(defaultenv): - "Test default Vary header value matches default one" - - with run(env=defaultenv) as postgrest: - response = postgrest.session.get("/projects") - - assert response.headers["Vary"] == "Accept, Prefer, Range" - - def test_positive_pool_metric(defaultenv): "When a network failure is caused on the pg connection, pgrst_db_pool_available stays positive" diff --git a/test/spec/Feature/HttpHeaderSpec.hs b/test/spec/Feature/HttpHeaderSpec.hs new file mode 100644 index 000000000..de4883e98 --- /dev/null +++ b/test/spec/Feature/HttpHeaderSpec.hs @@ -0,0 +1,34 @@ +module Feature.HttpHeaderSpec where + +import Network.HTTP.Types +import Test.Hspec +import Test.Hspec.Wai + +import PostgREST.Config (AppConfig (..)) +import PostgREST.SchemaCache.Identifiers (QualifiedIdentifier (..)) + +import Protolude +import SpecHelper + +spec :: SpecWithConfig +spec withConfig = do + withConfig baseCfg { configDbPreRequest = Just $ QualifiedIdentifier "test" "custom_vary_hdr" } $ + describe "Test HTTP Custom Header" $ + it "Test default Vary header value is overridden in pre-request database function" $ + request methodGet "/projects" [] + "" + `shouldRespondWith` + ResponseMatcher + { matchStatus = 200 + , matchBody = MatchBody (\_ _ -> Nothing) -- match any body + , matchHeaders = [ "Vary" <:> "X-Test-Accept" ] } + + withConfig baseCfg $ describe "Test HTTP Default Header" $ + it "Test default Vary header value matches default one" $ + request methodGet "/projects" [] + "" + `shouldRespondWith` + ResponseMatcher + { matchStatus = 200 + , matchBody = MatchBody (\_ _ -> Nothing) -- match any body + , matchHeaders = [ "Vary" <:> "Accept, Prefer, Range" ] } diff --git a/test/spec/Main.hs b/test/spec/Main.hs index 435f1d640..fc68abe17 100644 --- a/test/spec/Main.hs +++ b/test/spec/Main.hs @@ -29,6 +29,7 @@ import qualified Feature.Auth.NoJwtSecretSpec import qualified Feature.ConcurrentSpec import qualified Feature.CorsSpec import qualified Feature.ExtraSearchPathSpec +import qualified Feature.HttpHeaderSpec import qualified Feature.NoSuperuserSpec import qualified Feature.ObservabilitySpec import qualified Feature.OpenApi.DisabledOpenApiSpec @@ -118,6 +119,7 @@ main = do , ("Feature.Auth.NoJwtSecretSpec" , Feature.Auth.NoJwtSecretSpec.spec) , ("Feature.ConcurrentSpec" , Feature.ConcurrentSpec.spec) , ("Feature.CorsSpec" , Feature.CorsSpec.spec) + , ("Feature.HttpHeaderSpec" , Feature.HttpHeaderSpec.spec) , ("Feature.NoSuperuserSpec" , Feature.NoSuperuserSpec.spec) , ("Feature.ObservabilitySpec" , Feature.ObservabilitySpec.spec) , ("Feature.OpenApi.DisabledOpenApiSpec" , Feature.OpenApi.DisabledOpenApiSpec.spec) diff --git a/test/spec/fixtures/schema.sql b/test/spec/fixtures/schema.sql index 9a7937e38..ca5cd0782 100644 --- a/test/spec/fixtures/schema.sql +++ b/test/spec/fixtures/schema.sql @@ -3870,3 +3870,10 @@ create table visits ( end_time timestamp, visit_type visit_type ); + + +create or replace function custom_vary_hdr() returns void as $$ + begin + perform set_config('response.headers', '[{"Vary": "X-Test-Accept"}]', false); + end +$$ language plpgsql;