Skip to content
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Changelog
### Removed

### Issues Addressed
* Removed default values for authentication in `interface_hsrp_group`

## [v1.9.0]

Expand Down
6 changes: 3 additions & 3 deletions lib/cisco_node_utils/cmd_ref/interface_hsrp_group.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ authentication_enc_type:
default_value: '0'

authentication_key_type:
default_value: 'key-chain'
default_value: ~

authentication_string:
default_value: ''
default_value: ~

authentication_timeout:
kind: int
default_value: 0
default_value: ~

group_name:
get_value: '/^name (\S+)/'
Expand Down
23 changes: 17 additions & 6 deletions lib/cisco_node_utils/interface_hsrp_group.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# October 2016, Sai Chintalapudi
#
# Copyright (c) 2016 Cisco and/or its affiliates.
# Copyright (c) 2016-2018 Cisco and/or its affiliates.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -96,6 +96,12 @@ def destroy
# authentication md5 key-string ABCXYZ timeout 22
# authentication md5 key-string 7 12345678901234567890 timeout 22
# authentication md5 key-string 7 123456789 compatibility timeout 22
# if passwd
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this comment block intentional?

# req auth_enc_type
# if encrypted
# req authentication_key_type, authentication_enc_type
# if key-string
# optional compat and timeout
def authentication
hash = {}
hash[:auth_type] = default_authentication_auth_type
Expand Down Expand Up @@ -203,8 +209,13 @@ def authentication_timeout
end

def authentication_timeout=(val)
@set_args[:tval] = val
@set_args[:timeout] = 'timeout'
if val.nil?
@set_args[:tval] = ''
@set_args[:timeout] = ''
else
@set_args[:tval] = val
@set_args[:timeout] = 'timeout'
end
end

def default_authentication_timeout
Expand All @@ -227,14 +238,14 @@ def authentication_set(attrs)
:authentication_compatibility,
:authentication_timeout,
].each do |p|
send(p.to_s + '=', attrs[p]) unless attrs[p].nil?
send(p.to_s + '=', attrs[p])
end
return if @set_args[:passwd] == default_authentication_string
return if @set_args[:passwd].nil? || @set_args[:passwd].empty?
@set_args[:state] = ''
if @set_args[:authtype] == 'text'
@set_args[:keytype] = @set_args[:enctype] = ''
@set_args[:compatible] = @set_args[:timeout] = @set_args[:tval] = ''
elsif @set_args[:keytype] == default_authentication_key_type
elsif @set_args[:keytype] == 'key-chain'
@set_args[:enctype] = @set_args[:compatible] = ''
@set_args[:timeout] = @set_args[:tval] = ''
end
Expand Down
36 changes: 12 additions & 24 deletions tests/test_interface_hsrp_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ def test_mac_addr
def test_auth_type_clear
skip_legacy_defect?('7.3.0.D1.1', 'CSCuh90262: hsrp indentation')
ihg = create_interface_hsrp_group_ipv4
assert_equal(ihg.default_authentication_string,
ihg.authentication_string)
assert_nil(ihg.authentication_string)
attrs = {}
attrs[:authentication_auth_type] = 'cleartext'
attrs[:authentication_string] = 'Test'
Expand All @@ -119,8 +118,7 @@ def test_auth_type_clear
assert_equal('Test', ihg.authentication_string)
attrs[:authentication_string] = ihg.default_authentication_string
ihg.authentication_set(attrs)
assert_equal(ihg.default_authentication_string,
ihg.authentication_string)
assert_nil(ihg.authentication_string)

ihg = create_interface_hsrp_group_ipv6
attrs[:authentication_auth_type] = 'cleartext'
Expand All @@ -130,8 +128,7 @@ def test_auth_type_clear
assert_equal('Test', ihg.authentication_string)
attrs[:authentication_string] = ihg.default_authentication_string
ihg.authentication_set(attrs)
assert_equal(ihg.default_authentication_string,
ihg.authentication_string)
assert_nil(ihg.authentication_string)
end

def test_auth_type_md5
Expand All @@ -147,8 +144,7 @@ def test_auth_type_md5
assert_equal('MyMD5Password', ihg.authentication_string)
attrs[:authentication_string] = ihg.default_authentication_string
ihg.authentication_set(attrs)
assert_equal(ihg.default_authentication_string,
ihg.authentication_string)
assert_nil(ihg.authentication_string)
ihg = create_interface_hsrp_group_ipv6
attrs[:authentication_string] = 'MyMD5Password'
ihg.authentication_set(attrs)
Expand All @@ -157,8 +153,7 @@ def test_auth_type_md5
assert_equal('MyMD5Password', ihg.authentication_string)
attrs[:authentication_string] = ihg.default_authentication_string
ihg.authentication_set(attrs)
assert_equal(ihg.default_authentication_string,
ihg.authentication_string)
assert_nil(ihg.authentication_string)
end

def test_auth_key_string_enc_0
Expand All @@ -178,8 +173,7 @@ def test_auth_key_string_enc_0
assert_equal('7', ihg.authentication_string)
attrs[:authentication_string] = ihg.default_authentication_string
ihg.authentication_set(attrs)
assert_equal(ihg.default_authentication_string,
ihg.authentication_string)
assert_nil(ihg.authentication_string)
ihg = create_interface_hsrp_group_ipv6
attrs[:authentication_string] = '7'
ihg.authentication_set(attrs)
Expand All @@ -189,8 +183,7 @@ def test_auth_key_string_enc_0
assert_equal('7', ihg.authentication_string)
attrs[:authentication_string] = ihg.default_authentication_string
ihg.authentication_set(attrs)
assert_equal(ihg.default_authentication_string,
ihg.authentication_string)
assert_nil(ihg.authentication_string)
end

def test_auth_key_string_enc_7
Expand All @@ -217,8 +210,7 @@ def test_auth_key_string_enc_7
assert_equal('12345678901234567890', ihg.authentication_string)
attrs[:authentication_string] = ihg.default_authentication_string
ihg.authentication_set(attrs)
assert_equal(ihg.default_authentication_string,
ihg.authentication_string)
assert_nil(ihg.authentication_string)
end

def test_auth_key_string_enc_7_compat_timeout_ipv4
Expand Down Expand Up @@ -250,8 +242,7 @@ def test_auth_key_string_enc_7_compat_timeout_ipv4
assert_equal(false, ihg.authentication_compatibility)
attrs[:authentication_string] = ihg.default_authentication_string
ihg.authentication_set(attrs)
assert_equal(ihg.default_authentication_string,
ihg.authentication_string)
assert_nil(ihg.authentication_string)
end

def test_auth_key_string_enc_7_compat_timeout_ipv6
Expand Down Expand Up @@ -283,8 +274,7 @@ def test_auth_key_string_enc_7_compat_timeout_ipv6
assert_equal(false, ihg.authentication_compatibility)
attrs[:authentication_string] = ihg.default_authentication_string
ihg.authentication_set(attrs)
assert_equal(ihg.default_authentication_string,
ihg.authentication_string)
assert_nil(ihg.authentication_string)
end

def test_auth_key_string_enc_0_compat_timeout_ipv4
Expand Down Expand Up @@ -315,8 +305,7 @@ def test_auth_key_string_enc_0_compat_timeout_ipv4
assert_equal(3333, ihg.authentication_timeout)
attrs[:authentication_string] = ihg.default_authentication_string
ihg.authentication_set(attrs)
assert_equal(ihg.default_authentication_string,
ihg.authentication_string)
assert_nil(ihg.authentication_string)
end

def test_auth_key_string_enc_0_compat_timeout_ipv6
Expand Down Expand Up @@ -347,8 +336,7 @@ def test_auth_key_string_enc_0_compat_timeout_ipv6
assert_equal(3333, ihg.authentication_timeout)
attrs[:authentication_string] = ihg.default_authentication_string
ihg.authentication_set(attrs)
assert_equal(ihg.default_authentication_string,
ihg.authentication_string)
assert_nil(ihg.authentication_string)
end

def test_preempt_ipv4
Expand Down