-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tenant-permission tests #1694
Open
dlpzx
wants to merge
20
commits into
main
Choose a base branch
from
feat/tenant-permission-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+266
−30
Open
tenant-permission tests #1694
Changes from 10 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
3074c81
First draft manage tests for orgs
dlpzx e5c1d31
MANAGE_ORGANIZATION tests
dlpzx 463af4a
Revert "MANAGE_ORGANIZATION tests"
dlpzx 2a3238d
Revert "First draft manage tests for orgs"
dlpzx 2967ddd
Add tenant-permission-check at top level
dlpzx cee6b2b
Replace get function params with inspect
dlpzx 0bba981
Add defaults for mlstudio and notebooks creation requests
dlpzx 75d30c1
Invert logic and add assertion to check resolver is not None
dlpzx e8481d7
Merge remote-tracking branch 'origin/main' into feat/tenant-permissio…
dlpzx c87f712
Moved verification of groups inside service for worksheet creation
dlpzx 7ff6c8d
Full list of tenant-permission tests
dlpzx 0648c0f
Fix @is_enabled tests
dlpzx 2a86bbf
Added permission checks in update stack mutations
dlpzx 3450412
Added permission checks in run athena SQL query
dlpzx 501e5cd
Added permission checks in get shared dataset url
dlpzx b29cacf
Added permission checks in get author session dashboards
dlpzx 356ecdd
Added assume role tests
dlpzx be5689e
Added permissions and tests for data filters
dlpzx a447223
Added permissions and tests for data column/table operations
dlpzx 010bf74
Lint and cleanup
dlpzx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
from unittest.mock import MagicMock | ||
import pytest | ||
from assertpy import assert_that | ||
from dataall.base.api import bootstrap | ||
from dataall.base.loader import load_modules, ImportMode | ||
from dataall.base.context import RequestContext | ||
from dataall.base.db.exceptions import TenantUnauthorized | ||
import inspect | ||
|
||
|
||
load_modules(modes={ImportMode.API}) | ||
|
||
NO_CHECK_PERMS = [ | ||
'Mutation.updateGroupTenantPermissions', | ||
'Mutation.updateSSMParameter', | ||
'Mutation.createNetwork', | ||
'Mutation.deleteNetwork', | ||
'Mutation.updateStack', | ||
'Mutation.updateKeyValueTags', | ||
'Mutation.createMetadataForm', | ||
'Mutation.createMetadataFormVersion', | ||
'Mutation.createAttachedMetadataForm', | ||
'Mutation.deleteMetadataForm', | ||
'Mutation.deleteMetadataFormVersion', | ||
'Mutation.deleteAttachedMetadataForm', | ||
'Mutation.createMetadataFormFields', | ||
'Mutation.deleteMetadataFormField', | ||
'Mutation.batchMetadataFormFieldUpdates', | ||
'Mutation.startMaintenanceWindow', | ||
'Mutation.stopMaintenanceWindow', | ||
'Mutation.markNotificationAsRead', | ||
'Mutation.deleteNotification', | ||
'Mutation.postFeedMessage', | ||
'Mutation.createGlossary', | ||
'Mutation.updateGlossary', | ||
'Mutation.deleteGlossary', | ||
'Mutation.createCategory', | ||
'Mutation.updateCategory', | ||
'Mutation.deleteCategory', | ||
'Mutation.createTerm', | ||
'Mutation.updateTerm', | ||
'Mutation.deleteTerm', | ||
'Mutation.approveTermAssociation', | ||
'Mutation.dismissTermAssociation', | ||
'Mutation.startReindexCatalog', | ||
'Mutation.createShareObject', | ||
'Mutation.deleteShareObject', | ||
'Mutation.cancelShareExtension', | ||
'Mutation.addSharedItem', | ||
'Mutation.removeSharedItem', | ||
'Mutation.submitShareObject', | ||
'Mutation.submitShareExtension', | ||
'Mutation.approveShareObject', | ||
'Mutation.approveShareExtension', | ||
'Mutation.rejectShareObject', | ||
'Mutation.revokeItemsShareObject', | ||
'Mutation.verifyItemsShareObject', | ||
'Mutation.reApplyItemsShareObject', | ||
'Mutation.updateShareRejectReason', | ||
'Mutation.updateShareExpirationPeriod', | ||
'Mutation.updateShareExtensionReason', | ||
'Mutation.updateShareRequestReason', | ||
'Mutation.updateShareItemFilters', | ||
'Mutation.removeShareItemFilter', | ||
'Mutation.upVote', | ||
] | ||
|
||
CHECK_PERMS = [ | ||
'Mutation.createOrganization', | ||
'Mutation.updateOrganization', | ||
'Mutation.archiveOrganization', | ||
'Mutation.inviteGroupToOrganization', | ||
'Mutation.updateOrganizationGroup', | ||
'Mutation.removeGroupFromOrganization', | ||
'Mutation.createEnvironment', | ||
'Mutation.updateEnvironment', | ||
'Mutation.inviteGroupOnEnvironment', | ||
'Mutation.addConsumptionRoleToEnvironment', | ||
'Mutation.updateGroupEnvironmentPermissions', | ||
'Mutation.removeGroupFromEnvironment', | ||
'Mutation.removeConsumptionRoleFromEnvironment', | ||
'Mutation.deleteEnvironment', | ||
'Mutation.enableDataSubscriptions', | ||
'Mutation.DisableDataSubscriptions', | ||
'Mutation.updateConsumptionRole', | ||
'Mutation.createSagemakerStudioUser', | ||
'Mutation.deleteSagemakerStudioUser', | ||
'Mutation.createSagemakerNotebook', | ||
'Mutation.startSagemakerNotebook', | ||
'Mutation.stopSagemakerNotebook', | ||
'Mutation.deleteSagemakerNotebook', | ||
# 'Mutation.syncDatasetTableColumns', | ||
# 'Mutation.updateDatasetTableColumn', | ||
# 'Mutation.startDatasetProfilingRun', | ||
# 'Mutation.createDatasetStorageLocation', | ||
# 'Mutation.updateDatasetStorageLocation', | ||
# 'Mutation.deleteDatasetStorageLocation', | ||
# 'Mutation.createDataset', | ||
# 'Mutation.updateDataset', | ||
# 'Mutation.generateDatasetAccessToken', | ||
# 'Mutation.deleteDataset', | ||
# 'Mutation.importDataset', | ||
# 'Mutation.startGlueCrawler', | ||
# 'Mutation.updateDatasetTable', | ||
# 'Mutation.deleteDatasetTable', | ||
# 'Mutation.syncTables', | ||
# 'Mutation.createTableDataFilter', | ||
# 'Mutation.deleteTableDataFilter', | ||
# 'Mutation.createRedshiftConnection', | ||
# 'Mutation.deleteRedshiftConnection', | ||
# 'Mutation.addConnectionGroupPermission', | ||
# 'Mutation.deleteConnectionGroupPermission', | ||
# 'Mutation.importRedshiftDataset', | ||
# 'Mutation.updateRedshiftDataset', | ||
# 'Mutation.deleteRedshiftDataset', | ||
# 'Mutation.addRedshiftDatasetTables', | ||
# 'Mutation.deleteRedshiftDatasetTable', | ||
# 'Mutation.updateRedshiftDatasetTable', | ||
'Mutation.importDashboard', | ||
'Mutation.updateDashboard', | ||
'Mutation.deleteDashboard', | ||
'Mutation.requestDashboardShare', | ||
'Mutation.approveDashboardShare', | ||
'Mutation.rejectDashboardShare', | ||
# 'Mutation.createQuicksightDataSourceSet', | ||
# 'Mutation.verifyDatasetShareObjects', | ||
# 'Mutation.reApplyShareObjectItemsOnDataset', | ||
'Mutation.createWorksheet', | ||
'Mutation.updateWorksheet', | ||
'Mutation.deleteWorksheet', | ||
] | ||
|
||
ALL_RESOLVERS = { | ||
f'{_type.name}.{field.name}': field.resolver | ||
for _type in bootstrap().types | ||
for field in _type.fields | ||
if field.resolver | ||
} | ||
|
||
|
||
@pytest.mark.parametrize('name,field_resolver', [(name, ALL_RESOLVERS.get(name, None)) for name in CHECK_PERMS]) | ||
def test_unauthorized_tenant_permissions( | ||
name, field_resolver, mocker, db, userNoTenantPermissions, groupNoTenantPermissions | ||
): | ||
assert_that(field_resolver).is_not_none() | ||
mock_local = MagicMock() | ||
mock_local.context = RequestContext( | ||
db, userNoTenantPermissions.username, [groupNoTenantPermissions.groupUri], userNoTenantPermissions | ||
) | ||
with mocker.patch('dataall.base.context._request_storage', mock_local): | ||
print(inspect.signature(field_resolver).parameters.keys()) | ||
iargs = {arg: MagicMock() for arg in inspect.signature(field_resolver).parameters.keys()} | ||
assert_that(field_resolver).raises(TenantUnauthorized).when_called_with(**iargs).contains( | ||
'UnauthorizedOperation' | ||
) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this to say Operations like
createNetwork
anddeleteNetwork
do not haveMANAGE_XXXX
checks on them? They do haveMANAGE_ENVIRONMENTS
... and I think a handful of tohers on this list are simialrOr are these mutations that would need some additional work on the backend app logic side to conform to this pattern?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of things,
inspect