mirror of
https://github.com/ansible/awx.git
synced 2026-01-23 23:41:23 -03:30
Adding more through testing of tower_oauthtoken including failure messages
This commit is contained in:
parent
7c88a51992
commit
30346618f1
@ -3,7 +3,7 @@ __metaclass__ = type
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule, env_fallback
|
||||
from ansible.module_utils.urls import Request, SSLValidationError, ConnectionError
|
||||
from ansible.module_utils.six import PY2
|
||||
from ansible.module_utils.six import PY2, string_types
|
||||
from ansible.module_utils.six.moves import StringIO
|
||||
from ansible.module_utils.six.moves.urllib.parse import urlparse, urlencode
|
||||
from ansible.module_utils.six.moves.urllib.error import HTTPError
|
||||
@ -98,10 +98,16 @@ class TowerModule(AnsibleModule):
|
||||
|
||||
# Perform magic depending on whether tower_oauthtoken is a string or a dict
|
||||
if self.params.get('tower_oauthtoken'):
|
||||
if type(self.params.get('tower_oauthtoken')) is dict:
|
||||
setattr(self, 'oauth_token', self.params.get('tower_oauthtoken')['token'])
|
||||
elif 'token' in self.params.get('tower_oauthtoken'):
|
||||
setattr(self, 'oauth_token', self.params.get('tower_oauthtoken'))
|
||||
token_param = self.params.get('tower_oauthtoken')
|
||||
if type(token_param) is dict:
|
||||
if 'token' in token_param:
|
||||
self.oauth_token = self.params.get('tower_oauthtoken')['token']
|
||||
else:
|
||||
self.fail_json(msg="The provided dict in tower_oauthtoken did not properly contain the token entry")
|
||||
elif isinstance(token_param, string_types):
|
||||
self.oauth_token = self.params.get('tower_oauthtoken')
|
||||
else:
|
||||
self.fail_json(msg="The provided tower_oauthtoken type was not valid ({0}), please refer to ansible-doc for valid options".format(type(token_param).__name__))
|
||||
|
||||
# Perform some basic validation
|
||||
if not re.match('^https{0,1}://', self.host):
|
||||
|
||||
@ -3,6 +3,30 @@
|
||||
set_fact:
|
||||
token_description: "AWX-Collection-tests-tower_token-description-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
|
||||
|
||||
- name: Try to use a token as a dict which is missing the token parameter
|
||||
tower_job_list:
|
||||
tower_oauthtoken:
|
||||
not_token: "This has no token entry"
|
||||
register: results
|
||||
ignore_errors: True
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- results is failed
|
||||
- '"The provided dict in tower_oauthtoken did not properly contain the token entry" == results.msg'
|
||||
|
||||
- name: Try to use a token as a list
|
||||
tower_job_list:
|
||||
tower_oauthtoken:
|
||||
- dummy_token
|
||||
register: results
|
||||
ignore_errors: True
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- results is failed
|
||||
- '"The provided tower_oauthtoken type was not valid (list), please refer to ansible-doc for valid options" == results.msg'
|
||||
|
||||
- block:
|
||||
- name: Create a Token
|
||||
tower_token:
|
||||
@ -14,10 +38,12 @@
|
||||
- name: Validate our token works by token
|
||||
tower_job_list:
|
||||
tower_oauthtoken: "{{ tower_token.token }}"
|
||||
register: job_list
|
||||
|
||||
- name: Validate out token works by object
|
||||
tower_job_list:
|
||||
tower_oauthtoken: "{{ tower_token }}"
|
||||
register: job_list
|
||||
|
||||
always:
|
||||
- name: Delete our Token with our own token
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user