Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added null checks in configure_common_criteria_policy(aaa) #180

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pkgs/sdk-pkg/src/genie/libs/sdk/apis/iosxe/aaa/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -921,9 +921,9 @@ def configure_common_criteria_policy(device,
if lifetime:
for key in lifetime:
configs.append("lifetime {attr} {val}".format(attr=key, val=lifetime[key]))
if int(lower_case) > 0:
if lower_case and int(lower_case) > 0:
configs.append("lower-case {low}".format(low=lower_case))
if int(upper_case) > 0:
if upper_case and int(upper_case) > 0:
configs.append("upper-case {up}".format(up=upper_case))
if max_len:
configs.append("max-length {maxl}".format(maxl=max_len))
Expand All @@ -938,7 +938,7 @@ def configure_common_criteria_policy(device,
for key in no_value:
configs.append("no {attr} {val}".format(attr=key,
val=no_value[key]))
if int(num_count) > 0:
if num_count and int(num_count) > 0:
configs.append("numeric-count {num}".format(num=num_count))
if special_case:
configs.append("special-case {spcl}".format(spcl=special_case))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import unittest
from pyats.topology import loader
from genie.libs.sdk.apis.iosxe.aaa.configure import configure_common_criteria_policy
Expand Down Expand Up @@ -32,3 +33,33 @@ def test_configure_common_criteria_policy(self):
result = configure_common_criteria_policy(self.device, 'ABCD', 5, 0, 0, 1, 1, 20, 8, 0, 1, 5, True, 1)
expected_output = None
self.assertEqual(result, expected_output)

class TestConfigureCommonCriteriaPolicyBase(unittest.TestCase):

@classmethod
def setUpClass(self):
testbed = f"""
devices:
Router:
connections:
defaults:
class: unicon.Unicon
a:
command: mock_device_cli --os iosxe --mock_data_dir {os.path.dirname(__file__)}/mock_data --state connect
protocol: unknown
os: iosxe
platform: vwlc
type: wlc
"""
self.testbed = loader.load(testbed)
self.device = self.testbed.devices['Router']
self.device.connect(
learn_hostname=True,
init_config_commands=[],
init_exec_commands=[]
)

def test_configure_common_criteria_policy(self):
result = configure_common_criteria_policy(self.device, 'ABCD', None, None, None, None, None, None, 1, None, None, None, False, None)
expected_output = None
self.assertEqual(result, expected_output)