Omit placeholder vars with survey password defaults

WFJT nodes & schedules (launch configs) will accept POST/PATCH/PUT
with variables in extra_data that have $encrypted$ for their value
if a valid survey default exists.

In this case, the variable is simply removed from the extra_data.
This is done so that it does not affect pre-existing value
substitution for $encrypted$ values from the config itself
This commit is contained in:
AlanCoding
2018-02-12 09:31:52 -05:00
parent 605a2c7e01
commit 58a94be428
3 changed files with 38 additions and 4 deletions

View File

@@ -215,6 +215,24 @@ class TestWorkflowJobTemplateNodeSerializerSurveyPasswords():
assert 'var1' in attrs['survey_passwords']
assert attrs['extra_data']['var1'] == '$encrypted$foooooo'
def test_accept_password_default(self, jt, mocker):
'''
If user provides "$encrypted$" without a corresponding DB value for the
node, but survey question has a default, then variables are accepted
with that particular var omitted so on launch time the default takes effect
'''
serializer = WorkflowJobTemplateNodeSerializer()
wfjt = WorkflowJobTemplate(name='fake-wfjt')
jt.survey_spec['spec'][0]['default'] = '$encrypted$bar'
attrs = serializer.validate({
'unified_job_template': jt,
'workflow_job_template': wfjt,
'extra_data': {'var1': '$encrypted$'}
})
assert 'survey_passwords' in attrs
assert attrs['survey_passwords'] == {}
assert attrs['extra_data'] == {}
@mock.patch('awx.api.serializers.WorkflowJobTemplateNodeSerializer.get_related', lambda x,y: {})
class TestWorkflowJobNodeSerializerGetRelated():