cisco_node_utils 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (202) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/CHANGELOG.md +126 -1
  4. data/README.md +19 -12
  5. data/Rakefile +1 -0
  6. data/bin/git/hooks/commit-msg/enforce_style +8 -0
  7. data/cisco_node_utils.gemspec +4 -3
  8. data/docs/README-develop-best-practices.md +127 -109
  9. data/docs/README-develop-node-utils-APIs.md +47 -39
  10. data/docs/template-router.rb +3 -7
  11. data/lib/.rubocop.yml +4 -4
  12. data/lib/cisco_node_utils.rb +1 -1
  13. data/lib/cisco_node_utils/aaa_authentication_login.rb +96 -0
  14. data/lib/cisco_node_utils/aaa_authentication_login_service.rb +133 -0
  15. data/lib/cisco_node_utils/aaa_authorization_service.rb +150 -0
  16. data/lib/cisco_node_utils/ace.rb +196 -0
  17. data/lib/cisco_node_utils/acl.rb +100 -0
  18. data/lib/cisco_node_utils/bgp.rb +301 -163
  19. data/lib/cisco_node_utils/bgp_af.rb +187 -19
  20. data/lib/cisco_node_utils/bgp_neighbor.rb +18 -33
  21. data/lib/cisco_node_utils/bgp_neighbor_af.rb +25 -48
  22. data/lib/cisco_node_utils/cisco_cmn_utils.rb +23 -4
  23. data/lib/cisco_node_utils/cmd_ref/README_YAML.md +593 -0
  24. data/lib/cisco_node_utils/cmd_ref/aaa_auth_login_service.yaml +22 -0
  25. data/lib/cisco_node_utils/cmd_ref/aaa_authentication_login.yaml +31 -0
  26. data/lib/cisco_node_utils/cmd_ref/aaa_authorization_service.yaml +22 -0
  27. data/lib/cisco_node_utils/cmd_ref/acl.yaml +43 -0
  28. data/lib/cisco_node_utils/cmd_ref/bgp.yaml +242 -0
  29. data/lib/cisco_node_utils/cmd_ref/bgp_af.yaml +164 -0
  30. data/lib/cisco_node_utils/cmd_ref/bgp_neighbor.yaml +131 -0
  31. data/lib/cisco_node_utils/cmd_ref/bgp_neighbor_af.yaml +179 -0
  32. data/lib/cisco_node_utils/cmd_ref/dnsclient.yaml +34 -0
  33. data/lib/cisco_node_utils/cmd_ref/evpn_vni.yaml +42 -0
  34. data/lib/cisco_node_utils/cmd_ref/fabricpath.yaml +172 -0
  35. data/lib/cisco_node_utils/cmd_ref/fabricpath_topology.yaml +35 -0
  36. data/lib/cisco_node_utils/cmd_ref/feature.yaml +42 -0
  37. data/lib/cisco_node_utils/cmd_ref/fex.yaml +9 -0
  38. data/lib/cisco_node_utils/cmd_ref/images.yaml +7 -0
  39. data/lib/cisco_node_utils/cmd_ref/interface.yaml +339 -0
  40. data/lib/cisco_node_utils/cmd_ref/interface_channel_group.yaml +28 -0
  41. data/lib/cisco_node_utils/cmd_ref/interface_ospf.yaml +61 -0
  42. data/lib/cisco_node_utils/cmd_ref/interface_portchannel.yaml +54 -0
  43. data/lib/cisco_node_utils/cmd_ref/interface_service_vni.yaml +32 -0
  44. data/lib/cisco_node_utils/cmd_ref/inventory.yaml +45 -0
  45. data/lib/cisco_node_utils/cmd_ref/memory.yaml +13 -0
  46. data/lib/cisco_node_utils/cmd_ref/ntp_config.yaml +7 -0
  47. data/lib/cisco_node_utils/cmd_ref/ntp_server.yaml +14 -0
  48. data/lib/cisco_node_utils/cmd_ref/ospf.yaml +74 -0
  49. data/lib/cisco_node_utils/cmd_ref/overlay_global.yaml +33 -0
  50. data/lib/cisco_node_utils/cmd_ref/pim.yaml +40 -0
  51. data/lib/cisco_node_utils/cmd_ref/portchannel_global.yaml +69 -0
  52. data/lib/cisco_node_utils/cmd_ref/radius_global.yaml +25 -0
  53. data/lib/cisco_node_utils/cmd_ref/radius_server.yaml +64 -0
  54. data/lib/cisco_node_utils/cmd_ref/radius_server_group.yaml +14 -0
  55. data/lib/cisco_node_utils/cmd_ref/show_system.yaml +5 -0
  56. data/lib/cisco_node_utils/cmd_ref/show_version.yaml +72 -0
  57. data/lib/cisco_node_utils/cmd_ref/snmp_community.yaml +23 -0
  58. data/lib/cisco_node_utils/cmd_ref/snmp_group.yaml +7 -0
  59. data/lib/cisco_node_utils/cmd_ref/snmp_notification_receiver.yaml +50 -0
  60. data/lib/cisco_node_utils/cmd_ref/snmp_server.yaml +51 -0
  61. data/lib/cisco_node_utils/cmd_ref/snmp_user.yaml +55 -0
  62. data/lib/cisco_node_utils/cmd_ref/snmpnotification.yaml +11 -0
  63. data/lib/cisco_node_utils/cmd_ref/syslog_server.yaml +18 -0
  64. data/lib/cisco_node_utils/cmd_ref/syslog_settings.yaml +7 -0
  65. data/lib/cisco_node_utils/cmd_ref/system.yaml +6 -0
  66. data/lib/cisco_node_utils/cmd_ref/tacacs_server.yaml +49 -0
  67. data/lib/cisco_node_utils/cmd_ref/tacacs_server_group.yaml +33 -0
  68. data/lib/cisco_node_utils/cmd_ref/tacacs_server_host.yaml +35 -0
  69. data/lib/cisco_node_utils/cmd_ref/vdc.yaml +38 -0
  70. data/lib/cisco_node_utils/cmd_ref/virtual_service.yaml +6 -0
  71. data/lib/cisco_node_utils/cmd_ref/vlan.yaml +56 -0
  72. data/lib/cisco_node_utils/cmd_ref/vni.yaml +76 -0
  73. data/lib/cisco_node_utils/cmd_ref/vpc.yaml +197 -0
  74. data/lib/cisco_node_utils/cmd_ref/vrf.yaml +88 -0
  75. data/lib/cisco_node_utils/cmd_ref/vtp.yaml +38 -0
  76. data/lib/cisco_node_utils/cmd_ref/vxlan_vtep.yaml +60 -0
  77. data/lib/cisco_node_utils/cmd_ref/vxlan_vtep_vni.yaml +39 -0
  78. data/lib/cisco_node_utils/cmd_ref/yum.yaml +13 -0
  79. data/lib/cisco_node_utils/command_reference.rb +359 -187
  80. data/lib/cisco_node_utils/configparser_lib.rb +1 -1
  81. data/lib/cisco_node_utils/dns_domain.rb +19 -5
  82. data/lib/cisco_node_utils/domain_name.rb +4 -8
  83. data/lib/cisco_node_utils/evpn_vni.rb +157 -0
  84. data/lib/cisco_node_utils/fabricpath_global.rb +388 -0
  85. data/lib/cisco_node_utils/fabricpath_topology.rb +150 -0
  86. data/lib/cisco_node_utils/feature.rb +111 -0
  87. data/lib/cisco_node_utils/interface.rb +390 -97
  88. data/lib/cisco_node_utils/interface_channel_group.rb +124 -0
  89. data/lib/cisco_node_utils/interface_ospf.rb +11 -34
  90. data/lib/cisco_node_utils/interface_portchannel.rb +157 -0
  91. data/lib/cisco_node_utils/interface_service_vni.rb +132 -0
  92. data/lib/cisco_node_utils/name_server.rb +1 -1
  93. data/lib/cisco_node_utils/node.rb +55 -249
  94. data/lib/cisco_node_utils/node_util.rb +5 -1
  95. data/lib/cisco_node_utils/ntp_config.rb +2 -2
  96. data/lib/cisco_node_utils/ntp_server.rb +14 -5
  97. data/lib/cisco_node_utils/overlay_global.rb +153 -0
  98. data/lib/cisco_node_utils/pim.rb +124 -0
  99. data/lib/cisco_node_utils/pim_group_list.rb +108 -0
  100. data/lib/cisco_node_utils/pim_rp_address.rb +102 -0
  101. data/lib/cisco_node_utils/platform.rb +8 -9
  102. data/lib/cisco_node_utils/portchannel_global.rb +277 -0
  103. data/lib/cisco_node_utils/radius_global.rb +9 -19
  104. data/lib/cisco_node_utils/radius_server.rb +31 -41
  105. data/lib/cisco_node_utils/radius_server_group.rb +117 -0
  106. data/lib/cisco_node_utils/router_ospf.rb +1 -1
  107. data/lib/cisco_node_utils/router_ospf_vrf.rb +14 -19
  108. data/lib/cisco_node_utils/snmp_notification_receiver.rb +158 -0
  109. data/lib/cisco_node_utils/snmpcommunity.rb +3 -5
  110. data/lib/cisco_node_utils/snmpgroup.rb +1 -1
  111. data/lib/cisco_node_utils/snmpnotification.rb +57 -0
  112. data/lib/cisco_node_utils/snmpserver.rb +8 -17
  113. data/lib/cisco_node_utils/snmpuser.rb +67 -28
  114. data/lib/cisco_node_utils/syslog_server.rb +3 -9
  115. data/lib/cisco_node_utils/syslog_settings.rb +2 -10
  116. data/lib/cisco_node_utils/tacacs_server.rb +9 -14
  117. data/lib/cisco_node_utils/tacacs_server_group.rb +145 -0
  118. data/lib/cisco_node_utils/tacacs_server_host.rb +5 -9
  119. data/lib/cisco_node_utils/vdc.rb +88 -0
  120. data/lib/cisco_node_utils/version.rb +5 -2
  121. data/lib/cisco_node_utils/vlan.rb +71 -8
  122. data/lib/cisco_node_utils/vni.rb +227 -0
  123. data/lib/cisco_node_utils/vpc.rb +377 -0
  124. data/lib/cisco_node_utils/vrf.rb +60 -9
  125. data/lib/cisco_node_utils/vrf_af.rb +191 -0
  126. data/lib/cisco_node_utils/vtp.rb +8 -6
  127. data/lib/cisco_node_utils/vxlan_vtep.rb +151 -0
  128. data/lib/cisco_node_utils/vxlan_vtep_vni.rb +234 -0
  129. data/lib/cisco_node_utils/yum.rb +1 -1
  130. data/tests/.rubocop.yml +1 -1
  131. data/tests/basetest.rb +16 -7
  132. data/tests/ciscotest.rb +55 -13
  133. data/tests/cmd_config.yaml +2 -2
  134. data/tests/platform_info.rb +3 -2
  135. data/tests/test_aaa_authentication_login.rb +219 -0
  136. data/tests/test_aaa_authentication_login_service.rb +759 -0
  137. data/tests/test_aaa_authorization_service.rb +1041 -0
  138. data/tests/test_ace.rb +160 -0
  139. data/tests/test_acl.rb +176 -0
  140. data/tests/test_bgp_af.rb +269 -13
  141. data/tests/test_bgp_neighbor.rb +38 -40
  142. data/tests/test_bgp_neighbor_af.rb +92 -32
  143. data/tests/test_command_config.rb +5 -5
  144. data/tests/test_command_reference.rb +284 -101
  145. data/tests/test_dns_domain.rb +1 -1
  146. data/tests/test_domain_name.rb +1 -1
  147. data/tests/test_evpn_vni.rb +106 -0
  148. data/tests/test_fabricpath_global.rb +243 -0
  149. data/tests/test_fabricpath_topology.rb +98 -0
  150. data/tests/test_interface.rb +292 -74
  151. data/tests/test_interface_channel_group.rb +74 -0
  152. data/tests/test_interface_ospf.rb +9 -4
  153. data/tests/test_interface_portchannel.rb +105 -0
  154. data/tests/test_interface_service_vni.rb +232 -0
  155. data/tests/test_interface_svi.rb +77 -62
  156. data/tests/test_interface_switchport.rb +17 -5
  157. data/tests/test_name_server.rb +1 -1
  158. data/tests/test_node.rb +1 -1
  159. data/tests/test_node_ext.rb +10 -20
  160. data/tests/test_ntp_config.rb +1 -1
  161. data/tests/test_ntp_server.rb +18 -6
  162. data/tests/test_overlay_global.rb +102 -0
  163. data/tests/test_pim.rb +177 -0
  164. data/tests/test_pim_group_list.rb +181 -0
  165. data/tests/test_pim_rp_address.rb +153 -0
  166. data/tests/test_platform.rb +3 -3
  167. data/tests/test_portchannel_global.rb +202 -0
  168. data/tests/test_radius_global.rb +1 -1
  169. data/tests/test_radius_server.rb +92 -57
  170. data/tests/test_radius_server_group.rb +149 -0
  171. data/tests/test_router_bgp.rb +283 -112
  172. data/tests/test_router_ospf.rb +2 -2
  173. data/tests/test_router_ospf_vrf.rb +4 -4
  174. data/tests/test_snmp_notification_receiver.rb +167 -0
  175. data/tests/test_snmpcommunity.rb +1 -1
  176. data/tests/test_snmpgroup.rb +1 -1
  177. data/tests/test_snmpnotification.rb +72 -0
  178. data/tests/test_snmpserver.rb +29 -105
  179. data/tests/test_snmpuser.rb +32 -30
  180. data/tests/test_syslog_server.rb +36 -10
  181. data/tests/test_syslog_settings.rb +1 -1
  182. data/tests/test_tacacs_server.rb +1 -1
  183. data/tests/test_tacacs_server_group.rb +405 -0
  184. data/tests/test_tacacs_server_host.rb +1 -1
  185. data/tests/test_vdc.rb +78 -0
  186. data/tests/test_vlan.rb +74 -19
  187. data/tests/test_vlan_mt_full.rb +95 -0
  188. data/tests/test_vni.rb +106 -0
  189. data/tests/test_vpc.rb +361 -0
  190. data/tests/test_vrf.rb +172 -29
  191. data/tests/test_vtp.rb +1 -1
  192. data/tests/test_vxlan_vtep.rb +214 -0
  193. data/tests/test_vxlan_vtep_vni.rb +201 -0
  194. data/tests/test_yum.rb +1 -1
  195. metadata +120 -11
  196. data/lib/cisco_node_utils/README_YAML.md +0 -325
  197. data/lib/cisco_node_utils/command_reference_common.yaml +0 -1051
  198. data/lib/cisco_node_utils/command_reference_common_bgp.yaml +0 -535
  199. data/lib/cisco_node_utils/command_reference_n3064.yaml +0 -13
  200. data/lib/cisco_node_utils/command_reference_n7k.yaml +0 -52
  201. data/lib/cisco_node_utils/command_reference_n9k.yaml +0 -26
  202. data/tests/platform_info.yaml +0 -10
@@ -0,0 +1,1041 @@
1
+ # Copyright (c) 2013-2016 Cisco and/or its affiliates.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require_relative 'ciscotest'
16
+ require_relative '../lib/cisco_node_utils/aaa_authorization_service'
17
+
18
+ # TestAaaAuthorizationService - Minitest for AaaAuthorizationService util
19
+ class TestAaaAuthorizationService < CiscoTestCase
20
+ def setup
21
+ super
22
+ feature_tacacs
23
+ end
24
+
25
+ def teardown
26
+ feature_tacacs(false)
27
+ super
28
+ end
29
+
30
+ # Method to pre-configure a valid tacacs server and aaa group. This
31
+ # group can be included in the testing such access to the device
32
+ # never is compromised.
33
+ def preconfig_tacacs_server_access(group_name, keep=true)
34
+ if keep
35
+ config('tacacs-server key testing123',
36
+ 'tacacs-server host 10.122.197.197 key testing123',
37
+ "aaa group server tacacs+ #{group_name}",
38
+ 'server 10.122.197.197',
39
+ 'use-vrf management',
40
+ 'source-interface mgmt0',
41
+ 'aaa authentication login ascii-authentication')
42
+ else
43
+ config("no aaa group server tacacs+ #{group_name}")
44
+ end
45
+ end
46
+
47
+ def feature_tacacs(feature=true)
48
+ if feature
49
+ config('feature tacacs')
50
+ else
51
+ config('no feature tacacs',
52
+ 'no aaa authentication login ascii-authentication')
53
+ end
54
+ end
55
+
56
+ def config_tacacs_servers(servers)
57
+ config('feature tacacs+')
58
+ servers.each do |server|
59
+ config("aaa group server tacacs+ #{server}")
60
+ end
61
+ end
62
+
63
+ def show_cmd
64
+ 'show run aaa all | no-more'
65
+ end
66
+
67
+ def prefix
68
+ 'aaa authorization'
69
+ end
70
+
71
+ def test_create_unsupported_type
72
+ assert_raises(ArgumentError) do
73
+ AaaAuthorizationService.new(:none, 'default')
74
+ end
75
+ end
76
+
77
+ def test_create_nil_type
78
+ assert_raises(TypeError) do
79
+ AaaAuthorizationService.new(nil, 'default')
80
+ end
81
+ end
82
+
83
+ def test_create_invalid_type
84
+ assert_raises(TypeError) do
85
+ AaaAuthorizationService.new('test', 'default')
86
+ end
87
+ end
88
+
89
+ def test_create_invalid_range_type
90
+ assert_raises(TypeError) do
91
+ AaaAuthorizationService.new(34, 'default')
92
+ end
93
+ end
94
+
95
+ def test_create_invalid_service
96
+ assert_raises(ArgumentError) do
97
+ AaaAuthorizationService.new(:commands, 'test')
98
+ end
99
+ end
100
+
101
+ def test_create_empty_service
102
+ assert_raises(ArgumentError) do
103
+ AaaAuthorizationService.new(:commands, '')
104
+ end
105
+ end
106
+
107
+ def test_create_commands_default
108
+ aaa_a_service = AaaAuthorizationService.new(:commands, 'default')
109
+ refute_nil(aaa_a_service,
110
+ 'Error: AaaAuthorizationService creating commands default')
111
+ aaa_a_service.destroy unless aaa_a_service.nil?
112
+ end
113
+
114
+ def test_create_commands_console
115
+ aaa_a_service = AaaAuthorizationService.new(:commands, 'console')
116
+ refute_nil(aaa_a_service,
117
+ 'Error: AaaAuthorizationService creating commands default')
118
+ aaa_a_service.destroy unless aaa_a_service.nil?
119
+ end
120
+
121
+ def test_create_config_commands_default
122
+ aaa_a_service = AaaAuthorizationService.new(:config_commands, 'default')
123
+ refute_nil(aaa_a_service,
124
+ 'Error: AaaAuthorizationService creating ' \
125
+ 'config-commands default')
126
+ aaa_a_service.destroy unless aaa_a_service.nil?
127
+ end
128
+
129
+ def test_create_config_commands_console
130
+ aaa_a_service = AaaAuthorizationService.new(:config_commands, 'console')
131
+ refute_nil(aaa_a_service,
132
+ 'Error: AaaAuthorizationService creating commands default')
133
+ aaa_a_service.destroy unless aaa_a_service.nil?
134
+ end
135
+
136
+ def test_get_type
137
+ type = :config_commands
138
+ aaa_a_service = AaaAuthorizationService.new(type, 'default')
139
+ assert_equal(type, aaa_a_service.type, 'Error : Invalid type')
140
+ aaa_a_service.destroy
141
+ end
142
+
143
+ def test_get_name
144
+ service = 'default'
145
+ aaa_a_service = AaaAuthorizationService.new(:config_commands, service)
146
+ assert_equal(service, aaa_a_service.name, 'Error : Invalid service name')
147
+ aaa_a_service.destroy
148
+ end
149
+
150
+ def test_collection_invalid
151
+ assert_nil(AaaAuthorizationService.services['TEST'])
152
+ end
153
+
154
+ def test_collection_services_type_commands
155
+ type = :commands
156
+ collection = AaaAuthorizationService.services[type]
157
+
158
+ # Collection will not be empty since tacacs feature is enabled.
159
+ refute_empty(collection,
160
+ 'Error: AaaAuthorizationService collection is not filled')
161
+ assert_equal(2, collection.size,
162
+ 'Error: AaaAuthorizationService collection not correct size')
163
+ assert(collection.key?('default'),
164
+ 'Error: AaaAuthorizationService collection does contain default')
165
+ assert(collection.key?('console'),
166
+ 'Error: AaaAuthorizationService collection does contain console')
167
+
168
+ collection.each do |service, aaa_a_service|
169
+ assert_equal(service, aaa_a_service.name,
170
+ 'Error: Invalid AaaAuthorizationService ' \
171
+ "#{service} in collection")
172
+
173
+ method = :local
174
+ assert_equal(method, aaa_a_service.method,
175
+ 'Error: Invalid AaaAuthorizationService method for ' \
176
+ "#{service} in collection")
177
+
178
+ groups = []
179
+ assert_equal(groups, aaa_a_service.groups,
180
+ 'Error: Invalid AaaAuthorizationService groups for ' \
181
+ "#{service} in collection")
182
+ aaa_a_service.destroy
183
+ end
184
+ end
185
+
186
+ def test_collection_services_type_config_commands
187
+ type = :config_commands
188
+ collection = AaaAuthorizationService.services[type]
189
+
190
+ # Collection will not be empty since tacacs feature is enabled.
191
+ refute_empty(collection,
192
+ 'Error: AaaAuthorizationService collection is not filled')
193
+ assert_equal(2, collection.size,
194
+ 'Error: AaaAuthorizationService collection not correct size')
195
+ assert(collection.key?('default'),
196
+ 'Error: AaaAuthorizationService collection does contain default')
197
+ assert(collection.key?('console'),
198
+ 'Error: AaaAuthorizationService collection does contain console')
199
+
200
+ collection.each do |service, aaa_a_service|
201
+ assert_equal(service, aaa_a_service.name,
202
+ "Error: Invalid AaaAuthorizationService #{service} " \
203
+ 'in collection')
204
+ assert_equal(:local, aaa_a_service.method,
205
+ 'Error: Invalid AaaAuthorizationService method for ' \
206
+ "#{service} in collection")
207
+
208
+ # Due to preconfig groups will indeed be populated
209
+ groups = []
210
+ assert_equal(groups, aaa_a_service.groups,
211
+ 'Error: Invalid AaaAuthorizationService groups for ' \
212
+ "#{service} in collection")
213
+ aaa_a_service.destroy
214
+ end
215
+ end
216
+
217
+ def test_type_commands_default_console_group
218
+ # Preconfig AAA Authorization
219
+ cmd1 = 'aaa authorization commands default group group2 group1 local'
220
+ cmd2 = 'aaa authorization commands console group group1 local'
221
+ config('aaa group server tacacs+ group1',
222
+ 'aaa group server tacacs+ group2',
223
+ cmd1)
224
+
225
+ type = :commands
226
+ collection = AaaAuthorizationService.services[type]
227
+ refute_empty(collection,
228
+ 'Error: AaaAuthorizationService collection is not filled')
229
+ assert_equal(2, collection.size,
230
+ 'Error: AaaAuthorizationService collection not ' \
231
+ 'reporting correct size')
232
+ assert(collection.key?('default'),
233
+ 'Error: AaaAuthorizationService collection does contain default')
234
+ assert(collection.key?('console'),
235
+ 'Error: AaaAuthorizationService collection does contain console')
236
+
237
+ service = 'default'
238
+ aaa_a_service = collection[service]
239
+
240
+ assert_equal(service, aaa_a_service.name,
241
+ "Error: Invalid AaaAuthorizationService #{service} " \
242
+ 'in collection')
243
+
244
+ assert_equal(:local, aaa_a_service.method,
245
+ 'Error: Invalid AaaAuthorizationService method for ' \
246
+ 'default in collection')
247
+ groups = %w(group2 group1)
248
+ assert_equal(groups, aaa_a_service.groups,
249
+ 'Error: Invalid AaaAuthorizationService groups for ' \
250
+ 'default in collection')
251
+
252
+ # only one of default or console can be configured at a time without
253
+ # locking the CLI
254
+ config("no #{cmd1}", cmd2)
255
+
256
+ service = 'console'
257
+ aaa_a_service = collection[service]
258
+
259
+ assert_equal(:local, aaa_a_service.method,
260
+ 'Error: Invalid AaaAuthorizationService method for ' \
261
+ 'console in collection')
262
+ groups = ['group1']
263
+ assert_equal(groups, aaa_a_service.groups,
264
+ 'Error: Invalid AaaAuthorizationService groups for ' \
265
+ 'console in collection')
266
+
267
+ config("no #{cmd2}")
268
+ end
269
+
270
+ def test_type_config_commands_default_console_group
271
+ # Preconfig AAA Authorization
272
+ cmd1 = 'aaa authorization config-commands default group group2 group1 local'
273
+ cmd2 = 'aaa authorization config-commands console group group1 local'
274
+ config('aaa group server tacacs+ group1',
275
+ 'aaa group server tacacs+ group2',
276
+ cmd1)
277
+
278
+ type = :config_commands
279
+ collection = AaaAuthorizationService.services[type]
280
+ refute_empty(collection,
281
+ 'Error: AaaAuthorizationService collection is not filled')
282
+ assert_equal(2, collection.size,
283
+ 'Error: AaaAuthorizationService collection not ' \
284
+ 'reporting correct size')
285
+ assert(collection.key?('default'),
286
+ 'Error: AaaAuthorizationService collection does contain default')
287
+ assert(collection.key?('console'),
288
+ 'Error: AaaAuthorizationService collection does contain console')
289
+
290
+ service = 'default'
291
+ aaa_a_service = collection[service]
292
+
293
+ assert_equal(service, aaa_a_service.name,
294
+ "Error: Invalid AaaAuthorizationService #{service} " \
295
+ 'in collection')
296
+
297
+ assert_equal(:local, aaa_a_service.method,
298
+ 'Error: Invalid AaaAuthorizationService method ' \
299
+ 'for default in collection')
300
+ groups = %w(group2 group1)
301
+ assert_equal(groups, aaa_a_service.groups,
302
+ 'Error: Invalid AaaAuthorizationService groups ' \
303
+ 'for default in collection')
304
+
305
+ config("no #{cmd1}", cmd2)
306
+
307
+ service = 'console'
308
+ aaa_a_service = collection[service]
309
+
310
+ assert_equal(:local, aaa_a_service.method,
311
+ 'Error: Invalid AaaAuthorizationService method ' \
312
+ 'for console in collection')
313
+ groups = ['group1']
314
+ assert_equal(groups, aaa_a_service.groups,
315
+ 'Error: Invalid AaaAuthorizationService groups ' \
316
+ 'for console in collection')
317
+
318
+ config("no #{cmd2}")
319
+ end
320
+
321
+ def test_get_default_method
322
+ type = :commands
323
+ aaa_a_service = AaaAuthorizationService.new(type, 'default')
324
+ assert_equal(:local, aaa_a_service.default_method,
325
+ 'Error: AaaAuthorizationService command default, ' \
326
+ 'default method')
327
+ aaa_a_service.destroy
328
+
329
+ aaa_a_service = AaaAuthorizationService.new(type, 'console')
330
+ assert_equal(:local, aaa_a_service.default_method,
331
+ 'Error: AaaAuthorizationService command console, ' \
332
+ 'default method')
333
+ aaa_a_service.destroy
334
+
335
+ type = :config_commands
336
+ aaa_a_service = AaaAuthorizationService.new(type, 'default')
337
+ assert_equal(:local, aaa_a_service.default_method,
338
+ 'Error: AaaAuthorizationService config-command ' \
339
+ 'default, default method')
340
+ aaa_a_service.destroy
341
+
342
+ aaa_a_service = AaaAuthorizationService.new(type, 'console')
343
+ assert_equal(:local, aaa_a_service.default_method,
344
+ 'Error: AaaAuthorizationService config-command ' \
345
+ 'console, default method')
346
+ aaa_a_service.destroy
347
+ end
348
+
349
+ def test_collection_groups_commands_default
350
+ type = :commands
351
+ aaa_a_service = AaaAuthorizationService.new(type, 'default')
352
+
353
+ # Default case
354
+ assert_equal(aaa_a_service.default_groups, aaa_a_service.groups,
355
+ 'Error: AaaAuthorizationService commands, ' \
356
+ 'get groups for default')
357
+
358
+ # Preconfigure tacacs, tacacs server and AAA valid group
359
+ group0 = 'tac_group'
360
+ preconfig_tacacs_server_access(group0)
361
+
362
+ # Preconfig for test
363
+ group1 = 'bxb100'
364
+ group2 = 'sjc200'
365
+ group3 = 'rtp10'
366
+ servers = [group1, group2, group3]
367
+ config_tacacs_servers(servers)
368
+
369
+ config('aaa authorization commands default group ' \
370
+ "#{group0} #{group1} #{group2}")
371
+
372
+ groups = [group0, group1, group2]
373
+ assert_equal(groups, aaa_a_service.groups,
374
+ 'Error: AaaAuthorizationService default get groups, 0/1/2')
375
+ assert_equal(:unselected, aaa_a_service.method,
376
+ 'Error: AaaAuthorizationService default get method, 0/1/2')
377
+
378
+ # Change the config to have different groups and method
379
+ config('aaa authorization commands default group ' \
380
+ "#{group0} #{group3} #{group1} local")
381
+
382
+ groups = [group0, group3, group1]
383
+ assert_equal(groups, aaa_a_service.groups,
384
+ 'Error: AaaAuthorizationService default get groups, 0/3/1')
385
+ assert_equal(:local, aaa_a_service.method,
386
+ 'Error: AaaAuthorizationService default get method, 0/3/1')
387
+
388
+ # Mix default and console, but since our instance is for 'default'
389
+ # service we should only get 'default' groups and not 'console'
390
+ # groups.
391
+ aaa_cmd1 = 'aaa authorization commands default group ' \
392
+ "#{group0} #{group2} #{group1} #{group3} local"
393
+ aaa_cmd2 = 'aaa authorization commands console group ' \
394
+ "#{group0} #{group2} #{group3} local"
395
+ config(aaa_cmd1, aaa_cmd2)
396
+
397
+ groups = [group0, group2, group1, group3]
398
+ assert_equal(groups, aaa_a_service.groups,
399
+ 'Error: AaaAuthorizationService default get groups, 0/2/1/3')
400
+ assert_equal(:local, aaa_a_service.method,
401
+ 'Error: AaaAuthorizationService default get method, 0/3/1')
402
+
403
+ # Cleanup
404
+ aaa_a_service.destroy
405
+ config("no #{aaa_cmd1}", "no #{aaa_cmd2}")
406
+
407
+ # Unconfigure tacacs, tacacs server and AAA valid group
408
+ preconfig_tacacs_server_access(group0, false)
409
+ end
410
+
411
+ def test_collection_groups_commands_console
412
+ type = :commands
413
+ aaa_a_service = AaaAuthorizationService.new(type, 'console')
414
+
415
+ # Default case
416
+ assert_equal(aaa_a_service.default_groups, aaa_a_service.groups,
417
+ 'Error: AaaAuthorizationService commands, ' \
418
+ 'get groups for console')
419
+
420
+ # Preconfigure tacacs, tacacs server and AAA valid group
421
+ group0 = 'tac_group'
422
+ preconfig_tacacs_server_access(group0)
423
+
424
+ # Preconfig for test
425
+ group1 = 'bxb100'
426
+ group2 = 'sjc200'
427
+ group3 = 'rtp10'
428
+ servers = [group1, group2, group3]
429
+ config_tacacs_servers(servers)
430
+
431
+ config('aaa authorization commands console group ' \
432
+ "#{group0} #{group1} #{group2}")
433
+
434
+ groups = [group0, group1, group2]
435
+ # puts aaa_a_service.groups
436
+ assert_equal(groups, aaa_a_service.groups,
437
+ 'Error: AaaAuthorizationService console get groups, 0/1/2')
438
+ assert_equal(:unselected, aaa_a_service.method,
439
+ 'Error: AaaAuthorizationService default get method, 0/1/2')
440
+
441
+ # Change the config to have different groups and method
442
+ config('aaa authorization commands console group ' \
443
+ "#{group0} #{group3} #{group1} local")
444
+
445
+ groups = [group0, group3, group1]
446
+ assert_equal(groups, aaa_a_service.groups,
447
+ 'Error: AaaAuthorizationService console get groups, 0/3/1')
448
+ assert_equal(:local, aaa_a_service.method,
449
+ 'Error: AaaAuthorizationService default get method, 0/3/1')
450
+
451
+ # Mix default and console, but since our instance is for 'console'
452
+ # service we should only get 'console' groups and not 'default'
453
+ # groups.
454
+ aaa_cmd1 = 'aaa authorization commands console group ' \
455
+ "#{group0} #{group2} #{group1} #{group3} local"
456
+ aaa_cmd2 = 'aaa authorization commands default group ' \
457
+ "#{group0} #{group2} #{group3} local"
458
+ config(aaa_cmd1, aaa_cmd2)
459
+
460
+ groups = [group0, group2, group1, group3]
461
+ assert_equal(groups, aaa_a_service.groups,
462
+ 'Error: AaaAuthorizationService console get groups, 0/2/1/3')
463
+ assert_equal(:local, aaa_a_service.method,
464
+ 'Error: AaaAuthorizationService default get method, 0/2/1/3')
465
+
466
+ # Cleanup
467
+ aaa_a_service.destroy
468
+ config("no #{aaa_cmd1}", "no #{aaa_cmd2}")
469
+
470
+ # Unconfigure tacacs, tacacs server and AAA valid group
471
+ preconfig_tacacs_server_access(group0, false)
472
+ end
473
+
474
+ def test_collection_groups_config_commands_default
475
+ type = :config_commands
476
+ aaa_a_service = AaaAuthorizationService.new(type, 'default')
477
+
478
+ # Default case
479
+ assert_equal(aaa_a_service.default_groups, aaa_a_service.groups,
480
+ 'Error: AaaAuthorizationService config-commands, ' \
481
+ 'get groups for default')
482
+
483
+ # Preconfigure tacacs, tacacs server and AAA valid group
484
+ group0 = 'tac_group'
485
+ preconfig_tacacs_server_access(group0)
486
+
487
+ # Preconfig for test
488
+ group1 = 'bxb100'
489
+ group2 = 'sjc200'
490
+ group3 = 'rtp10'
491
+ servers = [group1, group2, group3]
492
+ config_tacacs_servers(servers)
493
+
494
+ config('aaa authorization config-commands default group ' \
495
+ "#{group0} #{group1} #{group2}")
496
+
497
+ groups = [group0, group1, group2]
498
+ assert_equal(groups, aaa_a_service.groups,
499
+ 'Error: AaaAuthorizationService default get groups, 0/1/2')
500
+ assert_equal(:unselected, aaa_a_service.method,
501
+ 'Error: AaaAuthorizationService default get method, 0/1/2')
502
+
503
+ # Change the config to have different groups and method
504
+ config('aaa authorization config-commands default group ' \
505
+ "#{group0} #{group3} #{group1} local")
506
+
507
+ groups = [group0, group3, group1]
508
+ # puts aaa_a_service.groups
509
+ assert_equal(groups, aaa_a_service.groups,
510
+ 'Error: AaaAuthorizationService default get groups, 0/3/1')
511
+ assert_equal(:local, aaa_a_service.method,
512
+ 'Error: AaaAuthorizationService default get method, 0/3/1')
513
+
514
+ # Mix default and console, but since our instance is for 'default'
515
+ # service we should only get 'default' groups and not 'console'
516
+ # groups.
517
+ aaa_cmd1 = 'aaa authorization config-commands default group ' \
518
+ "#{group0} #{group2} #{group1} #{group3} local"
519
+ aaa_cmd2 = 'aaa authorization config-commands console group ' \
520
+ "#{group0} #{group2} #{group3} local"
521
+ config(aaa_cmd1, aaa_cmd2)
522
+
523
+ groups = [group0, group2, group1, group3]
524
+ assert_equal(groups, aaa_a_service.groups,
525
+ 'Error: AaaAuthorizationService default get groups, 0/2/1/3')
526
+ assert_equal(:local, aaa_a_service.method,
527
+ 'Error: AaaAuthorizationService default get method, 0/2/1/3')
528
+
529
+ # Cleanup
530
+ aaa_a_service.destroy
531
+ config("no #{aaa_cmd1}", "no #{aaa_cmd2}")
532
+
533
+ # Unconfigure tacacs, tacacs server and AAA valid group
534
+ preconfig_tacacs_server_access(group0, false)
535
+ end
536
+
537
+ def test_collection_groups_config_commands_console
538
+ type = :config_commands
539
+ aaa_a_service = AaaAuthorizationService.new(type, 'console')
540
+
541
+ # Default case
542
+ assert_equal(aaa_a_service.default_groups, aaa_a_service.groups,
543
+ 'Error: AaaAuthorizationService config-commands, ' \
544
+ 'get groups for console')
545
+
546
+ # Preconfigure tacacs, tacacs server and AAA valid group
547
+ group0 = 'tac_group'
548
+ preconfig_tacacs_server_access(group0)
549
+
550
+ # Preconfig for test
551
+ group1 = 'bxb100'
552
+ group2 = 'sjc200'
553
+ group3 = 'rtp10'
554
+ servers = [group1, group2, group3]
555
+ config_tacacs_servers(servers)
556
+
557
+ config('aaa authorization config-commands console group ' \
558
+ "#{group0} #{group1} #{group2}")
559
+
560
+ groups = [group0, group1, group2]
561
+ assert_equal(groups, aaa_a_service.groups,
562
+ 'Error: AaaAuthorizationService console get groups, 0/1/2')
563
+ assert_equal(:unselected, aaa_a_service.method,
564
+ 'Error: AaaAuthorizationService default get method, 0/1/2')
565
+
566
+ # Change the config to have different groups and method
567
+ config('aaa authorization config-commands console group ' \
568
+ "#{group0} #{group3} #{group1} local")
569
+
570
+ groups = [group0, group3, group1]
571
+ # puts aaa_a_service.groups
572
+ assert_equal(groups, aaa_a_service.groups,
573
+ 'Error: AaaAuthorizationService console get groups, 0/3/1')
574
+ assert_equal(:local, aaa_a_service.method,
575
+ 'Error: AaaAuthorizationService default get method, 0/3/1')
576
+
577
+ # Mix default and console, but since our instance is for 'console'
578
+ # service we should only get 'console' groups and not 'default'
579
+ # groups.
580
+ aaa_cmd1 = 'aaa authorization config-commands console group ' \
581
+ "#{group0} #{group2} #{group1} #{group3} local"
582
+ aaa_cmd2 = 'aaa authorization config-commands default group ' \
583
+ "#{group0} #{group2} #{group3} local"
584
+ config(aaa_cmd1, aaa_cmd2)
585
+
586
+ groups = [group0, group2, group1, group3]
587
+ assert_equal(groups, aaa_a_service.groups,
588
+ 'Error: AaaAuthorizationService console get groups, 0/2/1/3')
589
+ assert_equal(:local, aaa_a_service.method,
590
+ 'Error: AaaAuthorizationService default get method, 0/2/1/3')
591
+
592
+ # Cleanup
593
+ aaa_a_service.destroy
594
+ config("no #{aaa_cmd1}", "no #{aaa_cmd2}")
595
+
596
+ # Unconfigure tacacs, tacacs server and AAA valid group
597
+ preconfig_tacacs_server_access(group0, false)
598
+ end
599
+
600
+ def test_get_default_groups
601
+ groups = []
602
+ type = :commands
603
+ aaa_a_service = AaaAuthorizationService.new(type, 'default')
604
+
605
+ assert_equal(groups, aaa_a_service.default_groups,
606
+ 'Error: AaaAuthorizationService commands default, ' \
607
+ 'default groups')
608
+ aaa_a_service.destroy
609
+
610
+ aaa_a_service = AaaAuthorizationService.new(type, 'console')
611
+
612
+ assert_equal(groups, aaa_a_service.default_groups,
613
+ 'Error: AaaAuthorizationService commands console, ' \
614
+ 'default groups')
615
+ aaa_a_service.destroy
616
+
617
+ type = :config_commands
618
+ aaa_a_service = AaaAuthorizationService.new(type, 'default')
619
+
620
+ assert_equal(groups, aaa_a_service.default_groups,
621
+ 'Error: AaaAuthorizationService config-commands ' \
622
+ 'default, default groups')
623
+ aaa_a_service.destroy
624
+
625
+ aaa_a_service = AaaAuthorizationService.new(type, 'console')
626
+
627
+ assert_equal(groups, aaa_a_service.default_groups,
628
+ 'Error: AaaAuthorizationService config-commands ' \
629
+ 'console, default groups')
630
+ aaa_a_service.destroy
631
+ end
632
+
633
+ def test_commands_default_set_groups
634
+ # Preconfigure tacacs, tacacs server and AAA valid group
635
+ group0 = 'tac_group'
636
+ preconfig_tacacs_server_access(group0)
637
+
638
+ # Preconfig for test
639
+ group1 = 'bxb100'
640
+ group2 = 'sjc200'
641
+ group3 = 'rtp10'
642
+ servers = [group1, group2, group3]
643
+ config_tacacs_servers(servers)
644
+
645
+ # Commands, service default
646
+ type_str = 'commands'
647
+ type = :commands
648
+ service = 'default'
649
+ aaa_a_service = AaaAuthorizationService.new(type, service)
650
+
651
+ # Single group, with method 'unselected'
652
+ method = :unselected
653
+ groups = [group0]
654
+ aaa_a_service.groups_method_set(groups, method)
655
+
656
+ p = /#{prefix} #{type_str} #{service} group #{group0}/
657
+ assert_show_match(command: show_cmd, pattern: p)
658
+
659
+ # Multi group, with method 'unselected'
660
+ method = :unselected
661
+ groups = [group0, group1, group2]
662
+ aaa_a_service.groups_method_set(groups, method)
663
+
664
+ p = /#{prefix} #{type_str} #{service} group #{group0} #{group1} #{group2}/
665
+ assert_show_match(command: show_cmd, pattern: p)
666
+
667
+ # Multi group, with method 'local'
668
+ method = :local
669
+ groups = [group0, group1, group3]
670
+ aaa_a_service.groups_method_set(groups, method)
671
+
672
+ group_str = "group #{group0} #{group1} #{group3}"
673
+ p = /#{prefix} #{type_str} #{service} #{group_str} local/
674
+ assert_show_match(command: show_cmd, pattern: p)
675
+
676
+ # Default group and method
677
+ method = aaa_a_service.default_method
678
+ groups = aaa_a_service.default_groups
679
+ aaa_a_service.groups_method_set(groups, method)
680
+
681
+ p = /#{prefix} #{type_str} #{service} local/
682
+ assert_show_match(command: show_cmd, pattern: p)
683
+
684
+ # Cleanup
685
+ aaa_a_service.destroy
686
+
687
+ # Unconfigure tacacs, tacacs server and AAA valid group
688
+ preconfig_tacacs_server_access(group0, false)
689
+ end
690
+
691
+ def test_commands_console_set_groups
692
+ # Preconfigure tacacs, tacacs server and AAA valid group
693
+ group0 = 'tac_group'
694
+ preconfig_tacacs_server_access(group0)
695
+
696
+ # Preconfig for test
697
+ group1 = 'bxb100'
698
+ group2 = 'sjc200'
699
+ group3 = 'rtp10'
700
+ servers = [group1, group2, group3]
701
+ config_tacacs_servers(servers)
702
+
703
+ # Commands, service console
704
+ type_str = 'commands'
705
+ type = :commands
706
+ service = 'console'
707
+ aaa_a_service = AaaAuthorizationService.new(type, service)
708
+
709
+ # Single group, with method 'unselected'
710
+ method = :unselected
711
+ groups = [group0]
712
+ aaa_a_service.groups_method_set(groups, method)
713
+
714
+ p = /#{prefix} #{type_str} #{service} group #{group0}/
715
+ assert_show_match(command: show_cmd, pattern: p)
716
+
717
+ # Multi group, with method 'unselected'
718
+ method = :unselected
719
+ groups = [group0, group1, group2]
720
+ aaa_a_service.groups_method_set(groups, method)
721
+
722
+ p = /#{prefix} #{type_str} #{service} group #{group0} #{group1} #{group2}/
723
+ assert_show_match(command: show_cmd, pattern: p)
724
+
725
+ # Multi group, with method 'local'
726
+ method = :local
727
+ groups = [group0, group1, group3]
728
+ aaa_a_service.groups_method_set(groups, method)
729
+
730
+ group_str = "group #{group0} #{group1} #{group3}"
731
+ p = /#{prefix} #{type_str} #{service} #{group_str} local/
732
+ assert_show_match(command: show_cmd, pattern: p)
733
+
734
+ # Default group and method
735
+ method = aaa_a_service.default_method
736
+ groups = aaa_a_service.default_groups
737
+ aaa_a_service.groups_method_set(groups, method)
738
+
739
+ p = /#{prefix} #{type_str} #{service} local/
740
+ assert_show_match(command: show_cmd, pattern: p)
741
+
742
+ aaa_a_service.destroy
743
+
744
+ # Unconfigure tacacs, tacacs server and AAA valid group
745
+ preconfig_tacacs_server_access(group0, false)
746
+ end
747
+
748
+ def test_config_commands_default_set_groups
749
+ # Preconfigure tacacs, tacacs server and AAA valid group
750
+ group0 = 'tac_group'
751
+ preconfig_tacacs_server_access(group0)
752
+
753
+ # Preconfig for test
754
+ group1 = 'bxb100'
755
+ group2 = 'sjc200'
756
+ group3 = 'rtp10'
757
+ servers = [group1, group2, group3]
758
+ config_tacacs_servers(servers)
759
+
760
+ # Commands, service default
761
+ type_str = 'config-commands'
762
+ type = :config_commands
763
+ service = 'default'
764
+ aaa_a_service = AaaAuthorizationService.new(type, service)
765
+
766
+ # Single group, with method 'unselected'
767
+ method = :unselected
768
+ groups = [group0]
769
+ aaa_a_service.groups_method_set(groups, method)
770
+
771
+ p = /#{prefix} #{type_str} #{service} group #{group0}/
772
+ assert_show_match(command: show_cmd, pattern: p)
773
+
774
+ # Multi group, with method 'unselected'
775
+ method = :unselected
776
+ groups = [group0, group1, group2]
777
+ aaa_a_service.groups_method_set(groups, method)
778
+
779
+ p = /#{prefix} #{type_str} #{service} group #{group0} #{group1} #{group2}/
780
+ assert_show_match(command: show_cmd, pattern: p)
781
+
782
+ # Multi group, with method 'local'
783
+ method = :local
784
+ groups = [group0, group1, group3]
785
+ aaa_a_service.groups_method_set(groups, method)
786
+
787
+ group_str = "group #{group0} #{group1} #{group3}"
788
+ p = /#{prefix} #{type_str} #{service} #{group_str} local/
789
+ assert_show_match(command: show_cmd, pattern: p)
790
+
791
+ # Default group and method
792
+ method = aaa_a_service.default_method
793
+ groups = aaa_a_service.default_groups
794
+ aaa_a_service.groups_method_set(groups, method)
795
+
796
+ p = /#{prefix} #{type_str} #{service} local/
797
+ assert_show_match(command: show_cmd, pattern: p)
798
+
799
+ aaa_a_service.destroy
800
+
801
+ # Unconfigure tacacs, tacacs server and AAA valid group
802
+ preconfig_tacacs_server_access(group0, false)
803
+ end
804
+
805
+ def test_config_commands_console_set_groups
806
+ # Preconfigure tacacs, tacacs server and AAA valid group
807
+ group0 = 'tac_group'
808
+ preconfig_tacacs_server_access(group0)
809
+
810
+ # Preconfig for test
811
+ group1 = 'bxb100'
812
+ group2 = 'sjc200'
813
+ group3 = 'rtp10'
814
+ servers = [group1, group2, group3]
815
+ config_tacacs_servers(servers)
816
+
817
+ # Commands, service console
818
+ type_str = 'config-commands'
819
+ type = :config_commands
820
+ service = 'console'
821
+ aaa_a_service = AaaAuthorizationService.new(type, service)
822
+
823
+ # Single group, with method 'unselected'
824
+ method = :unselected
825
+ groups = [group0]
826
+ aaa_a_service.groups_method_set(groups, method)
827
+
828
+ p = /#{prefix} #{type_str} #{service} group #{group0}/
829
+ assert_show_match(command: show_cmd, pattern: p)
830
+
831
+ # Multi group, with method 'unselected'
832
+ method = :unselected
833
+ groups = [group0, group1, group2]
834
+ aaa_a_service.groups_method_set(groups, method)
835
+
836
+ p = /#{prefix} #{type_str} #{service} group #{group0} #{group1} #{group2}/
837
+ assert_show_match(command: show_cmd, pattern: p)
838
+
839
+ # Multi group, with method 'local'
840
+ method = :local
841
+ groups = [group0, group1, group3]
842
+ aaa_a_service.groups_method_set(groups, method)
843
+
844
+ group_str = "group #{group0} #{group1} #{group3}"
845
+ p = /#{prefix} #{type_str} #{service} #{group_str} local/
846
+ assert_show_match(command: show_cmd, pattern: p)
847
+
848
+ # Default group and method
849
+ method = aaa_a_service.default_method
850
+ groups = aaa_a_service.default_groups
851
+ aaa_a_service.groups_method_set(groups, method)
852
+
853
+ p = /#{prefix} #{type_str} #{service} local/
854
+ assert_show_match(command: show_cmd, pattern: p)
855
+
856
+ aaa_a_service.destroy
857
+
858
+ # Unconfigure tacacs, tacacs server and AAA valid group
859
+ preconfig_tacacs_server_access(group0, false)
860
+ end
861
+
862
+ def test_commands_invalid_groups_method_set_groups
863
+ # preconfig servers
864
+ servers = %w(bxb100 sjc200 rtp10)
865
+ config_tacacs_servers(servers)
866
+
867
+ # Commands, with service default
868
+ type = :commands
869
+ service = 'default'
870
+ aaa_a_service = AaaAuthorizationService.new(type, service)
871
+
872
+ # Single invalid group
873
+ groups = ['test1']
874
+ assert_raises(Cisco::CliError) do
875
+ aaa_a_service.groups_method_set(groups, :unselected)
876
+ end
877
+
878
+ # Multi groups with invalid group
879
+ groups = %w(rtp10 test2 bxb100)
880
+ assert_raises(Cisco::CliError) do
881
+ aaa_a_service.groups_method_set(groups, :local)
882
+ end
883
+ aaa_a_service.destroy
884
+
885
+ # Repeat the test for service 'console'
886
+ service = 'console'
887
+ aaa_a_service = AaaAuthorizationService.new(type, service)
888
+
889
+ # Single invalid group
890
+ groups = ['test1']
891
+ assert_raises(Cisco::CliError) do
892
+ aaa_a_service.groups_method_set(groups, :unselected)
893
+ end
894
+
895
+ # Multi group with invalid group
896
+ groups = %w(rtp10 test1 bxb100)
897
+ assert_raises(Cisco::CliError) do
898
+ aaa_a_service.groups_method_set(groups, :local)
899
+ end
900
+
901
+ # Multiple group with group and invalid method
902
+ groups = %w(rtp10 bxb100)
903
+ assert_raises(TypeError) do
904
+ aaa_a_service.groups_method_set(groups, 45)
905
+ end
906
+
907
+ aaa_a_service.destroy
908
+ end
909
+
910
+ def test_config_commands_invalid_set_groups
911
+ # preconfig servers
912
+ servers = %w(bxb100 sjc200 rtp10)
913
+ config_tacacs_servers(servers)
914
+
915
+ # Commands, with service default
916
+ type = :config_commands
917
+ service = 'default'
918
+ aaa_a_service = AaaAuthorizationService.new(type, service)
919
+
920
+ # Single invalid group
921
+ groups = ['test1']
922
+ assert_raises(Cisco::CliError) do
923
+ aaa_a_service.groups_method_set(groups, :unselected)
924
+ end
925
+
926
+ # Multi groups with invalid group
927
+ groups = %w(rtp10 test2 bxb100)
928
+ assert_raises(Cisco::CliError) do
929
+ aaa_a_service.groups_method_set(groups, :local)
930
+ end
931
+ aaa_a_service.destroy
932
+
933
+ # Repeat the test for service 'console'
934
+ service = 'console'
935
+ aaa_a_service = AaaAuthorizationService.new(type, service)
936
+
937
+ # one invalid group
938
+ groups = ['test1']
939
+ assert_raises(Cisco::CliError) do
940
+ aaa_a_service.groups_method_set(groups, :unselected)
941
+ end
942
+
943
+ # multiple group with invalid group
944
+ groups = %w(rtp10 test1 bxb100)
945
+ assert_raises(Cisco::CliError) do
946
+ aaa_a_service.groups_method_set(groups, :local)
947
+ end
948
+
949
+ # Multiple group with group and invalid method
950
+ groups = %w(rtp10 bxb100)
951
+ assert_raises(TypeError) do
952
+ aaa_a_service.groups_method_set(groups, 45)
953
+ end
954
+
955
+ aaa_a_service.destroy
956
+ end
957
+
958
+ def test_commands_invalid_method
959
+ # preconfig servers
960
+ servers = %w(bxb100 sjc200 rtp10)
961
+ config_tacacs_servers(servers)
962
+
963
+ # Commands, with service default
964
+ type = :commands
965
+ service = 'default'
966
+ aaa_a_service = AaaAuthorizationService.new(type, service)
967
+
968
+ # No group and invalid method
969
+ groups = []
970
+ assert_raises(TypeError) do
971
+ aaa_a_service.groups_method_set(groups, 'test')
972
+ end
973
+
974
+ # Multiple group with group and invalid method
975
+ groups = %w(rtp10 bxb100)
976
+ assert_raises(TypeError) do
977
+ aaa_a_service.groups_method_set(groups, 45)
978
+ end
979
+ aaa_a_service.destroy
980
+
981
+ # Repeat the test for service 'console'
982
+ service = 'console'
983
+ aaa_a_service = AaaAuthorizationService.new(type, service)
984
+
985
+ # No group and invalid method
986
+ groups = []
987
+ assert_raises(TypeError) do
988
+ aaa_a_service.groups_method_set(groups, 'test')
989
+ end
990
+
991
+ # Multiple group with group and invalid method
992
+ groups = %w(rtp10 bxb100)
993
+ assert_raises(TypeError) do
994
+ aaa_a_service.groups_method_set(groups, 45)
995
+ end
996
+
997
+ aaa_a_service.destroy
998
+ end
999
+
1000
+ def test_config_commands_invalid_method
1001
+ # preconfig servers
1002
+ servers = %w(bxb100 sjc200 rtp10)
1003
+ config_tacacs_servers(servers)
1004
+
1005
+ # Commands, with service default
1006
+ type = :config_commands
1007
+ service = 'default'
1008
+ aaa_a_service = AaaAuthorizationService.new(type, service)
1009
+
1010
+ # No group and invalid method
1011
+ groups = []
1012
+ assert_raises(TypeError) do
1013
+ aaa_a_service.groups_method_set(groups, 'test')
1014
+ end
1015
+
1016
+ # Multiple group with group and invalid method
1017
+ groups = %w(rtp10 bxb100)
1018
+ assert_raises(TypeError) do
1019
+ aaa_a_service.groups_method_set(groups, 45)
1020
+ end
1021
+ aaa_a_service.destroy
1022
+
1023
+ # Repeat the test for service 'console'
1024
+ service = 'console'
1025
+ aaa_a_service = AaaAuthorizationService.new(type, service)
1026
+
1027
+ # No group and invalid method
1028
+ groups = []
1029
+ assert_raises(TypeError) do
1030
+ aaa_a_service.groups_method_set(groups, 'test')
1031
+ end
1032
+
1033
+ # Multiple group with group and invalid method
1034
+ groups = %w(rtp10 bxb100)
1035
+ assert_raises(TypeError) do
1036
+ aaa_a_service.groups_method_set(groups, 45)
1037
+ end
1038
+
1039
+ aaa_a_service.destroy
1040
+ end
1041
+ end