From 1466cd4e79994e31ba1c792fe58809fbc056beb8 Mon Sep 17 00:00:00 2001 From: Tomaz Muraus Date: Mon, 4 Feb 2019 14:57:28 +0100 Subject: [PATCH 01/13] Fix a bug with "serialize_positional_argument" not correctly handling unicode values. This would cause actions which rely on positions arguments (e.g. core.sendmail) not to work when an unicode value was provided. Reported by @johandahlberg. --- st2common/st2common/util/action_db.py | 15 ++++++++++--- st2common/tests/unit/test_action_db_utils.py | 22 ++++++++++++++++++++ 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/st2common/st2common/util/action_db.py b/st2common/st2common/util/action_db.py index 7bd2c33a6c..bb5983374c 100644 --- a/st2common/st2common/util/action_db.py +++ b/st2common/st2common/util/action_db.py @@ -268,7 +268,16 @@ def serialize_positional_argument(argument_type, argument_value): serialized). """ if argument_type in ['string', 'number', 'float']: - argument_value = str(argument_value) if argument_value else '' + if isinstance(argument_value, (int, float)): + argument_value = str(argument_value) + + if not argument_value: + argument_value = '' + return argument_value + + if not isinstance(argument_value, six.text_type): + # cast string non-unicode values to unicode + argument_value = argument_value.decode('utf-8') elif argument_type == 'boolean': # Booleans are serialized as string "1" and "0" if argument_value is not None: @@ -285,8 +294,8 @@ def serialize_positional_argument(argument_type, argument_value): # None / null is serialized as en empty string argument_value = '' else: - # Other values are simply cast to strings - argument_value = str(argument_value) if argument_value else '' + # Other values are simply cast to unicode string + argument_value = six.text_type(argument_value) if argument_value else '' return argument_value diff --git a/st2common/tests/unit/test_action_db_utils.py b/st2common/tests/unit/test_action_db_utils.py index 3132a2ebd7..061709d61a 100644 --- a/st2common/tests/unit/test_action_db_utils.py +++ b/st2common/tests/unit/test_action_db_utils.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- # Licensed to the StackStorm, Inc ('StackStorm') under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. @@ -399,6 +400,27 @@ def test_get_args(self): self.assertListEqual(pos_args, expected_pos_args, 'Positional args not parsed / serialized correctly.') + # Test unicode values + params = { + 'actionstr': 'bar č š hello đ č p ž Ž a 💩😁', + 'actionint': 20, + 'runnerint': 555 + } + expected_pos_args = [ + '20', + '', + u'bar č š hello đ č p ž Ž a 💩😁', + '', + '', + '', + '' + ] + pos_args, named_args = action_db_utils.get_args(params, ActionDBUtilsTestCase.action_db) + self.assertListEqual(pos_args, expected_pos_args, 'Positional args not parsed correctly.') + self.assertTrue('actionint' not in named_args) + self.assertTrue('actionstr' not in named_args) + self.assertEqual(named_args.get('runnerint'), 555) + @classmethod def _setup_test_models(cls): ActionDBUtilsTestCase.setup_runner() From 7d294fd309e33cbc5f11498428723c15ece45ae5 Mon Sep 17 00:00:00 2001 From: Tomaz Muraus Date: Mon, 4 Feb 2019 15:21:59 +0100 Subject: [PATCH 02/13] Add a changelog entry for #4533. --- CHANGELOG.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 9d2aee0cd8..1dbed3a801 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -35,6 +35,13 @@ Fixed values. Reported by @dswebbthg, @nickbaum. (bug fix) #4513 #4527 #4528 +* Fix a bug with action positional parameter serialization used in local and remote script runner + not working correctly with non-ascii (unicode) values. + + This would prevent actions such as ``core.sendmail`` which utilize positional parameters from + working correctly when a unicode value was provided. + + Reported by @johandahlberg (bug fix) #4533 2.10.0 - December 13, 2018 -------------------------- From 9b3c23ef4e4393edbf03863249d03c0cda8f2d24 Mon Sep 17 00:00:00 2001 From: Tomaz Muraus Date: Mon, 4 Feb 2019 15:24:01 +0100 Subject: [PATCH 03/13] Return early on None value. --- st2common/st2common/util/action_db.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/st2common/st2common/util/action_db.py b/st2common/st2common/util/action_db.py index bb5983374c..96969492e6 100644 --- a/st2common/st2common/util/action_db.py +++ b/st2common/st2common/util/action_db.py @@ -268,13 +268,13 @@ def serialize_positional_argument(argument_type, argument_value): serialized). """ if argument_type in ['string', 'number', 'float']: + if argument_value is None: + argument_value = six.text_type('') + return argument_value + if isinstance(argument_value, (int, float)): argument_value = str(argument_value) - if not argument_value: - argument_value = '' - return argument_value - if not isinstance(argument_value, six.text_type): # cast string non-unicode values to unicode argument_value = argument_value.decode('utf-8') From 4784d942f9af513077552864538c5918fcf55374 Mon Sep 17 00:00:00 2001 From: Tomaz Muraus Date: Tue, 5 Feb 2019 11:12:16 +0100 Subject: [PATCH 04/13] Try forcing UTF-8 charset in the email. --- contrib/core/actions/send_mail/send_mail | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/core/actions/send_mail/send_mail b/contrib/core/actions/send_mail/send_mail index 1d9bdbdc14..3f45cac00f 100755 --- a/contrib/core/actions/send_mail/send_mail +++ b/contrib/core/actions/send_mail/send_mail @@ -92,7 +92,7 @@ EOF else cat < Date: Tue, 5 Feb 2019 11:21:53 +0100 Subject: [PATCH 05/13] Update the parameter documentation. --- contrib/core/actions/sendmail.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/core/actions/sendmail.yaml b/contrib/core/actions/sendmail.yaml index 9f1582d313..7ff588e8a9 100644 --- a/contrib/core/actions/sendmail.yaml +++ b/contrib/core/actions/sendmail.yaml @@ -29,7 +29,7 @@ parameters: default: True content_type: type: string - description: Content type of message to be sent + description: Content type of message to be sent without the charset (charset is set to UTF-8 inside the script). default: "text/html" position: 4 body: From faf3218bee26b569833ed75a1a86107cc56b0acc Mon Sep 17 00:00:00 2001 From: Tomaz Muraus Date: Tue, 5 Feb 2019 11:22:56 +0100 Subject: [PATCH 06/13] Add changelog entry. --- CHANGELOG.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 1dbed3a801..29d12f3d41 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -41,6 +41,10 @@ Fixed This would prevent actions such as ``core.sendmail`` which utilize positional parameters from working correctly when a unicode value was provided. + Reported by @johandahlberg (bug fix) #4533 +* Fix ``core.sendmail`` action so it specifies ``charset=UTF-8`` in the ``Content-Type`` email + header. This way it works correctly when an email body contains unicode data. + Reported by @johandahlberg (bug fix) #4533 2.10.0 - December 13, 2018 From 0e951161540e617992c18ffc99c93e993c607642 Mon Sep 17 00:00:00 2001 From: Johan Dahlberg Date: Tue, 5 Feb 2019 13:45:21 +0100 Subject: [PATCH 07/13] UTF-8 encode both body and subject of email --- contrib/core/actions/send_mail/send_mail | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contrib/core/actions/send_mail/send_mail b/contrib/core/actions/send_mail/send_mail index 1d9bdbdc14..c75478c6bc 100755 --- a/contrib/core/actions/send_mail/send_mail +++ b/contrib/core/actions/send_mail/send_mail @@ -52,7 +52,7 @@ if [[ -z $trimmed && $SEND_EMPTY_BODY -eq 1 ]] || [[ -n $trimmed ]]; then cat < Date: Tue, 5 Feb 2019 14:56:13 +0100 Subject: [PATCH 08/13] base64 encode subject --- contrib/core/actions/send_mail/send_mail | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/core/actions/send_mail/send_mail b/contrib/core/actions/send_mail/send_mail index c75478c6bc..c7e756b777 100755 --- a/contrib/core/actions/send_mail/send_mail +++ b/contrib/core/actions/send_mail/send_mail @@ -52,7 +52,7 @@ if [[ -z $trimmed && $SEND_EMPTY_BODY -eq 1 ]] || [[ -n $trimmed ]]; then cat < Date: Tue, 5 Feb 2019 15:01:59 +0100 Subject: [PATCH 09/13] Update changelog entry. --- CHANGELOG.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 29d12f3d41..a50ac012d5 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -43,9 +43,9 @@ Fixed Reported by @johandahlberg (bug fix) #4533 * Fix ``core.sendmail`` action so it specifies ``charset=UTF-8`` in the ``Content-Type`` email - header. This way it works correctly when an email body contains unicode data. - - Reported by @johandahlberg (bug fix) #4533 + header. This way it works correctly when an email subject and / or body contains unicode data. + + Reported by @johandahlberg (bug fix) #4533 4534 2.10.0 - December 13, 2018 -------------------------- From ded040ff8a9f42893f3b22536d8c266bdb83853e Mon Sep 17 00:00:00 2001 From: Tomaz Muraus Date: Tue, 5 Feb 2019 17:34:14 +0100 Subject: [PATCH 10/13] Add some unit / integration tests for sendmail action. --- contrib/core/actions/send_mail/send_mail | 25 +- contrib/core/actions/sendmail.yaml | 21 +- contrib/core/requirements-tests.txt | 1 + contrib/core/tests/test_action_sendmail.py | 271 +++++++++++++++++++++ 4 files changed, 305 insertions(+), 13 deletions(-) create mode 100644 contrib/core/requirements-tests.txt create mode 100644 contrib/core/tests/test_action_sendmail.py diff --git a/contrib/core/actions/send_mail/send_mail b/contrib/core/actions/send_mail/send_mail index c7e756b777..6011c43d49 100755 --- a/contrib/core/actions/send_mail/send_mail +++ b/contrib/core/actions/send_mail/send_mail @@ -3,14 +3,27 @@ HOSTNAME=$(hostname -f) LINE_BREAK="" -SENDMAIL=`which sendmail` -if [ $? -ne 0 ]; then - echo "Unable to find sendmail binary in PATH" >&2 - exit 2 +FOOTER="This message was generated by StackStorm action `basename $0` running on `hostname`" + +# Allow user to provide a custom sendmail binary for more flexibility and easier +# testing +SENDMAIL_BINARY=$1 + +if [ "${SENDMAIL_BINARY}" = "None" ]; then + # If path to the sendmail binary is not provided, try to find one in $PATH + SENDMAIL=`which sendmail` + + if [ $? -ne 0 ]; then + echo "Unable to find sendmail binary in PATH" >&2 + exit 2 + fi + + MAIL="$SENDMAIL -t" +else + MAIL="${SENDMAIL_BINARY}" fi +shift -MAIL="$SENDMAIL -t" -FOOTER="This message was generated by StackStorm action `basename $0` running on `hostname`" if [[ $1 =~ '@' ]]; then FROM=$1 else diff --git a/contrib/core/actions/sendmail.yaml b/contrib/core/actions/sendmail.yaml index 7ff588e8a9..3d67275983 100644 --- a/contrib/core/actions/sendmail.yaml +++ b/contrib/core/actions/sendmail.yaml @@ -1,29 +1,36 @@ --- name: sendmail +pack: core description: This sends an email entry_point: send_mail/send_mail runner_type: "local-shell-script" enabled: true parameters: + sendmail_binary: + description: "Optional path to the sendmail binary. If not provided, it uses a system default one." + position: 0 + required: false + type: "string" + default: None from: description: Sender email address. - position: 0 + position: 1 required: false type: string default: "stanley" to: description: Recipient email address. - position: 1 + position: 2 required: true type: string subject: description: Subject of the email. - position: 2 + position: 3 required: true type: string send_empty_body: description: Send a message even if the body is empty. - position: 3 + position: 4 required: false type: boolean default: True @@ -31,16 +38,16 @@ parameters: type: string description: Content type of message to be sent without the charset (charset is set to UTF-8 inside the script). default: "text/html" - position: 4 + position: 5 body: description: Body of the email. - position: 5 + position: 6 required: true type: string sudo: immutable: true attachments: description: Array of attachment file paths, comma-delimited. - position: 6 + position: 7 required: false type: "string" diff --git a/contrib/core/requirements-tests.txt b/contrib/core/requirements-tests.txt new file mode 100644 index 0000000000..1dfe969c80 --- /dev/null +++ b/contrib/core/requirements-tests.txt @@ -0,0 +1 @@ +mail-parser>=3.9.1,<4.0 diff --git a/contrib/core/tests/test_action_sendmail.py b/contrib/core/tests/test_action_sendmail.py new file mode 100644 index 0000000000..dac74ef7c9 --- /dev/null +++ b/contrib/core/tests/test_action_sendmail.py @@ -0,0 +1,271 @@ +# -*- coding: utf-8 -*- +# Licensed to the StackStorm, Inc ('StackStorm') under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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 os +import uuid +import base64 +import tempfile + +import six +import mock +import mailparser + +from st2common.constants import action as action_constants + +from st2tests.fixturesloader import FixturesLoader +from st2tests.base import RunnerTestCase +from st2tests.base import CleanDbTestCase +from st2tests.base import CleanFilesTestCase + +from local_runner.local_shell_script_runner import LocalShellScriptRunner + +__all__ = [ + 'SendmailActionTestCase' +] + +MOCK_EXECUTION = mock.Mock() +MOCK_EXECUTION.id = '598dbf0c0640fd54bffc688b' + + +class SendmailActionTestCase(RunnerTestCase, CleanDbTestCase, CleanFilesTestCase): + fixtures_loader = FixturesLoader() + + def test_sendmail_default_text_html_content_type(self): + action_parameters = { + 'sendmail_binary': 'cat', + + 'from': 'from.user@example.tld1', + 'to': 'to.user@example.tld2', + 'subject': 'this is subject 1', + 'send_empty_body': False, + 'content_type': 'text/html', + 'body': 'Hello there html.', + 'attachments': '' + } + + expected_body = ('Hello there html.\n' + '

\n' + 'This message was generated by StackStorm action ' + 'send_mail running on localhost') + + status, _, email_data, message = self._run_action(action_parameters=action_parameters) + self.assertEquals(status, action_constants.LIVEACTION_STATUS_SUCCEEDED) + + # Verify subject contains utf-8 charset and is base64 encoded + self.assertTrue('SUBJECT: =?UTF-8?B?' in email_data) + + self.assertEqual(message.to[0][1], action_parameters['to']) + self.assertEqual(message.from_[0][1], action_parameters['from']) + self.assertEqual(message.subject, action_parameters['subject']) + self.assertEqual(message.body, expected_body) + self.assertEqual(message.content_type, 'text/html; charset=UTF-8') + + def test_sendmail_text_plain_content_type(self): + action_parameters = { + 'sendmail_binary': 'cat', + + 'from': 'from.user@example.tld1', + 'to': 'to.user@example.tld2', + 'subject': 'this is subject 2', + 'send_empty_body': False, + 'content_type': 'text/plain', + 'body': 'Hello there plain.', + 'attachments': '' + } + + expected_body = ('Hello there plain.\n\n' + 'This message was generated by StackStorm action ' + 'send_mail running on localhost') + + status, _, email_data, message = self._run_action(action_parameters=action_parameters) + self.assertEquals(status, action_constants.LIVEACTION_STATUS_SUCCEEDED) + + # Verify subject contains utf-8 charset and is base64 encoded + self.assertTrue('SUBJECT: =?UTF-8?B?' in email_data) + + self.assertEqual(message.to[0][1], action_parameters['to']) + self.assertEqual(message.from_[0][1], action_parameters['from']) + self.assertEqual(message.subject, action_parameters['subject']) + self.assertEqual(message.body, expected_body) + self.assertEqual(message.content_type, 'text/plain; charset=UTF-8') + + def test_sendmail_utf8_subject_and_body(self): + # 1. tex/html + action_parameters = { + 'sendmail_binary': 'cat', + + 'from': 'from.user@example.tld1', + 'to': 'to.user@example.tld2', + 'subject': u'Å unicode subject 😃😃', + 'send_empty_body': False, + 'content_type': 'text/html', + 'body': u'Hello there 😃😃.', + 'attachments': '' + } + + if six.PY2: + expected_body = (u'Hello there 😃😃.\n' + '

\n' + u'This message was generated by StackStorm action ' + u'send_mail running on localhost') + else: + expected_body = (u'Hello there \\U0001f603\\U0001f603.\n' + '

\n' + u'This message was generated by StackStorm action ' + u'send_mail running on localhost') + + status, _, email_data, message = self._run_action(action_parameters=action_parameters) + self.assertEquals(status, action_constants.LIVEACTION_STATUS_SUCCEEDED) + + # Verify subject contains utf-8 charset and is base64 encoded + self.assertTrue('SUBJECT: =?UTF-8?B?' in email_data) + + self.assertEqual(message.to[0][1], action_parameters['to']) + self.assertEqual(message.from_[0][1], action_parameters['from']) + self.assertEqual(message.subject, action_parameters['subject']) + self.assertEqual(message.body, expected_body) + self.assertEqual(message.content_type, 'text/html; charset=UTF-8') + + # 2. text/plain + action_parameters = { + 'sendmail_binary': 'cat', + + 'from': 'from.user@example.tld1', + 'to': 'to.user@example.tld2', + 'subject': u'Å unicode subject 😃😃', + 'send_empty_body': False, + 'content_type': 'text/plain', + 'body': u'Hello there 😃😃.', + 'attachments': '' + } + + if six.PY2: + expected_body = (u'Hello there 😃😃.\n\n' + u'This message was generated by StackStorm action ' + u'send_mail running on localhost') + else: + expected_body = (u'Hello there \\U0001f603\\U0001f603.\n\n' + u'This message was generated by StackStorm action ' + u'send_mail running on localhost') + + status, _, email_data, message = self._run_action(action_parameters=action_parameters) + self.assertEquals(status, action_constants.LIVEACTION_STATUS_SUCCEEDED) + + self.assertEqual(message.to[0][1], action_parameters['to']) + self.assertEqual(message.from_[0][1], action_parameters['from']) + self.assertEqual(message.subject, action_parameters['subject']) + self.assertEqual(message.body, expected_body) + self.assertEqual(message.content_type, 'text/plain; charset=UTF-8') + + def test_sendmail_with_attachments(self): + _, path_1 = tempfile.mkstemp() + _, path_2 = tempfile.mkstemp() + os.chmod(path_1, 0o755) + os.chmod(path_2, 0o755) + + self.to_delete_files.append(path_1) + self.to_delete_files.append(path_2) + + with open(path_1, 'w') as fp: + fp.write('content 1') + + with open(path_2, 'w') as fp: + fp.write('content 2') + + action_parameters = { + 'sendmail_binary': 'cat', + + 'from': 'from.user@example.tld1', + 'to': 'to.user@example.tld2', + 'subject': 'this is email with attachments', + 'send_empty_body': False, + 'content_type': 'text/plain', + 'body': 'Hello there plain.', + 'attachments': '%s,%s' % (path_1, path_2) + } + + expected_body = ('Hello there plain.\n\n' + 'This message was generated by StackStorm action ' + 'send_mail running on localhost') + + status, _, email_data, message = self._run_action(action_parameters=action_parameters) + self.assertEquals(status, action_constants.LIVEACTION_STATUS_SUCCEEDED) + + # Verify subject contains utf-8 charset and is base64 encoded + self.assertTrue('SUBJECT: =?UTF-8?B?' in email_data) + + self.assertEqual(message.to[0][1], action_parameters['to']) + self.assertEqual(message.from_[0][1], action_parameters['from']) + self.assertEqual(message.subject, action_parameters['subject']) + self.assertEqual(message.body, expected_body) + self.assertEqual(message.content_type, + 'multipart/mixed; boundary="ZZ_/afg6432dfgkl.94531q"') + + # There should be 3 message parts - 2 for attachments, one for body + self.assertEqual(email_data.count('--ZZ_/afg6432dfgkl.94531q'), 3) + + # There should be 2 attachments + self.assertEqual(email_data.count('Content-Transfer-Encoding: base64'), 2) + self.assertTrue(base64.b64encode(b'content 1').decode('utf-8') in email_data) + self.assertTrue(base64.b64encode(b'content 2').decode('utf-8') in email_data) + + def _run_action(self, action_parameters): + """ + Run action with the provided action parameters, return status output and + parse the output email data. + """ + models = self.fixtures_loader.load_models( + fixtures_pack='packs/core', fixtures_dict={'actions': ['sendmail.yaml']}) + action_db = models['actions']['sendmail.yaml'] + entry_point = self.fixtures_loader.get_fixture_file_path_abs( + 'packs/core', 'actions', 'send_mail/send_mail') + + runner = self._get_runner(action_db, entry_point=entry_point) + runner.pre_run() + status, result, _ = runner.run(action_parameters) + runner.post_run(status, result) + + # Remove footer added by the action which is not part of raw email data and parse + # the message + if 'stdout' in result: + email_data = result['stdout'] + email_data = email_data.split('\n')[:-2] + email_data = '\n'.join(email_data) + + if six.PY2 and isinstance(email_data, six.text_type): + email_data = email_data.encode('utf-8') + + message = mailparser.parse_from_string(email_data) + else: + email_data = None + message = None + + return (status, result, email_data, message) + + def _get_runner(self, action_db, entry_point): + runner = LocalShellScriptRunner(uuid.uuid4().hex) + runner.execution = MOCK_EXECUTION + runner.action = action_db + runner.action_name = action_db.name + runner.liveaction_id = uuid.uuid4().hex + runner.entry_point = entry_point + runner.runner_parameters = {} + runner.context = dict() + runner.callback = dict() + runner.libs_dir_path = None + runner.auth_token = mock.Mock() + runner.auth_token.token = 'mock-token' + return runner From 24c1427874c975b2e1af934dfda81210f0e78a72 Mon Sep 17 00:00:00 2001 From: Tomaz Muraus Date: Tue, 5 Feb 2019 18:19:50 +0100 Subject: [PATCH 11/13] We now also need stanley user for pack tests step. --- .travis.yml | 2 +- contrib/core/tests/test_action_sendmail.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 78d703392a..392a496c27 100644 --- a/.travis.yml +++ b/.travis.yml @@ -100,7 +100,7 @@ before_install: install: - ./scripts/travis/install-requirements.sh - - if [ "${TASK}" = 'ci-unit' ] || [ "${TASK}" = 'ci-integration' ] || [ "${TASK}" = 'compilepy3 ci-py3-unit' ] || [ "${TASK}" = 'ci-py3-integration' ]; then sudo .circle/add-itest-user.sh; fi + - if [ "${TASK}" = 'ci-unit' ] || [ "${TASK}" = 'ci-integration' ] || [ "${TASK}" = 'ci-checks ci-packs-tests' ] || [ "${TASK}" = 'compilepy3 ci-py3-unit' ] || [ "${TASK}" = 'ci-py3-integration' ]; then sudo .circle/add-itest-user.sh; fi # Let's enable rabbitmqadmin # See https://github.com/messagebus/lapine/wiki/Testing-on-Travis. diff --git a/contrib/core/tests/test_action_sendmail.py b/contrib/core/tests/test_action_sendmail.py index dac74ef7c9..370056974e 100644 --- a/contrib/core/tests/test_action_sendmail.py +++ b/contrib/core/tests/test_action_sendmail.py @@ -41,6 +41,10 @@ class SendmailActionTestCase(RunnerTestCase, CleanDbTestCase, CleanFilesTestCase): + """ + NOTE: Those tests rely on stanley user being available on the system and having paswordless + sudo access. + """ fixtures_loader = FixturesLoader() def test_sendmail_default_text_html_content_type(self): From f601fd0d966a1f5aebef3567657f9473a5675620 Mon Sep 17 00:00:00 2001 From: Tomaz Muraus Date: Tue, 5 Feb 2019 18:22:25 +0100 Subject: [PATCH 12/13] Make test more robust and not depend on the static hostname value. --- contrib/core/tests/test_action_sendmail.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/contrib/core/tests/test_action_sendmail.py b/contrib/core/tests/test_action_sendmail.py index 370056974e..4d003aa9be 100644 --- a/contrib/core/tests/test_action_sendmail.py +++ b/contrib/core/tests/test_action_sendmail.py @@ -18,6 +18,7 @@ import uuid import base64 import tempfile +import socket import six import mock @@ -38,6 +39,7 @@ MOCK_EXECUTION = mock.Mock() MOCK_EXECUTION.id = '598dbf0c0640fd54bffc688b' +HOSTNAME = socket.gethostname() class SendmailActionTestCase(RunnerTestCase, CleanDbTestCase, CleanFilesTestCase): @@ -63,7 +65,7 @@ def test_sendmail_default_text_html_content_type(self): expected_body = ('Hello there html.\n' '

\n' 'This message was generated by StackStorm action ' - 'send_mail running on localhost') + 'send_mail running on %s' % (HOSTNAME)) status, _, email_data, message = self._run_action(action_parameters=action_parameters) self.assertEquals(status, action_constants.LIVEACTION_STATUS_SUCCEEDED) @@ -92,7 +94,7 @@ def test_sendmail_text_plain_content_type(self): expected_body = ('Hello there plain.\n\n' 'This message was generated by StackStorm action ' - 'send_mail running on localhost') + 'send_mail running on %s' % (HOSTNAME)) status, _, email_data, message = self._run_action(action_parameters=action_parameters) self.assertEquals(status, action_constants.LIVEACTION_STATUS_SUCCEEDED) @@ -122,14 +124,14 @@ def test_sendmail_utf8_subject_and_body(self): if six.PY2: expected_body = (u'Hello there 😃😃.\n' - '

\n' + u'

\n' u'This message was generated by StackStorm action ' - u'send_mail running on localhost') + u'send_mail running on %s' % (HOSTNAME)) else: expected_body = (u'Hello there \\U0001f603\\U0001f603.\n' - '

\n' + u'

\n' u'This message was generated by StackStorm action ' - u'send_mail running on localhost') + u'send_mail running on %s' % (HOSTNAME)) status, _, email_data, message = self._run_action(action_parameters=action_parameters) self.assertEquals(status, action_constants.LIVEACTION_STATUS_SUCCEEDED) @@ -159,11 +161,11 @@ def test_sendmail_utf8_subject_and_body(self): if six.PY2: expected_body = (u'Hello there 😃😃.\n\n' u'This message was generated by StackStorm action ' - u'send_mail running on localhost') + u'send_mail running on %s' % (HOSTNAME)) else: expected_body = (u'Hello there \\U0001f603\\U0001f603.\n\n' u'This message was generated by StackStorm action ' - u'send_mail running on localhost') + u'send_mail running on %s' % (HOSTNAME)) status, _, email_data, message = self._run_action(action_parameters=action_parameters) self.assertEquals(status, action_constants.LIVEACTION_STATUS_SUCCEEDED) @@ -203,7 +205,7 @@ def test_sendmail_with_attachments(self): expected_body = ('Hello there plain.\n\n' 'This message was generated by StackStorm action ' - 'send_mail running on localhost') + 'send_mail running on %s' % (HOSTNAME)) status, _, email_data, message = self._run_action(action_parameters=action_parameters) self.assertEquals(status, action_constants.LIVEACTION_STATUS_SUCCEEDED) From 588bdf18d279efa4e97457858958fc34898b9404 Mon Sep 17 00:00:00 2001 From: Tomaz Muraus Date: Tue, 5 Feb 2019 18:30:15 +0100 Subject: [PATCH 13/13] Fix out of date build job name. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 392a496c27..42b794e571 100644 --- a/.travis.yml +++ b/.travis.yml @@ -56,7 +56,7 @@ matrix: name: "Lint Checks, Packs Tests (Python 2.7)" - env: TASK="compilepy3 ci-py3-unit" CACHE_NAME=py3 COMMAND_THRESHOLD=680 python: 3.6 - name: "Unit Tests (Python 3.6)" + name: "Unit Tests, Pack Tests (Python 3.6)" - env: TASK="ci-py3-integration" CACHE_NAME=py3 COMMAND_THRESHOLD=310 python: 3.6 name: "Integration Tests (Python 3.6)"