mirror of
https://github.com/ansible/awx.git
synced 2026-02-26 15:36:04 -03:30
Merge pull request #1298 from ryanpetrello/fix-1266
fix a bug preventing custom credential templates from including unicode
This commit is contained in:
@@ -632,7 +632,7 @@ class CredentialType(CommonModelNameNotUnique):
|
|||||||
data = Template(file_tmpl).render(**namespace)
|
data = Template(file_tmpl).render(**namespace)
|
||||||
_, path = tempfile.mkstemp(dir=private_data_dir)
|
_, path = tempfile.mkstemp(dir=private_data_dir)
|
||||||
with open(path, 'w') as f:
|
with open(path, 'w') as f:
|
||||||
f.write(data)
|
f.write(data.encode('utf-8'))
|
||||||
os.chmod(path, stat.S_IRUSR | stat.S_IWUSR)
|
os.chmod(path, stat.S_IRUSR | stat.S_IWUSR)
|
||||||
|
|
||||||
# determine if filename indicates single file or many
|
# determine if filename indicates single file or many
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from functools import partial
|
from functools import partial
|
||||||
@@ -12,6 +14,7 @@ from backports.tempfile import TemporaryDirectory
|
|||||||
import fcntl
|
import fcntl
|
||||||
import mock
|
import mock
|
||||||
import pytest
|
import pytest
|
||||||
|
import six
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
@@ -1319,6 +1322,33 @@ class TestJobCredentials(TestJobExecution):
|
|||||||
self.run_pexpect.side_effect = run_pexpect_side_effect
|
self.run_pexpect.side_effect = run_pexpect_side_effect
|
||||||
self.task.run(self.pk)
|
self.task.run(self.pk)
|
||||||
|
|
||||||
|
def test_custom_environment_injectors_with_unicode_content(self):
|
||||||
|
value = six.u('Iñtërnâtiônàlizætiøn')
|
||||||
|
some_cloud = CredentialType(
|
||||||
|
kind='cloud',
|
||||||
|
name='SomeCloud',
|
||||||
|
managed_by_tower=False,
|
||||||
|
inputs={'fields': []},
|
||||||
|
injectors={
|
||||||
|
'file': {'template': value},
|
||||||
|
'env': {'MY_CLOUD_INI_FILE': '{{tower.filename}}'}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
credential = Credential(
|
||||||
|
pk=1,
|
||||||
|
credential_type=some_cloud,
|
||||||
|
)
|
||||||
|
self.instance.credentials.add(credential)
|
||||||
|
self.task.run(self.pk)
|
||||||
|
|
||||||
|
def run_pexpect_side_effect(*args, **kwargs):
|
||||||
|
args, cwd, env, stdout = args
|
||||||
|
assert open(env['MY_CLOUD_INI_FILE'], 'rb').read() == value.encode('utf-8')
|
||||||
|
return ['successful', 0]
|
||||||
|
|
||||||
|
self.run_pexpect.side_effect = run_pexpect_side_effect
|
||||||
|
self.task.run(self.pk)
|
||||||
|
|
||||||
def test_custom_environment_injectors_with_files(self):
|
def test_custom_environment_injectors_with_files(self):
|
||||||
some_cloud = CredentialType(
|
some_cloud = CredentialType(
|
||||||
kind='cloud',
|
kind='cloud',
|
||||||
|
|||||||
Reference in New Issue
Block a user