Skip to content

Commit

Permalink
JiraV3: Validate args when creating & editing issues (#32818)
Browse files Browse the repository at this point in the history
* change description

* add description and UT for create_issue command

* add UT

* change description for edit issue command

* change description on README file

* add RN empty

* update RN and json bc file

* update docker

* update RN

* autopep8

* autopep8 again

* update RN

* Apply suggestions from doc review

Co-authored-by: ShirleyDenkberg <[email protected]>

* fix pre commit

* comment corrections

---------

Co-authored-by: ShirleyDenkberg <[email protected]>
  • Loading branch information
israelpoli and ShirleyDenkberg authored Feb 13, 2024
1 parent 52089cf commit 226f6e2
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 6 deletions.
19 changes: 19 additions & 0 deletions Packs/Jira/Integrations/JiraV3/JiraV3.py
Original file line number Diff line number Diff line change
Expand Up @@ -1937,6 +1937,13 @@ def create_issue_command(client: JiraBaseClient, args: Dict[str, str]) -> Comman
Returns:
CommandResults: CommandResults to return to XSOAR.
"""

# Validate that no more args are sent when the issue_json arg is used
if "issue_json" in args and len(args) > 1:
raise DemistoException(
"When using the argument `issue_json`, additional arguments cannot be used.ֿֿֿ\n see the argument description"
)

args_for_api = deepcopy(args)
if project_name := args_for_api.get('project_name'):
args_for_api['project_id'] = get_project_id_from_name(client=client, project_name=project_name)
Expand Down Expand Up @@ -1972,6 +1979,18 @@ def edit_issue_command(client: JiraBaseClient, args: Dict[str, str]) -> CommandR
Returns:
CommandResults: CommandResults to return to XSOAR.
"""
if "issue_json" in args and [
k
for k in args
if k
not in ("status", "transition", "action", "issue_id", "issue_key", "issue_json")
]:
raise DemistoException(
"When using the `issue_json` argument, additional arguments cannot be used "
"except `issue_id`, `issue_key`, `status`, `transition`, and `action` arguments.ֿֿֿ"
"\n see the argument description"
)

issue_id_or_key = get_issue_id_or_key(
issue_id=args.get("issue_id", ""), issue_key=args.get("issue_key", "")
)
Expand Down
6 changes: 3 additions & 3 deletions Packs/Jira/Integrations/JiraV3/JiraV3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ script:
name: issue_id
- description: The issue key (Issue ID or key is required).
name: issue_key
- description: 'The issue object (in JSON format). Using this argument will override the other arguments. For example {"fields":{"customfield_10037":"field_value"}}.'
- description: 'The issue object (in JSON format). This argument is for advanced users, as when utilizing this argument, one cannot use other arguments (it will raise an error) except the `issue_id` `issue_key` `action` `transition` and `status` and must input all required arguments into the issue_json. In addition, when issue_json is used, it is not possible to use the project name but only the project key. For example {"fields":{"customfield_10037":"field_value", "summary": "some summary", "project": {"key": "<project_key>"}}}. For more information about this argument, see https://developer.atlassian.com/server/jira/platform/jira-rest-api-example-create-issue-7897248/.'
name: issue_json
- description: Deprecated. Please use issue_json.
name: issueJson
Expand Down Expand Up @@ -556,7 +556,7 @@ script:
description: The last time the ticket was updated.
type: Date
- arguments:
- description: 'The issue object (in JSON format). Using this argument will override the other arguments. For example {"fields":{"customfield_10037":"field_value"}}.'
- description: 'The issue object (in JSON format). This argument is for advanced users, as when utilizing this argument, one cannot use other arguments and must input all required arguments into the issue_json. In addition, when issue_json is used, it is not possible to use the project name but only the project key. For example {"fields":{"customfield_10037":"field_value", "summary": "some summary", "project": {"key": "<project_key>"}}}. For more information about this argument, see https://developer.atlassian.com/server/jira/platform/jira-rest-api-example-create-issue-7897248/.'
name: issue_json
- description: Deprecated. Please use issue_json.
name: issueJson
Expand Down Expand Up @@ -1462,7 +1462,7 @@ script:
- description: Updates the remote incident with local incident changes. This method is only used for debugging purposes and will not update the current incident.
name: update-remote-system
arguments: []
dockerimage: demisto/btfl-soup:1.0.1.85862
dockerimage: demisto/btfl-soup:1.0.1.87353
isfetch: true
ismappable: true
isremotesyncin: true
Expand Down
77 changes: 77 additions & 0 deletions Packs/Jira/Integrations/JiraV3/JiraV3_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import pytest
from pytest_mock import MockerFixture
import demistomock as demisto
from unittest.mock import patch
from JiraV3 import (JiraBaseClient, JiraCloudClient, JiraOnPremClient)
Expand Down Expand Up @@ -717,6 +718,61 @@ def test_create_custom_issue_fields_for_update_with_action_append(self, mocker):
edit_issue_command(client=client, args=args)
assert expected_issue_fields == edit_issue_mocker.call_args[1].get('json_data')

def test_edit_issue_command_with_issue_json_and_another_arg_error(self):
from JiraV3 import edit_issue_command
client = jira_base_client_mock()
with pytest.raises(
DemistoException,
match=(
"When using the `issue_json` argument, additional arguments cannot be used "
"except `issue_id`, `issue_key`, `status`, `transition`, and `action` arguments.ֿֿֿ"
"\n see the argument description"
)
):
edit_issue_command(
client=client,
args={"summary": "test", "issue_json": '{"fields": {"customfield_10037":"field_value"}}'}
)

@pytest.mark.parametrize(
"extra_args",
[
{"action": "test"},
{"status": "test"},
{"transition": "test"},
{"issue_key": "test"},
{"issue_id": "test"},
]
)
def test_edit_issue_command_with_issue_json_and_another_arg_no_error(
self, mocker: MockerFixture, extra_args: dict
):
"""
Given:
- The `issue_json` arg and one more arg allowed for use with `issue_json`
When:
- run edit_issue_command function
Then:
- Ensure that the validation process,
which ensures that no additional arguments are present alongside the 'issue_json' argument,
does not result in an error in cases where the additional arguments are one of:
`action`, `status`, `transition`.
"""
from JiraV3 import edit_issue_command

client = jira_base_client_mock()
mocker.patch("JiraV3.apply_issue_status")
mocker.patch("JiraV3.apply_issue_transition")
mocker.patch.object(client, "edit_issue")
mocker.patch.object(client, "get_issue", return_value={})
mocker.patch("JiraV3.create_issue_md_and_outputs_dict", return_value=({}, {}))
mocker.patch("JiraV3.create_issue_fields", return_value={})
mocker.patch("JiraV3.create_issue_fields_for_appending", return_value={})
mocker.patch("JiraV3.get_issue_id_or_key", return_value="test")
args = {"issue_json": '{"fields": {"customfield_10037":"field_value"}}'} | extra_args
assert edit_issue_command(client=client, args=args)


class TestJiraCreateIssueCommand:
def test_create_issue_command(self, mocker):
Expand Down Expand Up @@ -755,6 +811,27 @@ def test_create_issue_command_with_issue_json(self, mocker):
command_result = create_issue_command(client=client, args={"issue_json": '{"fields": {"summary": "test"}}'})
assert command_result.to_context().get('EntryContext') == {'Ticket(val.Id && val.Id == obj.Id)': expected_outputs}

def test_create_issue_command_with_issue_json_and_another_arg(self):
"""
Given:
- A Jira client
- issue_json and summary args
When
- Calling the create issue command.
Then
- Ensure an error is raised with an expected error message.
"""
from JiraV3 import create_issue_command
client = jira_base_client_mock()
with pytest.raises(
DemistoException,
match="When using the argument `issue_json`, additional arguments cannot be used.ֿֿֿ\n see the argument description"
):
create_issue_command(
client=client,
args={"summary": "test", "issue_json": '{"fields": {"customfield_10037":"field_value"}}'}
)

def test_create_issue_command_no_summary(self):
"""
Given:
Expand Down
4 changes: 2 additions & 2 deletions Packs/Jira/Integrations/JiraV3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ Scope: `write:jira-work`
| issueId | Deprecated. Please use issue_id or issue_key. | Optional |
| issue_id | The issue ID (Issue ID or key is required). | Optional |
| issue_key | The issue key (Issue ID or key is required). | Optional |
| issue_json | The issue object (in JSON format). Using this argument will override the other arguments. For example {"fields":{"customfield_10037":"field_value"}}. | Optional |
| issue_json | The issue object (in JSON format). This argument is for advanced users, as when utilizing this argument, one cannot use other arguments (it will raise an error) except the `issue_id` `issue_eky` `action` `transition` and `status` and must input all required arguments into the issue_json. In addition, when issue_json is used, it is not possible to use the project name but only the project key. For example {"fields":{"customfield_10037":"field_value", "summary": "some summary", "project": {"key": "<project_key>"}}}. For more information about this argument, see https://developer.atlassian.com/server/jira/platform/jira-rest-api-example-create-issue-7897248/. | Optional |
| issueJson | Deprecated. Please use issue_json. | Optional |
| summary | The issue summary. | Optional |
| description | The issue description. | Optional |
Expand Down Expand Up @@ -972,7 +972,7 @@ Scope: `write:jira-work`

| **Argument Name** | **Description** | **Required** |
| --- | --- | --- |
| issue_json | The issue object (in JSON format). Using this argument will override the other arguments. For example {"fields":{"customfield_10037":"field_value"}}. | Optional |
| issue_json | 'The issue object (in JSON format). This argument is for advanced users, as when utilizing this argument, one cannot use other arguments (it will raise an error) and must input all required arguments into the issue_json. In addition, when issue_json is used, it is not possible to use the project name but only the project key. For example {"fields":{"customfield_10037":"field_value", "summary": "some summary", "project": {"key": "<project_key>"}}}. For more information about this argument, see https://developer.atlassian.com/server/jira/platform/jira-rest-api-example-create-issue-7897248/'. | Optional |
| issueJson | Deprecated. Please use issue_json. | Optional |
| summary | The summary of the issue (Summary value is required, either from the "summary" argument, or from the "issue_json" argument). | Optional |
| project_key | The project key with which to associate the issue (Project Key or name is required). | Optional |
Expand Down
4 changes: 4 additions & 0 deletions Packs/Jira/ReleaseNotes/3_1_10.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"breakingChanges": true,
"breakingChangesNotes": "#### Changes in the ***jira-create-issue*** and ***jira-edit-issue*** commands:\n- ***jira-create-issue***: It is no longer possible to send additional arguments when using the 'issue_json' argument. All required arguments for the command must be provided within the 'issue_json'.\n- ***jira-edit-issue***: It is no longer possible to send additional arguments when using the 'issue_json' argument, except for the arguments 'action', 'transition', 'status', 'issue_id', and 'issue_key'. All required arguments for the command must be provided within the 'issue_json'."
}
9 changes: 9 additions & 0 deletions Packs/Jira/ReleaseNotes/3_1_10.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

#### Integrations

##### Atlassian Jira v3

- Updated the Docker image to: *demisto/btfl-soup:1.0.1.87353*.
- Updated the documentation for the *issue_json* argument in the ***jira-create-issue*** and ***jira-edit-issue*** commands.
- Updated the ***jira-create-issue*** command. Will now fail when providing the `issue_json` argument with another argument.
- Updated the ***jira-edit-issue*** command. Will now fail when providing the `issue_json` argument with another argument except *status*, *transition*, *action*, *issue_id*, and *issue_key*.
2 changes: 1 addition & 1 deletion Packs/Jira/pack_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "Atlassian Jira",
"description": "Use the Jira integration to manage issues and create Cortex XSOAR incidents from Jira projects.",
"support": "xsoar",
"currentVersion": "3.1.9",
"currentVersion": "3.1.10",
"author": "Cortex XSOAR",
"url": "https://www.paloaltonetworks.com/cortex",
"email": "",
Expand Down

0 comments on commit 226f6e2

Please sign in to comment.