-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: handle unicode and byte encoding for power environment variables
Signed-off-by: Martin Styk <[email protected]>
- Loading branch information
1 parent
69b28c8
commit 9cb36a8
Showing
3 changed files
with
76 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Copyright Contributors to the Beaker project. | ||
# SPDX-License-Identifier: GPL-2.0-or-later | ||
|
||
import unittest | ||
|
||
import six | ||
|
||
from bkr.common.helpers import SensitiveUnicode | ||
from bkr.labcontroller.provision import build_power_env | ||
|
||
|
||
class TestBuildPowerEnv(unittest.TestCase): | ||
def test_build_power_env(self): | ||
t_command = { | ||
"power": { | ||
"address": u"192.168.1.1", | ||
"id": u"42", | ||
"user": u"root", | ||
"passwd": SensitiveUnicode(u"toor"), | ||
}, | ||
"action": u"reboot", | ||
} | ||
|
||
expected = { | ||
"power_address": "192.168.1.1", | ||
"power_id": "42", | ||
"power_user": "root", | ||
"power_pass": "toor", | ||
"power_mode": "reboot", | ||
} | ||
|
||
actual = build_power_env(t_command) | ||
|
||
for key, value in six.iteritems(expected): | ||
self.assertEqual(expected[key], actual[key]) | ||
|
||
def test_build_power_env_with_missing_fields(self): | ||
t_command = { | ||
"power": {"address": u"192.168.1.1", "passwd": SensitiveUnicode(u"toor")}, | ||
"action": u"reboot", | ||
} | ||
|
||
expected = { | ||
"power_address": "192.168.1.1", | ||
"power_id": "", | ||
"power_user": "", | ||
"power_pass": "toor", | ||
"power_mode": "reboot", | ||
} | ||
|
||
actual = build_power_env(t_command) | ||
|
||
for key, value in six.iteritems(expected): | ||
self.assertEqual(expected[key], actual[key]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters