Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
7f8a651
Fixed #4739. st2 cli now prints action ref for various commands
nmaludy Jul 12, 2019
cfe0aa7
Fix the visibility of action secret parameters on rule
jeansfelix Sep 12, 2019
0f1bae2
Fix PEP8
jeansfelix Sep 12, 2019
c604c15
Merge branch 'master' into fix/mask-secrets-rule-parameters
jeansfelix Sep 12, 2019
1e8aa64
Add ActionResourceManager and implement GET entrypoint
trstruth Sep 17, 2019
d05c236
Instead of calling eventlet directly, pass the calls through the
Kami Sep 19, 2019
ee52f63
Add missing change.
Kami Sep 19, 2019
b1360e6
Add a missing import.
Kami Sep 19, 2019
e8e8e49
Add missing function to __all__.
Kami Sep 19, 2019
1b343ee
Also update test code in st2reactor to utilize our concurrency wrapper.
Kami Sep 19, 2019
6478e3d
Update st2common.log.setup function so it takes new "st2_config_path"
Kami Sep 23, 2019
b5780b8
Allow user to pass "wrapper_script_path" and "create_token" arguments to
Kami Sep 24, 2019
cebeccc
Move code for setting CLI arguments which are passed to the wrapper
Kami Sep 24, 2019
eaa0076
Update CHANGELOG to reflect new feature
trstruth Sep 24, 2019
fcf6fe0
Add unit tests for the new ActionResourceManager methods
trstruth Sep 24, 2019
622fbfc
Assert correctness of return value and add 404 test
trstruth Sep 24, 2019
150aafe
Use assertRaisesRegexp
trstruth Oct 2, 2019
6a86330
Merge branch 'master' into trstruth/entrypoint
trstruth Oct 8, 2019
3a70c59
Merge branch 'master' into bugfix/4739-st2-cli-action-ref
Kami Oct 9, 2019
4f7f7a1
Add tests when secrets masking works correctly when ?include_attribut…
Nicodemos305 Oct 9, 2019
36980e5
Change name method test_get_one_parameters_mask_with_include_paramete…
Nicodemos305 Oct 9, 2019
6b9eb4e
add assertequal for length of json
Nicodemos305 Oct 9, 2019
42eb393
Add test model test_rule_with_secret_parameter_masked
Nicodemos305 Oct 9, 2019
76cd651
Fix syntax error
Nicodemos305 Oct 10, 2019
5defcda
Fix api path
Nicodemos305 Oct 10, 2019
421321d
Add default value p4 parameter
Nicodemos305 Oct 10, 2019
0cc4cb5
Include import constant
Nicodemos305 Oct 10, 2019
c07522a
Fix whitespace
Nicodemos305 Oct 10, 2019
8b01949
Fix delete before finish test method
Nicodemos305 Oct 10, 2019
9f3feaf
Fix parameters
Nicodemos305 Oct 10, 2019
7ff661e
Fix parameters
Nicodemos305 Oct 10, 2019
4182f4b
Remove blank lines
Nicodemos305 Oct 10, 2019
46dd3fa
Simple string in secret true parameter
Nicodemos305 Oct 10, 2019
a643ba7
Merge pull request #4791 from trstruth/trstruth/entrypoint
m4dcoder Oct 10, 2019
7ad78a9
Add import RuleTypeDB
Nicodemos305 Oct 11, 2019
4c0fd03
Fix test_rule_with_secret_parameter_masked
Nicodemos305 Oct 11, 2019
3271499
Fix test_rule_with_secret_parameter_masked
Nicodemos305 Oct 11, 2019
4ffaa6f
Remove test test_rule_with_secret_parameter_masked
Nicodemos305 Oct 11, 2019
4d7e552
Remove parameters p4
Nicodemos305 Oct 11, 2019
ee220c1
Fix syntax error
Nicodemos305 Oct 11, 2019
b73e1c3
Remove unnecessary constant
Nicodemos305 Oct 11, 2019
a202c4b
Remove All tests test_get_all_parameters_mask_with_include_parameters…
Nicodemos305 Oct 11, 2019
1ca2854
Add tests with include_attribute and exclude_attributes
Nicodemos305 Oct 11, 2019
a644014
Model tests done, WIP API Tests
Nicodemos305 Oct 16, 2019
8faa9ab
Fix get api rule include attribute
Nicodemos305 Oct 17, 2019
a1b97c6
Include test key action in map rule
Nicodemos305 Oct 17, 2019
07d4eb7
Clean Lint errors
Nicodemos305 Oct 17, 2019
b3a7531
Fix lin rule.py
Nicodemos305 Oct 17, 2019
3e5f001
fixing subprocess to use system buffer instead of being unbuffered
Oct 17, 2019
8277c78
Fix test rule
Nicodemos305 Oct 17, 2019
61b8b58
Fix Db rule
Nicodemos305 Oct 17, 2019
f1c4de4
Fix method ref_query_args
Nicodemos305 Oct 17, 2019
8b85474
Fix Lint
Nicodemos305 Oct 17, 2019
cb3b35c
Merge branch 'master' into fix/mask-secrets-rule-parameters
blag Oct 18, 2019
4614d44
Add changelog Added mask of rule action secret parameters #4788
Nicodemos305 Oct 18, 2019
8e80197
Merge branch 'fix/mask-secrets-rule-parameters' of github.com:pepepro…
Nicodemos305 Oct 18, 2019
c601c19
Merge branch 'master' into reactor_gevent_adapter
Kami Oct 21, 2019
2bb212b
Allow user to specify additional options which are passed to "pip"
Kami Oct 21, 2019
0568f19
Add changelog entry.
Kami Oct 21, 2019
fba4935
Re-generate sample config.
Kami Oct 21, 2019
25ea404
Allow user to pass "bufsize" argument to
Kami Oct 29, 2019
2f96d5d
Add new actionrunner.stream_output_buf_size config option and use that
Kami Oct 29, 2019
711436f
Add a simple test case which verifies that different values for "bufs…
Kami Oct 29, 2019
f058a5d
Add changelog entry.
Kami Oct 29, 2019
dcfe02f
Fix changelog entry.
Kami Oct 29, 2019
bf421a3
Don't break the DB abstraction and use persistance class to query for
Kami Oct 29, 2019
70f960b
get one and get all rules api endpoint show also support
Kami Oct 29, 2019
3400a76
Add some test cases which verify secrets masking works correctly for
Kami Oct 29, 2019
0343096
Fix lint, add missing change.
Kami Oct 29, 2019
e7d62d1
Re-generate sample config.
Kami Oct 29, 2019
e446a46
Use a separate action for bufsize test case.
Kami Oct 29, 2019
0b76bd5
Store log files for each screen session inside launchdev script.
Kami Oct 29, 2019
b3d885a
Add some log messages to make it easier to identify output.
Kami Oct 29, 2019
28d7c50
Merge pull request #4803 from jdmeyer3/bug/thread_buffering_issue
Kami Oct 29, 2019
3dc9ca1
Merge branch 'master' into fix/mask-secrets-rule-parameters
Kami Oct 29, 2019
bfafd43
Remove unused method, fix docstring.
Kami Oct 29, 2019
ec6b7fd
Add additional clarification.
Kami Oct 29, 2019
dc178a9
Merge branch 'master' into reactor_gevent_adapter
Kami Oct 29, 2019
92c7271
Merge pull request #4792 from StackStorm/reactor_gevent_adapter
Kami Oct 30, 2019
1022c1e
Merge branch 'master' into fix/mask-secrets-rule-parameters
Kami Oct 30, 2019
06628a7
Update changelog.
Kami Oct 30, 2019
7ecb5fe
Merge pull request #4807 from StackStorm/fix/mask-secrets-rule-parame…
Kami Oct 30, 2019
0fde265
Fix a bug with authentication returning internal server error under
Kami Oct 31, 2019
b8b874f
Add changelog entry.
Kami Oct 31, 2019
3ce8ef9
Merge pull request #4809 from StackStorm/fix_api_url_none_gunicorn_issue
Kami Oct 31, 2019
deb7c1b
Merge branch 'bugfix/4739-st2-cli-action-ref' of https://github.com/n…
Kami Nov 1, 2019
03909b4
Update affected tests.
Kami Nov 1, 2019
32446df
Update changelog.
Kami Nov 1, 2019
5d3a3a8
Fix test so it also passes with another common content type for python
Kami Nov 1, 2019
1d1aa02
Update more affected tests.
Kami Nov 1, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ Added
#4757
* Add ``user`` parameter to ``re_run`` method of st2client. #4785
* Install pack dependencies automatically. #4769
* Add support for `immutable_parameters` on Action Aliases. This feature allows default parameters to be supplied to the action on every execution of the alias. #4786
* Add support for `immutable_parameters` on Action Aliases. This feature allows default
parameters to be supplied to the action on every execution of the alias. #4786
* Add ``get_entrypoint()`` method to ``ActionResourceManager`` attribute of st2client.
#4791

Changed
~~~~~~~
Expand All @@ -27,6 +30,15 @@ Changed
writing very large executions (executions with large results) to the database. #4767
* Improved development instructions in requirements.txt and dist_utils.py comment headers
(improvement) #4774
* Add new ``actionrunner.stream_output_buffer_size`` config option and default it to ``-1``
(previously default value was ``0``). This should result in a better performance and smaller
CPU utilization for Python runner actions which produce a lot of output.
(improvement)

Reported and contributed by Joshua Meyer (@jdmeyer3) #4803
* Add new ``action_runner.pip_opts`` st2.conf config option which allows user to specify a list
of command line option which are passed to ``pip install`` command when installing pack
dependencies into a pack specific virtual environment. #4792

Fixed
~~~~~
Expand All @@ -49,6 +61,21 @@ Fixed
doesn't depend on internal pip API and so it works with latest pip version. (bug fix) #4750
* Fix dependency conflicts in pack CI runs: downgrade requests dependency back to 0.21.0, update
internal dependencies and test expectations (amqp, pyyaml, prance, six) (bugfix) #4774
* Fix secrets masking in action parameters section defined inside the rule when using
``GET /v1/rules`` and ``GET /v1/rules/<ref>`` API endpoint. (bug fix) #4788 #4807

Contributed by @Nicodemos305 and @jeansfelix
* Fix a bug with authentication API endpoint (``POST /auth/v1/tokens``) returning internal
server error when running under gunicorn and when``auth.api_url`` config option was not set.
(bug fix) #4809

Reported by @guzzijones
* Fixed ``st2 execution get`` and ``st2 run`` not printing the ``action.ref`` for non-workflow
actions. (bug fix) #4739

Contributed by Nick Maludy (@nmaludy Encore Technologies)
* Update ``st2 execution get`` command to always include ``context.user``, ``start_timestamp`` and
``end_timestamp`` attributes. (improvement) #4739

3.1.0 - June 27, 2019
---------------------
Expand Down
4 changes: 4 additions & 0 deletions conf/st2.conf.sample
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ enable = True
emit_when = succeeded,failed,timeout,canceled,abandoned # comma separated list allowed here.

[actionrunner]
# List of pip options to be passed to "pip install" command when installing pack dependencies into pack virtual environment.
pip_opts = # comma separated list allowed here.
# Internal pool size for dispatcher used by regular actions.
actions_pool_size = 60
# Default log level to use for Python runner actions. Can be overriden on invocation basis using "log_level" runner parameter.
Expand All @@ -20,6 +22,8 @@ python3_prefix = None
virtualenv_binary = /usr/bin/virtualenv
# Python 3 binary which will be used by Python actions for packs which use Python 3 virtual environment.
python3_binary = /usr/bin/python3
# Buffer size to use for real time action output streaming. 0 means unbuffered 1 means line buffered, -1 means system default, which usually means fully buffered and any other positive value means use a buffer of (approximately) that size
stream_output_buffer_size = -1
# List of virtualenv options to be passsed to "virtualenv" command that creates pack virtualenv.
virtualenv_opts = --system-site-packages # comma separated list allowed here.
# True to store and stream action output (stdout and stderr) in real-time.
Expand Down
10 changes: 7 additions & 3 deletions contrib/runners/python_runner/python_runner/python_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,11 @@ def run(self, action_parameters):
if stdin_params:
command_string = 'echo %s | %s' % (quote_unix(stdin_params), command_string)

LOG.debug('Running command: PATH=%s PYTHONPATH=%s %s' % (env['PATH'], env['PYTHONPATH'],
command_string))
bufsize = cfg.CONF.actionrunner.stream_output_buffer_size

LOG.debug('Running command (bufsize=%s): PATH=%s PYTHONPATH=%s %s' % (bufsize, env['PATH'],
env['PYTHONPATH'],
command_string))
exit_code, stdout, stderr, timed_out = run_command(cmd=args,
stdin=stdin,
stdout=subprocess.PIPE,
Expand All @@ -261,7 +264,8 @@ def run(self, action_parameters):
read_stderr_func=read_and_store_stderr,
read_stdout_buffer=stdout,
read_stderr_buffer=stderr,
stdin_value=stdin_params)
stdin_value=stdin_params,
bufsize=bufsize)
LOG.debug('Returning values: %s, %s, %s, %s', exit_code, stdout, stderr, timed_out)
LOG.debug('Returning.')
return self._get_output_values(exit_code, stdout, stderr, timed_out)
Expand Down
27 changes: 27 additions & 0 deletions contrib/runners/python_runner/tests/unit/test_pythonrunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@

PRINT_CONFIG_ITEM_ACTION = os.path.join(tests_base.get_resources_path(), 'packs',
'pythonactions/actions/print_config_item_doesnt_exist.py')
PRINT_TO_STDOUT_STDERR_ACTION = os.path.join(tests_base.get_resources_path(), 'packs',
'pythonactions/actions/print_to_stdout_and_stderr.py')


# Note: runner inherits parent args which doesn't work with tests since test pass additional
Expand Down Expand Up @@ -406,6 +408,31 @@ def test_action_stdout_and_stderr_is_stored_in_the_db(self, mock_spawn, mock_pop
self.assertEqual(output_dbs[1].data, mock_stderr[1])
self.assertEqual(output_dbs[2].data, mock_stderr[2])

def test_real_time_output_streaming_bufsize(self):
# Test various values for bufsize and verify it works / doesn't hang the process
cfg.CONF.set_override(name='stream_output', group='actionrunner', override=True)

bufsize_values = [-100, -2, -1, 0, 1, 2, 1024, 2048, 4096, 10000]

for index, bufsize in enumerate(bufsize_values, 1):
cfg.CONF.set_override(name='stream_output_buffer_size', override=bufsize,
group='actionrunner')

output_dbs = ActionExecutionOutput.get_all()
self.assertEqual(len(output_dbs), (index - 1) * 4)

runner = self._get_mock_runner_obj()
runner.entry_point = PRINT_TO_STDOUT_STDERR_ACTION
runner.pre_run()
(_, output, _) = runner.run({'stdout_count': 2, 'stderr_count': 2})

self.assertEqual(output['stdout'], 'stdout line 0\nstdout line 1\n')
self.assertEqual(output['stderr'], 'stderr line 0\nstderr line 1\n')
self.assertEqual(output['exit_code'], 0)

output_dbs = ActionExecutionOutput.get_all()
self.assertEqual(len(output_dbs), (index) * 4)

@mock.patch('st2common.util.concurrency.subprocess_popen')
def test_stdout_interception_and_parsing(self, mock_popen):
values = {'delimiter': ACTION_OUTPUT_RESULT_DELIMITER}
Expand Down
12 changes: 12 additions & 0 deletions scripts/travis/prepare-integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,21 @@ source ./virtualenv/bin/activate
python ./st2client/setup.py develop
st2 --version

# Clean up old screen log files
rm -f logs/screen-*.log

# start dev environment in screens
./tools/launchdev.sh start -x

# Give processes some time to start and check logs to see if all the services
# started or if there was any error / failure
echo "Giving screen processes some time to start..."
sleep 10

echo " === START: Catting screen process log files. ==="
cat logs/screen-*.log
echo " === END: Catting screen process log files. ==="

# This script runs as root on Travis which means other processes which don't run
# as root can't write to logs/ directory and tests fail
chmod 777 logs/
Expand Down
3 changes: 2 additions & 1 deletion st2api/st2api/controllers/v1/rule_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,9 @@ def get_all(self, exclude_attributes=None, include_attributes=None, sort=None, o
return rules

def get_one(self, ref_or_id, requester_user):
from_model_kwargs = {'mask_secrets': True}
rule = self._get_one(ref_or_id, permission_type=PermissionType.RULE_VIEW,
requester_user=requester_user)
requester_user=requester_user, from_model_kwargs=from_model_kwargs)
result = self._append_view_properties([rule.json])[0]
rule.json = result
return rule
Expand Down
18 changes: 13 additions & 5 deletions st2api/st2api/controllers/v1/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from st2common import log as logging
from st2common.exceptions.apivalidation import ValueValidationException
from st2common.exceptions.triggers import TriggerDoesNotExistException
from st2api.controllers.base import BaseRestControllerMixin
from st2api.controllers.resource import BaseResourceIsolationControllerMixin
from st2api.controllers.resource import ContentPackResourceController
from st2api.controllers.controller_transforms import transform_to_bool
Expand All @@ -39,7 +40,8 @@
LOG = logging.getLogger(__name__)


class RuleController(BaseResourceIsolationControllerMixin, ContentPackResourceController):
class RuleController(BaseRestControllerMixin, BaseResourceIsolationControllerMixin,
ContentPackResourceController):
"""
Implements the RESTful web endpoint that handles
the lifecycle of Rules in the system.
Expand Down Expand Up @@ -68,8 +70,11 @@ class RuleController(BaseResourceIsolationControllerMixin, ContentPackResourceCo
mandatory_include_fields_retrieve = ['pack', 'name', 'trigger']

def get_all(self, exclude_attributes=None, include_attributes=None, sort=None, offset=0,
limit=None, requester_user=None, **raw_filters):
from_model_kwargs = {'ignore_missing_trigger': True}
limit=None, show_secrets=False, requester_user=None, **raw_filters):
from_model_kwargs = {
'ignore_missing_trigger': True,
'mask_secrets': self._get_mask_secrets(requester_user, show_secrets=show_secrets)
}
return super(RuleController, self)._get_all(exclude_fields=exclude_attributes,
include_fields=include_attributes,
from_model_kwargs=from_model_kwargs,
Expand All @@ -79,8 +84,11 @@ def get_all(self, exclude_attributes=None, include_attributes=None, sort=None, o
raw_filters=raw_filters,
requester_user=requester_user)

def get_one(self, ref_or_id, requester_user):
from_model_kwargs = {'ignore_missing_trigger': True}
def get_one(self, ref_or_id, requester_user, show_secrets=False):
from_model_kwargs = {
'ignore_missing_trigger': True,
'mask_secrets': self._get_mask_secrets(requester_user, show_secrets=show_secrets)
}
return super(RuleController, self)._get_one(ref_or_id, from_model_kwargs=from_model_kwargs,
requester_user=requester_user,
permission_type=PermissionType.RULE_VIEW)
Expand Down
3 changes: 2 additions & 1 deletion st2api/tests/unit/controllers/v1/test_action_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ def test_get_one_ref_python_content_type(self):
try:
get_resp = self.app.get('/v1/actions/views/entry_point/%s' % action_ref)
self.assertEqual(get_resp.status_int, 200)
self.assertEqual(get_resp.headers['Content-Type'], 'application/x-python')
self.assertTrue(get_resp.headers['Content-Type'] in ['application/x-python',
'text/x-python'])
finally:
self.app.delete('/v1/actions/%s' % action_id)

Expand Down
53 changes: 53 additions & 0 deletions st2api/tests/unit/controllers/v1/test_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

from st2common.constants.rules import RULE_TYPE_STANDARD, RULE_TYPE_BACKSTOP
from st2common.constants.pack import DEFAULT_PACK_NAME
from st2common.constants.secrets import MASKED_ATTRIBUTE_VALUE
from st2common.persistence.trigger import Trigger
from st2common.models.system.common import ResourceReference
from st2common.transport.publishers import PoolPublisher
Expand Down Expand Up @@ -185,6 +186,58 @@ def test_get_all_enabled(self):
self.__do_delete(self.__get_rule_id(post_resp_rule_1))
self.__do_delete(self.__get_rule_id(post_resp_rule_3))

def test_get_all_action_parameters_secrets_masking(self):
post_resp_rule_1 = self.__do_post(RulesControllerTestCase.RULE_1)

# Verify parameter is masked by default
resp = self.app.get('/v1/rules')
self.assertEqual('action' in resp.json[0], True)
self.assertEqual(resp.json[0]['action']['parameters']['action_secret'],
MASKED_ATTRIBUTE_VALUE)

# Verify ?show_secrets=true works
resp = self.app.get('/v1/rules?include_attributes=action&show_secrets=true')
self.assertEqual('action' in resp.json[0], True)
self.assertEqual(resp.json[0]['action']['parameters']['action_secret'], 'secret')

self.__do_delete(self.__get_rule_id(post_resp_rule_1))

def test_get_all_parameters_mask_with_exclude_parameters(self):
post_resp_rule_1 = self.__do_post(RulesControllerTestCase.RULE_1)
resp = self.app.get('/v1/rules?exclude_attributes=action')
self.assertEqual('action' in resp.json[0], False)
self.__do_delete(self.__get_rule_id(post_resp_rule_1))

def test_get_all_parameters_mask_with_include_parameters(self):
post_resp_rule_1 = self.__do_post(RulesControllerTestCase.RULE_1)

# Verify parameter is masked by default
resp = self.app.get('/v1/rules?include_attributes=action')
self.assertEqual('action' in resp.json[0], True)
self.assertEqual(resp.json[0]['action']['parameters']['action_secret'],
MASKED_ATTRIBUTE_VALUE)

# Verify ?show_secrets=true works
resp = self.app.get('/v1/rules?include_attributes=action&show_secrets=true')
self.assertEqual('action' in resp.json[0], True)
self.assertEqual(resp.json[0]['action']['parameters']['action_secret'], 'secret')

self.__do_delete(self.__get_rule_id(post_resp_rule_1))

def test_get_one_action_parameters_secrets_masking(self):
post_resp_rule_1 = self.__do_post(RulesControllerTestCase.RULE_1)

# Verify parameter is masked by default
resp = self.app.get('/v1/rules/%s' % (post_resp_rule_1.json['id']))
self.assertEqual(resp.json['action']['parameters']['action_secret'],
MASKED_ATTRIBUTE_VALUE)

# Verify ?show_secrets=true works
resp = self.app.get('/v1/rules/%s?show_secrets=true' % (post_resp_rule_1.json['id']))
self.assertEqual(resp.json['action']['parameters']['action_secret'], 'secret')

self.__do_delete(self.__get_rule_id(post_resp_rule_1))

def test_get_one_by_id(self):
post_resp = self.__do_post(RulesControllerTestCase.RULE_1)
rule_id = self.__get_rule_id(post_resp)
Expand Down
4 changes: 3 additions & 1 deletion st2auth/st2auth/controllers/v1/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from st2common.router import exc
from st2common.router import Response
from st2common.util import auth as auth_utils
from st2common.util import api as api_utils
from st2common import log as logging
import st2auth.handlers as handlers

Expand Down Expand Up @@ -80,7 +81,8 @@ def post(self, request, **kwargs):

def process_successful_response(token):
resp = Response(json=token, status=http_client.CREATED)
resp.headers['X-API-URL'] = cfg.CONF.auth.api_url
# NOTE: gunicon fails and throws an error if header value is not a string (e.g. if it's None)
resp.headers['X-API-URL'] = api_utils.get_base_public_api_url()
return resp


Expand Down
17 changes: 17 additions & 0 deletions st2auth/tests/unit/controllers/v1/test_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def _test_token_post(self, path=TOKEN_V1_PATH):
actual_expiry = isotime.parse(response.json['expiry'])
self.assertLess(timestamp, actual_expiry)
self.assertLess(actual_expiry, expected_expiry)
return response

def test_token_post_unauthorized(self):
response = self.app.post_json(TOKEN_V1_PATH, {}, expect_errors=True, extra_environ={
Expand All @@ -109,6 +110,22 @@ def test_token_post_new_user(self):
def test_token_post_existing_user(self):
self._test_token_post()

@mock.patch.object(
User, 'get_by_name',
mock.MagicMock(return_value=UserDB(name=USERNAME)))
def test_token_post_success_x_api_url_header_value(self):
# auth.api_url option is explicitly set
cfg.CONF.set_override('api_url', override='https://example.com', group='auth')

resp = self._test_token_post()
self.assertEqual(resp.headers['X-API-URL'], 'https://example.com')

# auth.api_url option is not set, url is inferred from listen host and port
cfg.CONF.set_override('api_url', override=None, group='auth')

resp = self._test_token_post()
self.assertEqual(resp.headers['X-API-URL'], 'http://127.0.0.1:9101')

@mock.patch.object(
User, 'get_by_name',
mock.MagicMock(return_value=UserDB(name=USERNAME)))
Expand Down
3 changes: 2 additions & 1 deletion st2client/st2client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from st2client.models.core import ResourceManager
from st2client.models.core import ActionAliasResourceManager
from st2client.models.core import ActionAliasExecutionManager
from st2client.models.core import ActionResourceManager
from st2client.models.core import ExecutionResourceManager
from st2client.models.core import InquiryResourceManager
from st2client.models.core import TriggerInstanceResourceManager
Expand Down Expand Up @@ -118,7 +119,7 @@ def __init__(self, base_url=None, auth_url=None, api_url=None, stream_url=None,
models.Token, self.endpoints['auth'], cacert=self.cacert, debug=self.debug)
self.managers['RunnerType'] = ResourceManager(
models.RunnerType, self.endpoints['api'], cacert=self.cacert, debug=self.debug)
self.managers['Action'] = ResourceManager(
self.managers['Action'] = ActionResourceManager(
models.Action, self.endpoints['api'], cacert=self.cacert, debug=self.debug)
self.managers['ActionAlias'] = ActionAliasResourceManager(
models.ActionAlias, self.endpoints['api'], cacert=self.cacert, debug=self.debug)
Expand Down
Loading