Remove *Source fields from API test permissions

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/7275
GitOrigin-RevId: 44345ec361fdbb93f2c166825e5d78983759b5b0
This commit is contained in:
Tom Harding 2022-12-14 18:42:24 +00:00 committed by hasura-bot
parent beb20c7dab
commit f2dd4a5eb7
6 changed files with 23 additions and 39 deletions

View File

@ -14,12 +14,10 @@ module Test.Queries.FilterSearch.AggregationPredicatesSpec (spec) where
import Data.Aeson (Value) import Data.Aeson (Value)
import Data.List.NonEmpty qualified as NE import Data.List.NonEmpty qualified as NE
import Data.Text qualified as Text
import Harness.Backend.Postgres qualified as Postgres import Harness.Backend.Postgres qualified as Postgres
import Harness.GraphqlEngine (postGraphql, postGraphqlWithHeaders) import Harness.GraphqlEngine (postGraphql, postGraphqlWithHeaders)
import Harness.Quoter.Graphql (graphql) import Harness.Quoter.Graphql (graphql)
import Harness.Quoter.Yaml (interpolateYaml, yaml) import Harness.Quoter.Yaml (interpolateYaml, yaml)
import Harness.Test.BackendType qualified as BackendType
import Harness.Test.Fixture qualified as Fixture import Harness.Test.Fixture qualified as Fixture
import Harness.Test.Permissions (Permission (SelectPermission), SelectPermissionDetails (..), selectPermission) import Harness.Test.Permissions (Permission (SelectPermission), SelectPermissionDetails (..), selectPermission)
import Harness.Test.Schema (Table (..), table) import Harness.Test.Schema (Table (..), table)
@ -39,7 +37,7 @@ spec = do
[ (Fixture.fixture $ Fixture.Backend Postgres.backendTypeMetadata) [ (Fixture.fixture $ Fixture.Backend Postgres.backendTypeMetadata)
{ Fixture.setupTeardown = \(testEnv, _) -> { Fixture.setupTeardown = \(testEnv, _) ->
[ Postgres.setupTablesAction schema testEnv, [ Postgres.setupTablesAction schema testEnv,
Postgres.setupPermissionsAction (permissions Postgres.backendTypeMetadata) testEnv Postgres.setupPermissionsAction permissions testEnv
] ]
} }
] ]
@ -80,19 +78,17 @@ schema =
} }
] ]
permissions :: BackendType.BackendTypeConfig -> [Permission] permissions :: [Permission]
permissions backend = permissions =
[ SelectPermission [ SelectPermission
selectPermission selectPermission
{ selectPermissionTable = "author", { selectPermissionTable = "author",
selectPermissionSource = Text.pack $ BackendType.backendSourceName backend,
selectPermissionRole = "role-select-author-name-only", selectPermissionRole = "role-select-author-name-only",
selectPermissionColumns = ["id", "name"] selectPermissionColumns = ["id", "name"]
}, },
SelectPermission SelectPermission
selectPermission selectPermission
{ selectPermissionTable = "article", { selectPermissionTable = "article",
selectPermissionSource = Text.pack $ BackendType.backendSourceName backend,
selectPermissionRole = "role-select-author-name-only", selectPermissionRole = "role-select-author-name-only",
selectPermissionColumns = ["id", "title", "author_id"], selectPermissionColumns = ["id", "title", "author_id"],
selectPermissionRows = selectPermissionRows =
@ -104,14 +100,12 @@ permissions backend =
SelectPermission SelectPermission
selectPermission selectPermission
{ selectPermissionTable = "author", { selectPermissionTable = "author",
selectPermissionSource = Text.pack $ BackendType.backendSourceName backend,
selectPermissionRole = "disallow-aggregation-queries", selectPermissionRole = "disallow-aggregation-queries",
selectPermissionColumns = ["id", "name"] selectPermissionColumns = ["id", "name"]
}, },
SelectPermission SelectPermission
selectPermission selectPermission
{ selectPermissionTable = "article", { selectPermissionTable = "article",
selectPermissionSource = Text.pack $ BackendType.backendSourceName backend,
selectPermissionRole = "disallow-aggregation-queries", selectPermissionRole = "disallow-aggregation-queries",
selectPermissionColumns = ["id", "title", "author_id"], selectPermissionColumns = ["id", "title", "author_id"],
selectPermissionAllowAggregations = False selectPermissionAllowAggregations = False

View File

@ -66,7 +66,6 @@ updatePermission =
Permissions.UpdatePermission Permissions.UpdatePermission
Permissions.updatePermission Permissions.updatePermission
{ Permissions.updatePermissionTable = authorTableName, { Permissions.updatePermissionTable = authorTableName,
Permissions.updatePermissionSource = "postgres",
Permissions.updatePermissionRole = "user", Permissions.updatePermissionRole = "user",
Permissions.updatePermissionColumns = ["age"] Permissions.updatePermissionColumns = ["age"]
} }

View File

@ -29,19 +29,19 @@ spec = do
[ (Fixture.fixture $ Fixture.Backend Postgres.backendTypeMetadata) [ (Fixture.fixture $ Fixture.Backend Postgres.backendTypeMetadata)
{ Fixture.setupTeardown = \(testEnvironment, _) -> { Fixture.setupTeardown = \(testEnvironment, _) ->
[ Postgres.setupTablesAction schema testEnvironment, [ Postgres.setupTablesAction schema testEnvironment,
Postgres.setupPermissionsAction (permissions "postgres") testEnvironment Postgres.setupPermissionsAction permissions testEnvironment
] ]
}, },
(Fixture.fixture $ Fixture.Backend Citus.backendTypeMetadata) (Fixture.fixture $ Fixture.Backend Citus.backendTypeMetadata)
{ Fixture.setupTeardown = \(testEnvironment, _) -> { Fixture.setupTeardown = \(testEnvironment, _) ->
[ Citus.setupTablesAction schema testEnvironment, [ Citus.setupTablesAction schema testEnvironment,
Citus.setupPermissionsAction (permissions "citus") testEnvironment Citus.setupPermissionsAction permissions testEnvironment
] ]
}, },
(Fixture.fixture $ Fixture.Backend Cockroach.backendTypeMetadata) (Fixture.fixture $ Fixture.Backend Cockroach.backendTypeMetadata)
{ Fixture.setupTeardown = \(testEnvironment, _) -> { Fixture.setupTeardown = \(testEnvironment, _) ->
[ Cockroach.setupTablesAction schema testEnvironment, [ Cockroach.setupTablesAction schema testEnvironment,
Cockroach.setupPermissionsAction (permissions "cockroach") testEnvironment Cockroach.setupPermissionsAction permissions testEnvironment
] ]
} }
] ]
@ -70,19 +70,17 @@ schema =
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
-- Permissions -- Permissions
permissions :: Text -> [Permission] permissions :: [Permission]
permissions source = permissions =
[ SelectPermission [ SelectPermission
selectPermission selectPermission
{ selectPermissionTable = "foo", { selectPermissionTable = "foo",
selectPermissionSource = source,
selectPermissionRole = "role-select-only", selectPermissionRole = "role-select-only",
selectPermissionColumns = ["id", "bar"] selectPermissionColumns = ["id", "bar"]
}, },
InsertPermission InsertPermission
insertPermission insertPermission
{ insertPermissionTable = "foo", { insertPermissionTable = "foo",
insertPermissionSource = source,
insertPermissionRole = "role-insert-only", insertPermissionRole = "role-insert-only",
insertPermissionColumns = ["id", "bar"] insertPermissionColumns = ["id", "bar"]
} }

View File

@ -232,8 +232,7 @@ setupMetadata testEnvironment =
testEnvironment testEnvironment
$ SelectPermission $ SelectPermission
selectPermission selectPermission
{ selectPermissionSource = T.pack source, { selectPermissionTable = "author",
selectPermissionTable = "author",
selectPermissionRole = "user_1", selectPermissionRole = "user_1",
selectPermissionColumns = (["id", "name"] :: [Text]) selectPermissionColumns = (["id", "name"] :: [Text])
}, },
@ -245,8 +244,7 @@ setupMetadata testEnvironment =
testEnvironment testEnvironment
$ SelectPermission $ SelectPermission
selectPermission selectPermission
{ selectPermissionSource = T.pack source, { selectPermissionTable = "article",
selectPermissionTable = "article",
selectPermissionRole = "user_1", selectPermissionRole = "user_1",
selectPermissionColumns = (["id", "title", "content", "author_id"] :: [Text]) selectPermissionColumns = (["id", "title", "content", "author_id"] :: [Text])
}, },
@ -259,8 +257,7 @@ setupMetadata testEnvironment =
testEnvironment testEnvironment
$ SelectPermission $ SelectPermission
selectPermission selectPermission
{ selectPermissionSource = T.pack source, { selectPermissionTable = "author",
selectPermissionTable = "author",
selectPermissionRole = "user_2", selectPermissionRole = "user_2",
selectPermissionColumns = (["id", "name"] :: [Text]) selectPermissionColumns = (["id", "name"] :: [Text])
}, },

View File

@ -192,7 +192,6 @@ lhsRole1 =
Permissions.SelectPermission Permissions.SelectPermission
Permissions.selectPermission Permissions.selectPermission
{ selectPermissionRole = "role1", { selectPermissionRole = "role1",
selectPermissionSource = lhsSourceName_,
selectPermissionTable = lhsTableName_, selectPermissionTable = lhsTableName_,
selectPermissionColumns = (["id", "name"] :: [Text]) selectPermissionColumns = (["id", "name"] :: [Text])
} }
@ -202,7 +201,6 @@ lhsRole2 =
Permissions.SelectPermission Permissions.SelectPermission
Permissions.selectPermission Permissions.selectPermission
{ selectPermissionRole = "role2", { selectPermissionRole = "role2",
selectPermissionSource = lhsSourceName_,
selectPermissionTable = lhsTableName_, selectPermissionTable = lhsTableName_,
selectPermissionColumns = (["id", "name"] :: [Text]) selectPermissionColumns = (["id", "name"] :: [Text])
} }
@ -260,7 +258,6 @@ rhsRole1 =
Permissions.SelectPermission Permissions.SelectPermission
Permissions.selectPermission Permissions.selectPermission
{ selectPermissionRole = "role1", { selectPermissionRole = "role1",
selectPermissionSource = rhsSourceName_,
selectPermissionTable = rhsTableName_, selectPermissionTable = rhsTableName_,
selectPermissionColumns = (["title", "artist_id"] :: [Text]), selectPermissionColumns = (["title", "artist_id"] :: [Text]),
selectPermissionRows = selectPermissionRows =
@ -275,7 +272,6 @@ rhsRole2 =
Permissions.SelectPermission Permissions.SelectPermission
Permissions.selectPermission Permissions.selectPermission
{ selectPermissionRole = "role2", { selectPermissionRole = "role2",
selectPermissionSource = rhsSourceName_,
selectPermissionTable = rhsTableName_, selectPermissionTable = rhsTableName_,
selectPermissionColumns = (["id", "title", "artist_id"] :: [Text]), selectPermissionColumns = (["id", "title", "artist_id"] :: [Text]),
selectPermissionAllowAggregations = True, selectPermissionAllowAggregations = True,

View File

@ -39,7 +39,6 @@ data Permission
data SelectPermissionDetails = SelectPermissionDetails data SelectPermissionDetails = SelectPermissionDetails
{ selectPermissionTable :: Text, { selectPermissionTable :: Text,
selectPermissionSource :: Text,
selectPermissionRole :: Text, selectPermissionRole :: Text,
selectPermissionColumns :: [Text], selectPermissionColumns :: [Text],
selectPermissionRows :: Aeson.Value, selectPermissionRows :: Aeson.Value,
@ -49,7 +48,6 @@ data SelectPermissionDetails = SelectPermissionDetails
data UpdatePermissionDetails = UpdatePermissionDetails data UpdatePermissionDetails = UpdatePermissionDetails
{ updatePermissionTable :: Text, { updatePermissionTable :: Text,
updatePermissionSource :: Text,
updatePermissionRole :: Text, updatePermissionRole :: Text,
updatePermissionColumns :: [Text], updatePermissionColumns :: [Text],
updatePermissionRows :: Aeson.Value updatePermissionRows :: Aeson.Value
@ -57,7 +55,6 @@ data UpdatePermissionDetails = UpdatePermissionDetails
data InsertPermissionDetails = InsertPermissionDetails data InsertPermissionDetails = InsertPermissionDetails
{ insertPermissionTable :: Text, { insertPermissionTable :: Text,
insertPermissionSource :: Text,
insertPermissionRole :: Text, insertPermissionRole :: Text,
insertPermissionColumns :: [Text], insertPermissionColumns :: [Text],
insertPermissionRows :: Aeson.Value insertPermissionRows :: Aeson.Value
@ -67,7 +64,6 @@ selectPermission :: SelectPermissionDetails
selectPermission = selectPermission =
SelectPermissionDetails SelectPermissionDetails
{ selectPermissionTable = mempty, { selectPermissionTable = mempty,
selectPermissionSource = mempty,
selectPermissionRole = mempty, selectPermissionRole = mempty,
selectPermissionColumns = mempty, selectPermissionColumns = mempty,
selectPermissionRows = [yaml|{}|], selectPermissionRows = [yaml|{}|],
@ -79,7 +75,6 @@ updatePermission :: UpdatePermissionDetails
updatePermission = updatePermission =
UpdatePermissionDetails UpdatePermissionDetails
{ updatePermissionTable = mempty, { updatePermissionTable = mempty,
updatePermissionSource = mempty,
updatePermissionRole = mempty, updatePermissionRole = mempty,
updatePermissionColumns = mempty, updatePermissionColumns = mempty,
updatePermissionRows = [yaml|{}|] updatePermissionRows = [yaml|{}|]
@ -89,7 +84,6 @@ insertPermission :: InsertPermissionDetails
insertPermission = insertPermission =
InsertPermissionDetails InsertPermissionDetails
{ insertPermissionTable = mempty, { insertPermissionTable = mempty,
insertPermissionSource = mempty,
insertPermissionRole = mempty, insertPermissionRole = mempty,
insertPermissionColumns = mempty, insertPermissionColumns = mempty,
insertPermissionRows = [yaml|{}|] insertPermissionRows = [yaml|{}|]
@ -103,6 +97,7 @@ createPermission testEnvironment (InsertPermission InsertPermissionDetails {..})
let backendTypeMetadata = fromMaybe (error "Unknown backend") $ backendTypeConfig testEnvironment let backendTypeMetadata = fromMaybe (error "Unknown backend") $ backendTypeConfig testEnvironment
schemaName = Schema.getSchemaName testEnvironment schemaName = Schema.getSchemaName testEnvironment
backendType = BackendType.backendTypeString backendTypeMetadata backendType = BackendType.backendTypeString backendTypeMetadata
sourceName = BackendType.backendSourceName backendTypeMetadata
requestType = backendType <> "_create_insert_permission" requestType = backendType <> "_create_insert_permission"
qualifiedTable = Schema.mkTableField backendTypeMetadata schemaName insertPermissionTable qualifiedTable = Schema.mkTableField backendTypeMetadata schemaName insertPermissionTable
GraphqlEngine.postMetadata_ GraphqlEngine.postMetadata_
@ -111,7 +106,7 @@ createPermission testEnvironment (InsertPermission InsertPermissionDetails {..})
type: *requestType type: *requestType
args: args:
table: *qualifiedTable table: *qualifiedTable
source: *insertPermissionSource source: *sourceName
role: *insertPermissionRole role: *insertPermissionRole
permission: permission:
columns: *insertPermissionColumns columns: *insertPermissionColumns
@ -123,6 +118,7 @@ createPermission testEnvironment (UpdatePermission UpdatePermissionDetails {..})
let backendTypeMetadata = fromMaybe (error "Unknown backend") $ backendTypeConfig testEnvironment let backendTypeMetadata = fromMaybe (error "Unknown backend") $ backendTypeConfig testEnvironment
schemaName = Schema.getSchemaName testEnvironment schemaName = Schema.getSchemaName testEnvironment
backendType = BackendType.backendTypeString backendTypeMetadata backendType = BackendType.backendTypeString backendTypeMetadata
sourceName = BackendType.backendSourceName backendTypeMetadata
requestType = backendType <> "_create_update_permission" requestType = backendType <> "_create_update_permission"
qualifiedTable = Schema.mkTableField backendTypeMetadata schemaName updatePermissionTable qualifiedTable = Schema.mkTableField backendTypeMetadata schemaName updatePermissionTable
GraphqlEngine.postMetadata_ GraphqlEngine.postMetadata_
@ -131,7 +127,7 @@ createPermission testEnvironment (UpdatePermission UpdatePermissionDetails {..})
type: *requestType type: *requestType
args: args:
table: *qualifiedTable table: *qualifiedTable
source: *updatePermissionSource source: *sourceName
role: *updatePermissionRole role: *updatePermissionRole
permission: permission:
columns: *updatePermissionColumns columns: *updatePermissionColumns
@ -143,6 +139,7 @@ createPermission testEnvironment (SelectPermission SelectPermissionDetails {..})
let backendTypeMetadata = fromMaybe (error "Unknown backend") $ backendTypeConfig testEnvironment let backendTypeMetadata = fromMaybe (error "Unknown backend") $ backendTypeConfig testEnvironment
schemaName = Schema.getSchemaName testEnvironment schemaName = Schema.getSchemaName testEnvironment
backendType = BackendType.backendTypeString backendTypeMetadata backendType = BackendType.backendTypeString backendTypeMetadata
sourceName = BackendType.backendSourceName backendTypeMetadata
requestType = backendType <> "_create_select_permission" requestType = backendType <> "_create_select_permission"
qualifiedTable = Schema.mkTableField backendTypeMetadata schemaName selectPermissionTable qualifiedTable = Schema.mkTableField backendTypeMetadata schemaName selectPermissionTable
GraphqlEngine.postMetadata_ GraphqlEngine.postMetadata_
@ -151,7 +148,7 @@ createPermission testEnvironment (SelectPermission SelectPermissionDetails {..})
type: *requestType type: *requestType
args: args:
table: *qualifiedTable table: *qualifiedTable
source: *selectPermissionSource source: *sourceName
role: *selectPermissionRole role: *selectPermissionRole
permission: permission:
columns: *selectPermissionColumns columns: *selectPermissionColumns
@ -165,6 +162,7 @@ dropPermission backendTypeMetadata env (InsertPermission InsertPermissionDetails
let schemaName = Schema.getSchemaName env let schemaName = Schema.getSchemaName env
backendType = BackendType.backendTypeString backendTypeMetadata backendType = BackendType.backendTypeString backendTypeMetadata
requestType = backendType <> "_drop_insert_permission" requestType = backendType <> "_drop_insert_permission"
sourceName = BackendType.backendSourceName backendTypeMetadata
qualifiedTable = Schema.mkTableField backendTypeMetadata schemaName insertPermissionTable qualifiedTable = Schema.mkTableField backendTypeMetadata schemaName insertPermissionTable
GraphqlEngine.postMetadata_ GraphqlEngine.postMetadata_
env env
@ -172,12 +170,13 @@ dropPermission backendTypeMetadata env (InsertPermission InsertPermissionDetails
type: *requestType type: *requestType
args: args:
table: *qualifiedTable table: *qualifiedTable
source: *insertPermissionSource source: *sourceName
role: *insertPermissionRole role: *insertPermissionRole
|] |]
dropPermission backendTypeMetadata env (SelectPermission SelectPermissionDetails {..}) = do dropPermission backendTypeMetadata env (SelectPermission SelectPermissionDetails {..}) = do
let schemaName = Schema.getSchemaName env let schemaName = Schema.getSchemaName env
backendType = BackendType.backendTypeString backendTypeMetadata backendType = BackendType.backendTypeString backendTypeMetadata
sourceName = BackendType.backendSourceName backendTypeMetadata
requestType = backendType <> "_drop_select_permission" requestType = backendType <> "_drop_select_permission"
qualifiedTable = Schema.mkTableField backendTypeMetadata schemaName selectPermissionTable qualifiedTable = Schema.mkTableField backendTypeMetadata schemaName selectPermissionTable
GraphqlEngine.postMetadata_ GraphqlEngine.postMetadata_
@ -186,12 +185,13 @@ dropPermission backendTypeMetadata env (SelectPermission SelectPermissionDetails
type: *requestType type: *requestType
args: args:
table: *qualifiedTable table: *qualifiedTable
source: *selectPermissionSource source: *sourceName
role: *selectPermissionRole role: *selectPermissionRole
|] |]
dropPermission backendTypeMetadata env (UpdatePermission UpdatePermissionDetails {..}) = do dropPermission backendTypeMetadata env (UpdatePermission UpdatePermissionDetails {..}) = do
let schemaName = Schema.getSchemaName env let schemaName = Schema.getSchemaName env
backendType = BackendType.backendTypeString backendTypeMetadata backendType = BackendType.backendTypeString backendTypeMetadata
sourceName = BackendType.backendSourceName backendTypeMetadata
requestType = backendType <> "_drop_update_permission" requestType = backendType <> "_drop_update_permission"
qualifiedTable = Schema.mkTableField backendTypeMetadata schemaName updatePermissionTable qualifiedTable = Schema.mkTableField backendTypeMetadata schemaName updatePermissionTable
GraphqlEngine.postMetadata_ GraphqlEngine.postMetadata_
@ -200,7 +200,7 @@ dropPermission backendTypeMetadata env (UpdatePermission UpdatePermissionDetails
type: *requestType type: *requestType
args: args:
table: *qualifiedTable table: *qualifiedTable
source: *updatePermissionSource source: *sourceName
role: *updatePermissionRole role: *updatePermissionRole
|] |]