This repository has been archived by the owner on Jun 5, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changes to fix model creation for release 2.25.2 (#3781)
* Cherry pick model/e2e fixes from commit cf6e9d5. Update TF version used by e2e tests to avoid issue with TF versions in Forseti module. Fixcrawlertest (#3743). Fix e2e tests. Update forseticli. * Update Forseti version.
- Loading branch information
1 parent
9b5852a
commit bb8e7f0
Showing
24 changed files
with
410 additions
and
151 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# Copyright 2020 The Forseti Security Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import pytest | ||
import re | ||
from endtoend_tests.helpers.forseti_cli import ForsetiCli | ||
|
||
|
||
class TestExplainerAccessByResource: | ||
"""Explainer access_by_resource tests. | ||
TODO: Tests take a long time for explain commands, use different resources? | ||
""" | ||
|
||
@pytest.mark.client | ||
@pytest.mark.e2e | ||
@pytest.mark.explainer | ||
def test_access_by_resource_for_organization(self, forseti_cli: ForsetiCli, | ||
forseti_model_readonly, | ||
forseti_server_service_account, | ||
organization_id): | ||
"""Test access_by_resource for organization includes Forseti SA. | ||
Args: | ||
forseti_cli (ForsetiCli): Instance of the forseti cli helper | ||
forseti_model_readonly (Tuple): Model name & process result | ||
forseti_server_service_account (str): Server service account email | ||
organization_id (str): Organization id being scanned | ||
""" | ||
# Arrange | ||
model_name, _, _ = forseti_model_readonly | ||
forseti_cli.model_use(model_name=model_name) | ||
|
||
# Act | ||
result = forseti_cli.explainer_access_by_resource( | ||
f'organization/{organization_id}') | ||
|
||
# Assert | ||
assert result.returncode == 0, f'Forseti stdout: {str(result.stdout)}' | ||
assert 10 == len(re.findall(forseti_server_service_account, str(result.stdout))) | ||
|
||
@pytest.mark.client | ||
@pytest.mark.e2e | ||
@pytest.mark.explainer | ||
def test_access_by_resource_for_project(self, forseti_cli: ForsetiCli, | ||
forseti_model_readonly, | ||
forseti_server_service_account, | ||
project_id): | ||
"""Test access_by_resource for project includes Forseti SA. | ||
Args: | ||
forseti_cli (ForsetiCli): Instance of the forseti cli helper | ||
forseti_model_readonly (Tuple): Model name & process result | ||
forseti_server_service_account (str): Server service account email | ||
project_id (str): Project id being scanned | ||
""" | ||
# Arrange | ||
model_name, _, _ = forseti_model_readonly | ||
forseti_cli.model_use(model_name=model_name) | ||
|
||
# Act | ||
result = forseti_cli.explainer_access_by_resource( | ||
f'project/{project_id}') | ||
|
||
# Assert | ||
assert result.returncode == 0, f'Forseti stdout: {str(result.stdout)}' | ||
assert 16 == len(re.findall(forseti_server_service_account, str(result.stdout))) |
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,58 @@ | ||
# Copyright 2020 The Forseti Security Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""Model end-to-end tests""" | ||
|
||
import pytest | ||
import re | ||
from endtoend_tests.helpers.forseti_cli import ForsetiCli | ||
from sqlalchemy.sql import text | ||
|
||
|
||
class TestModel: | ||
"""Model tests | ||
Execute the basic model functionality such as: create, get, use, etc. | ||
""" | ||
|
||
@pytest.mark.client | ||
@pytest.mark.e2e | ||
@pytest.mark.model | ||
def test_model_use(self, forseti_cli: ForsetiCli, forseti_model_readonly): | ||
# Arrange | ||
model_name, handle, _ = forseti_model_readonly | ||
|
||
# Act | ||
forseti_cli.model_use(model_name) | ||
result = forseti_cli.config_show() | ||
|
||
# Assert | ||
assert handle | ||
assert re.search(fr'{handle}', str(result.stdout)) | ||
|
||
@pytest.mark.e2e | ||
@pytest.mark.model | ||
@pytest.mark.server | ||
def test_model_roles(self, cloudsql_connection, forseti_model_readonly): | ||
# Arrange/Act | ||
model_name, handle, _ = forseti_model_readonly | ||
|
||
# Assert | ||
table_name = f'forseti_security.{handle}_roles' | ||
query = text('SELECT ' | ||
'COUNT(*) ' | ||
f'FROM {table_name}') | ||
model_roles = (cloudsql_connection.execute(query).fetchone()) | ||
assert model_roles | ||
assert model_roles[0] > 0 |
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.