| 44 | | # Verify that a new device isn't valid unless its attributes have been |
|---|
| 45 | | # supplied |
|---|
| 46 | | |
|---|
| 47 | | def test_invalid_with_empty_attributes |
|---|
| 48 | | |
|---|
| 49 | | device = Device.new |
|---|
| 50 | | |
|---|
| 51 | | assert(!device.valid?, "A new device should not be valid without attributes set") |
|---|
| 52 | | |
|---|
| 53 | | end |
|---|
| 54 | | |
|---|
| 55 | | |
|---|
| 56 | | # Verify that a new device is created with an SNMP version set |
|---|
| 57 | | |
|---|
| 58 | | def test_new_device_has_snmp_version_set |
|---|
| 59 | | |
|---|
| 60 | | device = Device.new |
|---|
| 61 | | |
|---|
| 62 | | assert(!device.snmp_version.nil?, "A new device should have an SNMP version set by default") |
|---|
| 63 | | |
|---|
| 64 | | end |
|---|
| 65 | | |
|---|
| 66 | | |
|---|
| 67 | | # Verify that a device is not valid unless it has a hostname and IPv4 address |
|---|
| 68 | | |
|---|
| 69 | | def test_invalid_with_only_hostname |
|---|
| 70 | | |
|---|
| 71 | | device = Device.new |
|---|
| 72 | | device.hostname = "example" |
|---|
| 73 | | assert(!device.valid?, "A device should not be valid with only a hostname set") |
|---|
| 74 | | |
|---|
| 75 | | device.hostname = nil |
|---|
| 76 | | |
|---|
| 77 | | device.ipv4_address = "1.2.3.4" |
|---|
| 78 | | assert(!device.valid?, "A new device should not be valid with only a management IP address set") |
|---|
| 79 | | |
|---|
| 80 | | end |
|---|
| 81 | | |
|---|
| 82 | | |
|---|
| 83 | | # Verify that a new device is valid with a hostname and IPv4 address |
|---|
| 84 | | |
|---|
| 85 | | def test_valid_with_hostname_and_ipv4_address |
|---|
| 86 | | |
|---|
| 87 | | device = Device.new |
|---|
| 88 | | device.hostname = "example" |
|---|
| 89 | | device.ipv4_address = "127.0.0.1" |
|---|
| 90 | | |
|---|
| 91 | | assert(device.valid?, "A new device should be valid with a hostname and management IP address set") |
|---|
| 92 | | |
|---|
| 93 | | end |
|---|
| 94 | | |
|---|
| 95 | | |
|---|
| 96 | | # Verify that a device can be associated with a site and the association works correctly |
|---|
| 97 | | |
|---|
| 98 | | def test_device_to_site_association |
|---|
| 99 | | |
|---|
| 100 | | site = Site.new |
|---|
| 101 | | site.description = "example site" |
|---|
| 102 | | site.save |
|---|
| 103 | | |
|---|
| 104 | | device = Device.new |
|---|
| 105 | | device.hostname = "example device" |
|---|
| 106 | | device.ipv4_address = "127.0.0.1" |
|---|
| 107 | | device.site_id = site.id |
|---|
| 108 | | device.site.description = "example site" |
|---|
| 109 | | device.save |
|---|
| 110 | | |
|---|
| 111 | | assert(device.site.description == "example site", "A device should be able to be associated with a new site") |
|---|
| 112 | | |
|---|
| 113 | | end |
|---|
| 114 | | |
|---|
| 115 | | |
|---|
| 116 | | # Verify the is_manageable method returns false if no SNMP community string has been entered |
|---|
| 117 | | |
|---|
| 118 | | def test_is_manageable_method_false |
|---|
| 119 | | |
|---|
| 120 | | device = Device.new |
|---|
| 121 | | device.hostname = "example" |
|---|
| 122 | | device.ipv4_address = "127.0.0.1" |
|---|
| 123 | | |
|---|
| 124 | | assert(!device.is_manageable?, "A device without an SNMP community string should not be 'manageable'") |
|---|
| 125 | | |
|---|
| 126 | | end |
|---|
| 127 | | |
|---|
| 128 | | |
|---|
| 129 | | # Verify the is_manageable method returns true if an SNMP community string has been entered |
|---|
| 130 | | |
|---|
| 131 | | def test_is_manageable_method_true |
|---|
| 132 | | |
|---|
| 133 | | device = Device.new |
|---|
| 134 | | device.hostname = "example" |
|---|
| 135 | | device.ipv4_address = "127.0.0.1" |
|---|
| 136 | | device.snmp_community = "sample" |
|---|
| 137 | | |
|---|
| 138 | | assert(device.is_manageable?, "A device with an SNMP community string should be manageable") |
|---|
| 139 | | |
|---|
| 140 | | end |
|---|
| 141 | | |
|---|
| 142 | | |
|---|
| 143 | | # Verify that the ipv4_address_long attribute is correctly populated when |
|---|
| 144 | | # set to 0.0.0.0 |
|---|
| 145 | | |
|---|
| 146 | | def test_ipv4_address_long_population_low |
|---|
| 147 | | |
|---|
| 148 | | device = Device.new |
|---|
| 149 | | device.ipv4_address = "0.0.0.0" |
|---|
| 150 | | device.valid? |
|---|
| 151 | | |
|---|
| 152 | | assert(device.ipv4_address_long == 0, "A device with an IPv4 address of 0.0.0.0 should have a long IPv4 address of 0") |
|---|
| 153 | | |
|---|
| 154 | | end |
|---|
| 155 | | |
|---|
| 156 | | |
|---|
| 157 | | # Verify that the ipv4_address_long attribute is correctly populated when |
|---|
| 158 | | # set to 255.255.255.255 |
|---|
| 159 | | |
|---|
| 160 | | def test_ipv4_address_long_population_high |
|---|
| 161 | | |
|---|
| 162 | | device = Device.new |
|---|
| 163 | | device.ipv4_address = "255.255.255.255" |
|---|
| 164 | | device.valid? |
|---|
| 165 | | |
|---|
| 166 | | assert(device.ipv4_address_long == 4294967295, "A device with an IPv4 address of 255.255.255.255 should have a long IPv4 address of 4294967295") |
|---|
| 167 | | |
|---|
| 168 | | end |
|---|
| 169 | | |
|---|
| 170 | | |
|---|
| 171 | | # Verify that the created_at and updated_at attributes are nil when a |
|---|
| 172 | | # record hasn't yet been saved |
|---|
| 173 | | |
|---|
| 174 | | def test_created_and_updated_attributes_are_nil_when_unsaved |
|---|
| 175 | | |
|---|
| 176 | | device = Device.new |
|---|
| 177 | | device.hostname = "example" |
|---|
| 178 | | device.ipv4_address = "127.0.0.1" |
|---|
| 179 | | device.valid? |
|---|
| 180 | | |
|---|
| 181 | | assert(device.created_at.nil? && device.updated_at.nil?, "The created_at and updated_at attributes of a new device should be nil before it has been saved") |
|---|
| 182 | | |
|---|
| 183 | | end |
|---|
| 184 | | |
|---|
| 185 | | |
|---|
| 186 | | # Verify that the created_at and updated_at attributes are equal when a |
|---|
| 187 | | # record has just been saved |
|---|
| 188 | | |
|---|
| 189 | | def test_created_and_updated_attributes_are_equal_when_saved |
|---|
| 190 | | |
|---|
| 191 | | device = Device.new |
|---|
| 192 | | device.hostname = "example" |
|---|
| 193 | | device.ipv4_address = "127.0.0.1" |
|---|
| 194 | | device.save |
|---|
| 195 | | |
|---|
| 196 | | assert(device.created_at == device.updated_at, "A new device should have identical created_at and updated_at values when first saved") |
|---|
| 197 | | |
|---|
| 198 | | end |
|---|
| 199 | | |
|---|
| 200 | | |
|---|
| 201 | | # Verify that the created_at attribute is less than the updated_at |
|---|
| 202 | | # attribute when a record has been saved and updated |
|---|
| 203 | | |
|---|
| 204 | | def test_created_is_less_than_updated_when_saved |
|---|
| 205 | | |
|---|
| 206 | | device = Device.new |
|---|
| 207 | | device.hostname = "example" |
|---|
| 208 | | device.ipv4_address = "127.0.0.1" |
|---|
| 209 | | device.save |
|---|
| 210 | | |
|---|
| 211 | | device.hostname = "anotherexample" |
|---|
| 212 | | device.save |
|---|
| 213 | | |
|---|
| 214 | | assert(device.created_at < device.updated_at, "A device's created_at should be before its updated_at if it is updated after initial creation") |
|---|
| 215 | | |
|---|
| 216 | | end |
|---|
| 217 | | |
|---|
| 218 | | |
|---|
| 219 | | # Verify the only SNMP versions acceptable are nil, 1, 2 or 3 |
|---|
| 220 | | |
|---|
| 221 | | def test_snmp_versions |
|---|
| 222 | | |
|---|
| 223 | | device = Device.new |
|---|
| 224 | | device.hostname = "example" |
|---|
| 225 | | device.ipv4_address = "127.0.0.1" |
|---|
| 226 | | |
|---|
| 227 | | device.snmp_version = 1 |
|---|
| 228 | | assert(device.valid?, "A device should be valid with an SNMP version of 1") |
|---|
| 229 | | |
|---|
| 230 | | device.snmp_version = 2 |
|---|
| 231 | | assert(device.valid?, "A device should be valid with an SNMP version of 2") |
|---|
| 232 | | |
|---|
| 233 | | device.snmp_version = 3 |
|---|
| 234 | | assert(device.valid?, "A device should be valid with an SNMP version of 3") |
|---|
| 235 | | |
|---|
| 236 | | device.snmp_version = nil |
|---|
| 237 | | assert(device.valid?, "A device should be valid with a nil SNMP version") |
|---|
| 238 | | |
|---|
| 239 | | device.snmp_version = 4 |
|---|
| 240 | | assert(!device.valid?, "A device should not be valid with an SNMP version of 4") |
|---|
| 241 | | |
|---|
| 242 | | device.snmp_version = "garbage" |
|---|
| 243 | | assert(!device.valid?, "A device should not be valid with an SNMP version of 'garbage'") |
|---|
| 244 | | |
|---|
| 245 | | end |
|---|
| 246 | | |
|---|
| 247 | | |
|---|
| 248 | | # Verify the only SNMPv3 security protocols acceptable are SHA or MD5 |
|---|
| 249 | | |
|---|
| 250 | | def test_snmpv3_security_protocols |
|---|
| 251 | | |
|---|
| 252 | | device = Device.new |
|---|
| 253 | | device.hostname = "example" |
|---|
| 254 | | device.ipv4_address = "127.0.0.1" |
|---|
| 255 | | |
|---|
| 256 | | device.snmpv3_auth_protocol = "SHA" |
|---|
| 257 | | assert(device.valid?, "A device should be valid with an SNMPv3 security protocol of SHA") |
|---|
| 258 | | |
|---|
| 259 | | device.snmpv3_auth_protocol = "MD5" |
|---|
| 260 | | assert(device.valid?, "A device should be valid with an SNMPv3 security protocol of MD5") |
|---|
| 261 | | |
|---|
| 262 | | device.snmpv3_auth_protocol = "garbage" |
|---|
| 263 | | assert(!device.valid?, "A device should not be valid with an invalid SNMPv3 security protocol") |
|---|
| 264 | | |
|---|
| 265 | | end |
|---|
| 266 | | |
|---|
| 267 | | |
|---|
| 268 | | # Verify the only SNMPv3 privacy levels acceptable are DES or AES |
|---|
| 269 | | |
|---|
| 270 | | def test_snmpv3_privacy_protocols |
|---|
| 271 | | |
|---|
| 272 | | device = Device.new |
|---|
| 273 | | device.hostname = "example" |
|---|
| 274 | | device.ipv4_address = "127.0.0.1" |
|---|
| 275 | | |
|---|
| 276 | | device.snmpv3_priv_protocol = "DES" |
|---|
| 277 | | assert(device.valid?, "A device should be valid with an SNMPv3 privacy protocol of DES") |
|---|
| 278 | | |
|---|
| 279 | | device.snmpv3_priv_protocol = "AES" |
|---|
| 280 | | assert(device.valid?, "A device should be valid with an SNMPv3 privacy protocol of AES") |
|---|
| 281 | | |
|---|
| 282 | | device.snmpv3_priv_protocol = "garbage" |
|---|
| 283 | | assert(!device.valid?, "A device should not be valid with an invalid SNMPv3 privacy protocol") |
|---|
| 284 | | |
|---|
| 285 | | end |
|---|
| 286 | | |
|---|
| 287 | | |
|---|
| 288 | | # Verify the only SNMPv3 security levels acceptable are noAuthNoPriv, |
|---|
| 289 | | # authNoPriv or authPriv |
|---|
| 290 | | |
|---|
| 291 | | def test_snmpv3_privacy_levels |
|---|
| 292 | | |
|---|
| 293 | | device = Device.new |
|---|
| 294 | | device.hostname = "example" |
|---|
| 295 | | device.ipv4_address = "127.0.0.1" |
|---|
| 296 | | |
|---|
| 297 | | device.snmpv3_security_level = "noAuthNoPriv" |
|---|
| 298 | | assert(device.valid?, "A device should be valid with an SNMPv3 security level of noAuthNoPriv") |
|---|
| 299 | | |
|---|
| 300 | | device.snmpv3_security_level = "authNoPriv" |
|---|
| 301 | | assert(device.valid?, "A device should be valid with an SNMPv3 security level of authNoPriv") |
|---|
| 302 | | |
|---|
| 303 | | device.snmpv3_security_level = "authPriv" |
|---|
| 304 | | assert(device.valid?, "A device should be valid with an SNMPv3 security level of authPriv") |
|---|
| 305 | | |
|---|
| 306 | | device.snmpv3_security_level = "garbage" |
|---|
| 307 | | assert(!device.valid?, "A device should not be valid with an invalid SNMPv3 security level") |
|---|
| 308 | | |
|---|
| 309 | | end |
|---|
| 310 | | |
|---|
| 311 | | |
|---|