forked from demisto/content
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change override flow (demisto#32832)
* test changes in the override flow * fix * test * fixed path to script * test * test * fix logging * fix logging * test * test * fix * test * test * test * Test * Test * test * test * fixed path to artifcats * fixed path2 * tests * format * removed file version * removed file version * last upload * bucket * di * rn * pytest * revert * removed unused inport * fixed unit test * override reverted to master * CR * cr * override new template * override only when content is shown * fix
- Loading branch information
Showing
12 changed files
with
331 additions
and
341 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
135 changes: 135 additions & 0 deletions
135
Tests/Marketplace/Tests/override_core_packs_versions_test.py
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,135 @@ | ||
import json | ||
import os | ||
import pytest | ||
from unittest.mock import MagicMock | ||
|
||
|
||
@pytest.fixture | ||
def mocked_content_repo(): | ||
mocked_content_repo = MagicMock() | ||
mocked_commit = MagicMock() | ||
mocked_blob = MagicMock() | ||
mocked_blob.data_stream.read.return_value = b'{\ | ||
"server_version": "8.3.0",\ | ||
"xsoar":\ | ||
{\ | ||
"updated_corepacks_content":\ | ||
{\ | ||
"corePacks": [],\ | ||
"upgradeCorePacks": [],\ | ||
"buildNumber": "123"\ | ||
}\ | ||
}\ | ||
}' | ||
mocked_commit.tree.__truediv__.return_value = mocked_blob | ||
mocked_content_repo.commit.return_value = mocked_commit | ||
yield mocked_content_repo | ||
|
||
|
||
def test_should_override_locked_corepacks_file(mocker, mocked_content_repo): | ||
""" | ||
When: | ||
- running the should_override_locked_corepacks_file command | ||
Given: | ||
1. corepacks_versions.json file that wasn't changed since last upload. | ||
2. corepacks_versions.json file that was changed since last upload, and the marketplace is as the upload. | ||
3. corepacks_versions.json file that was changed since last upload, but the marketplace is not as the upload. | ||
Then: | ||
1. Assert that the result returned from the function is False | ||
2. Assert that the result returned from the function is True | ||
3. Assert that the result returned from the function is False | ||
""" | ||
|
||
from Tests.Marketplace.override_core_packs_versions import should_override_locked_corepacks_file | ||
from Tests.Marketplace.marketplace_constants import GCPConfig | ||
marketplace = "xsoar" | ||
last_upload_commit = "abcd1234" | ||
|
||
mocker.patch('Tests.Marketplace.override_core_packs_versions.get_content_git_client', return_value=mocked_content_repo) | ||
|
||
# Case 1 | ||
corepacks_override = { | ||
"server_version": "8.3.0", | ||
'xsoar': | ||
{ | ||
"updated_corepacks_content": | ||
{ | ||
"corePacks": [], | ||
"upgradeCorePacks": [], | ||
"buildNumber": "123" | ||
} | ||
|
||
} | ||
} | ||
mocker.patch.object(GCPConfig, "corepacks_override_contents", corepacks_override) | ||
assert not should_override_locked_corepacks_file(marketplace, last_upload_commit) | ||
|
||
# Case 2 | ||
corepacks_override = { | ||
"server_version": "8.2.0", | ||
'xsoar': | ||
{ | ||
"updated_corepacks_content": | ||
{ | ||
"corePacks": [], | ||
"upgradeCorePacks": [], | ||
"buildNumber": "123" | ||
} | ||
} | ||
} | ||
mocker.patch.object(GCPConfig, "corepacks_override_contents", corepacks_override) | ||
assert should_override_locked_corepacks_file(marketplace, last_upload_commit) | ||
|
||
# Case 3 | ||
corepacks_override = { | ||
"server_version": "8.2.0", | ||
'marketplacev2': | ||
{ | ||
"updated_corepacks_content": | ||
{ | ||
"corePacks": [], | ||
"upgradeCorePacks": [], | ||
"buildNumber": "123" | ||
} | ||
} | ||
} | ||
mocker.patch.object(GCPConfig, "corepacks_override_contents", corepacks_override) | ||
assert not should_override_locked_corepacks_file(marketplace, last_upload_commit) | ||
|
||
|
||
def test_override_locked_corepacks_file(mocker): | ||
""" | ||
Test the override_locked_corepacks_file function. | ||
""" | ||
from Tests.Marketplace.override_core_packs_versions import override_locked_corepacks_file | ||
from Tests.Marketplace.marketplace_constants import GCPConfig | ||
import shutil | ||
|
||
# Create a temp artifacts dir for the corepacks files: | ||
artifacts_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'tmp') | ||
os.makedirs(artifacts_dir, exist_ok=True) | ||
|
||
corepacks_override = { | ||
"server_version": "8.2.0", | ||
"xsoar": { | ||
"updated_corepacks_content": | ||
{ | ||
"corePacks": ['pack1', 'pack2'], | ||
"upgradeCorePacks": ['pack3'], | ||
"buildNumber": "123" | ||
} | ||
|
||
} | ||
} | ||
mocker.patch.object(GCPConfig, "corepacks_override_contents", corepacks_override) | ||
|
||
override_locked_corepacks_file(build_number='456', artifacts_dir=artifacts_dir, marketplace='xsoar') | ||
|
||
# Assert that the file was created in the artifacts folder with the build number as expected: | ||
with open(os.path.join(artifacts_dir, 'corepacks-8.2.0.json')) as corepacks_file: | ||
corepacks_file_contents = json.load(corepacks_file) | ||
assert corepacks_file_contents.get('buildNumber') == '456' | ||
assert corepacks_file_contents.get('corePacks') == ['pack1', 'pack2'] | ||
|
||
# Remove the temp artifacts dir that was created for testing: | ||
shutil.rmtree(artifacts_dir) |
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 |
---|---|---|
@@ -1,67 +1,8 @@ | ||
{ | ||
"server_version": "8.4.0", | ||
"file_version": "3", | ||
"marketplaces": [ | ||
"xsoar_saas" | ||
], | ||
"updated_corepacks_content": { | ||
"corePacks": [ | ||
"Whois/1.5.1/Whois.zip", | ||
"Base/1.33.6/Base.zip", | ||
"TIM_SIEM/1.1.1/TIM_SIEM.zip", | ||
"CommonTypes/3.3.85/CommonTypes.zip", | ||
"FeedUnit42v2/1.0.35/FeedUnit42v2.zip", | ||
"EDL/3.2.8/EDL.zip", | ||
"ImageOCR/1.1.18/ImageOCR.zip", | ||
"CommonReports/1.0.3/CommonReports.zip", | ||
"DemistoLocking/1.0.6/DemistoLocking.zip", | ||
"CommonDashboards/1.3.6/CommonDashboards.zip", | ||
"Unit42Intel/1.0.13/Unit42Intel.zip", | ||
"VirusTotal/2.6.10/VirusTotal.zip", | ||
"AutoFocus/2.1.14/AutoFocus.zip", | ||
"DefaultPlaybook/2.0.4/DefaultPlaybook.zip", | ||
"TIM_Processing/1.1.21/TIM_Processing.zip", | ||
"DemistoRESTAPI/1.3.35/DemistoRESTAPI.zip", | ||
"FiltersAndTransformers/1.2.29/FiltersAndTransformers.zip", | ||
"CommonWidgets/1.2.30/CommonWidgets.zip", | ||
"ThreatIntelligenceManagement/1.1.5/ThreatIntelligenceManagement.zip", | ||
"PAN-OS/2.1.4/PAN-OS.zip", | ||
"rasterize/1.2.25/rasterize.zip", | ||
"HelloWorld/1.2.22/HelloWorld.zip", | ||
"Palo_Alto_Networks_WildFire/2.1.33/Palo_Alto_Networks_WildFire.zip", | ||
"CommonScripts/1.12.20/CommonScripts.zip", | ||
"CommonPlaybooks/2.4.2/CommonPlaybooks.zip", | ||
"ThreatIntelReports/1.0.10/ThreatIntelReports.zip", | ||
"FeedMitreAttackv2/1.1.22/FeedMitreAttackv2.zip" | ||
], | ||
"upgradeCorePacks": [ | ||
"AutoFocus", | ||
"Base", | ||
"CommonDashboards", | ||
"CommonPlaybooks", | ||
"CommonReports", | ||
"CommonScripts", | ||
"CommonTypes", | ||
"CommonWidgets", | ||
"DefaultPlaybook", | ||
"DemistoLocking", | ||
"DemistoRESTAPI", | ||
"EDL", | ||
"FeedMitreAttackv2", | ||
"FeedUnit42v2", | ||
"FiltersAndTransformers", | ||
"HelloWorld", | ||
"ImageOCR", | ||
"Palo_Alto_Networks_WildFire", | ||
"PAN-OS", | ||
"TIM_Processing", | ||
"TIM_SIEM", | ||
"ThreatIntelReports", | ||
"ThreatIntelligenceManagement", | ||
"Unit42Intel", | ||
"VirusTotal", | ||
"Whois", | ||
"rasterize" | ||
] | ||
} | ||
} | ||
"server_version": "8.4.0", | ||
"xsoar_saas": { | ||
"updated_corepacks_content": { | ||
} | ||
} | ||
} | ||
|
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
Oops, something went wrong.