mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 12:50:22 -07:00
[Scaleway] Add module to manage function namespaces (#5415)
* [Scaleway] Add module to manage function namespaces Signed-off-by: Lunik <lunik@tiwabbit.fr> * rename short_descriptions Signed-off-by: Lunik <lunik@tiwabbit.fr> * handle changed verification on hashed secret values Signed-off-by: Lunik <lunik@tiwabbit.fr> * fix syntax for python 2.6 Signed-off-by: Lunik <lunik@tiwabbit.fr> * fix missing argon2 in unittest Signed-off-by: Lunik <lunik@tiwabbit.fr> * fix missing value on description field Signed-off-by: Lunik <lunik@tiwabbit.fr> Signed-off-by: Lunik <lunik@tiwabbit.fr>
This commit is contained in:
parent
ea3550d838
commit
5fe0f57033
13 changed files with 962 additions and 1 deletions
128
tests/unit/plugins/module_utils/cloud/test_scaleway.py
Normal file
128
tests/unit/plugins/module_utils/cloud/test_scaleway.py
Normal file
|
@ -0,0 +1,128 @@
|
|||
# Copyright (c) Ansible project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import random
|
||||
|
||||
from ansible_collections.community.general.tests.unit.compat import unittest
|
||||
from ansible_collections.community.general.plugins.module_utils.scaleway import SecretVariables, argon2
|
||||
|
||||
|
||||
class SecretVariablesTestCase(unittest.TestCase):
|
||||
def test_dict_to_list(self):
|
||||
source = dict(
|
||||
attribute1="value1",
|
||||
attribute2="value2"
|
||||
)
|
||||
expect = [
|
||||
dict(key="attribute1", value="value1"),
|
||||
dict(key="attribute2", value="value2")
|
||||
]
|
||||
|
||||
result = SecretVariables.dict_to_list(source)
|
||||
result = sorted(result, key=lambda el: el['key'])
|
||||
self.assertEqual(result, expect)
|
||||
|
||||
def test_list_to_dict(self):
|
||||
source = [
|
||||
dict(key="secret1", hashed_value="$argon2id$v=19$m=65536,t=1,p=2$NuZk+6UATHNFV78nFRXFvA$3kivcXfzNHI1c/4ZBpP8BeBSGhhI82NfOh4Dd48JJgc"),
|
||||
dict(key="secret2", hashed_value="$argon2id$v=19$m=65536,t=1,p=2$etGO/Z8ImYDeKr6uFsyPAQ$FbL5+hG/duDEpa8UCYqXpEUQ5EacKg6i2iAs+Dq4dAI")
|
||||
]
|
||||
expect = dict(
|
||||
secret1="$argon2id$v=19$m=65536,t=1,p=2$NuZk+6UATHNFV78nFRXFvA$3kivcXfzNHI1c/4ZBpP8BeBSGhhI82NfOh4Dd48JJgc",
|
||||
secret2="$argon2id$v=19$m=65536,t=1,p=2$etGO/Z8ImYDeKr6uFsyPAQ$FbL5+hG/duDEpa8UCYqXpEUQ5EacKg6i2iAs+Dq4dAI"
|
||||
)
|
||||
|
||||
self.assertEqual(SecretVariables.list_to_dict(source, hashed=True), expect)
|
||||
|
||||
def test_list_to_dict(self):
|
||||
source = [
|
||||
dict(key="secret1", value="value1"),
|
||||
dict(key="secret2", value="value2")
|
||||
]
|
||||
expect = dict(
|
||||
secret1="value1",
|
||||
secret2="value2"
|
||||
)
|
||||
|
||||
self.assertEqual(SecretVariables.list_to_dict(source, hashed=False), expect)
|
||||
|
||||
@unittest.skipIf(argon2 is None, "Missing required 'argon2' library")
|
||||
def test_decode_full(self):
|
||||
source_secret = [
|
||||
dict(key="secret1", hashed_value="$argon2id$v=19$m=65536,t=1,p=2$NuZk+6UATHNFV78nFRXFvA$3kivcXfzNHI1c/4ZBpP8BeBSGhhI82NfOh4Dd48JJgc"),
|
||||
dict(key="secret2", hashed_value="$argon2id$v=19$m=65536,t=1,p=2$etGO/Z8ImYDeKr6uFsyPAQ$FbL5+hG/duDEpa8UCYqXpEUQ5EacKg6i2iAs+Dq4dAI"),
|
||||
]
|
||||
source_value = [
|
||||
dict(key="secret1", value="value1"),
|
||||
dict(key="secret2", value="value2"),
|
||||
]
|
||||
|
||||
expect = [
|
||||
dict(key="secret1", value="value1"),
|
||||
dict(key="secret2", value="value2"),
|
||||
]
|
||||
|
||||
result = SecretVariables.decode(source_secret, source_value)
|
||||
result = sorted(result, key=lambda el: el['key'])
|
||||
self.assertEqual(result, expect)
|
||||
|
||||
@unittest.skipIf(argon2 is None, "Missing required 'argon2' library")
|
||||
def test_decode_dict_divergent_values(self):
|
||||
source_secret = [
|
||||
dict(key="secret1", hashed_value="$argon2id$v=19$m=65536,t=1,p=2$NuZk+6UATHNFV78nFRXFvA$3kivcXfzNHI1c/4ZBpP8BeBSGhhI82NfOh4Dd48JJgc"),
|
||||
dict(key="secret2", hashed_value="$argon2id$v=19$m=65536,t=1,p=2$etGO/Z8ImYDeKr6uFsyPAQ$FbL5+hG/duDEpa8UCYqXpEUQ5EacKg6i2iAs+Dq4dAI"),
|
||||
]
|
||||
source_value = [
|
||||
dict(key="secret1", value="value1"),
|
||||
dict(key="secret2", value="diverged_value2"),
|
||||
]
|
||||
|
||||
expect = [
|
||||
dict(key="secret1", value="value1"),
|
||||
dict(key="secret2", value="$argon2id$v=19$m=65536,t=1,p=2$etGO/Z8ImYDeKr6uFsyPAQ$FbL5+hG/duDEpa8UCYqXpEUQ5EacKg6i2iAs+Dq4dAI"),
|
||||
]
|
||||
|
||||
result = SecretVariables.decode(source_secret, source_value)
|
||||
result = sorted(result, key=lambda el: el['key'])
|
||||
self.assertEqual(result, expect)
|
||||
|
||||
@unittest.skipIf(argon2 is None, "Missing required 'argon2' library")
|
||||
def test_decode_dict_missing_values_left(self):
|
||||
source_secret = [
|
||||
dict(key="secret1", hashed_value="$argon2id$v=19$m=65536,t=1,p=2$NuZk+6UATHNFV78nFRXFvA$3kivcXfzNHI1c/4ZBpP8BeBSGhhI82NfOh4Dd48JJgc"),
|
||||
]
|
||||
source_value = [
|
||||
dict(key="secret1", value="value1"),
|
||||
dict(key="secret2", value="value2"),
|
||||
]
|
||||
|
||||
expect = [
|
||||
dict(key="secret1", value="value1"),
|
||||
]
|
||||
|
||||
result = SecretVariables.decode(source_secret, source_value)
|
||||
result = sorted(result, key=lambda el: el['key'])
|
||||
self.assertEqual(result, expect)
|
||||
|
||||
@unittest.skipIf(argon2 is None, "Missing required 'argon2' library")
|
||||
def test_decode_dict_missing_values_right(self):
|
||||
source_secret = [
|
||||
dict(key="secret1", hashed_value="$argon2id$v=19$m=65536,t=1,p=2$NuZk+6UATHNFV78nFRXFvA$3kivcXfzNHI1c/4ZBpP8BeBSGhhI82NfOh4Dd48JJgc"),
|
||||
dict(key="secret2", hashed_value="$argon2id$v=19$m=65536,t=1,p=2$etGO/Z8ImYDeKr6uFsyPAQ$FbL5+hG/duDEpa8UCYqXpEUQ5EacKg6i2iAs+Dq4dAI"),
|
||||
]
|
||||
source_value = [
|
||||
dict(key="secret1", value="value1"),
|
||||
]
|
||||
|
||||
expect = [
|
||||
dict(key="secret1", value="value1"),
|
||||
dict(key="secret2", value="$argon2id$v=19$m=65536,t=1,p=2$etGO/Z8ImYDeKr6uFsyPAQ$FbL5+hG/duDEpa8UCYqXpEUQ5EacKg6i2iAs+Dq4dAI"),
|
||||
]
|
||||
|
||||
result = SecretVariables.decode(source_secret, source_value)
|
||||
result = sorted(result, key=lambda el: el['key'])
|
||||
self.assertEqual(result, expect)
|
Loading…
Add table
Add a link
Reference in a new issue