spec/inputs/snmp_spec.rb in logstash-input-snmp-0.1.0.beta4 vs spec/inputs/snmp_spec.rb in logstash-input-snmp-0.1.0.beta5

- old
+ new

@@ -56,10 +56,11 @@ {"get" => ["1.0"], "hosts" => [{"host" => "udp:127.0.0.1/161", "community" => "public"}]}, {"get" => ["1.0"], "hosts" => [{"host" => "tcp:127.0.0.1/112345"}]}, {"get" => ["1.0"], "hosts" => [{"host" => "tcp:127.0.0.1/161", "community" => "public"}]}, {"get" => ["1.0"], "hosts" => [{"host" => "udp:127.0.0.1/161", "version" => "1"}]}, {"get" => ["1.0"], "hosts" => [{"host" => "udp:127.0.0.1/161", "version" => "2c"}]}, + {"get" => ["1.0"], "hosts" => [{"host" => "udp:127.0.0.1/161", "version" => "3"}], "security_name" => "v3user"}, ] } let(:invalid_configs) { [ @@ -70,17 +71,42 @@ {"get" => ["1.0"], "hosts" => [{"host" => "udp:127.0.0.1"}]}, {"get" => ["1.0"], "hosts" => [{"host" => "udp:127.0.0.1/"}]}, {"get" => ["1.0"], "hosts" => [{"host" => "udp:127.0.0.1/aaa"}]}, {"get" => ["1.0"], "hosts" => [{"host" => "udp:127.0.0.1/161"}, {"host" => "udp:127.0.0.1/aaa"}]}, {"get" => ["1.0"], "hosts" => [{"host" => "udp:127.0.0.1/161", "version" => "2"}]}, - {"get" => ["1.0"], "hosts" => [{"host" => "udp:127.0.0.1/161", "version" => "3"}]}, + {"get" => ["1.0"], "hosts" => [{"host" => "udp:127.0.0.1/161", "version" => "3a"}]}, {"get" => ["1.0"], "hosts" => ""}, {"get" => ["1.0"], "hosts" => []}, {"get" => ["1.0"] }, ] } it "validates hosts" do + valid_configs.each do |config| + expect{ described_class.new(config).register }.not_to raise_error + end + invalid_configs.each do |config| + expect{ described_class.new(config).register }.to raise_error(LogStash::ConfigurationError) + end + end + end + + context "v3_users options validation" do + let(:valid_configs) { + [ + {"get" => ["1.0"], "hosts" => [{"host" => "udp:127.0.0.1/161", "version" => "3"}], "security_name" => "ciscov3", "auth_protocol" => "sha", "auth_pass" => "myshapass", "priv_protocol" => "aes", "priv_pass" => "myprivpass", "security_level" => "authNoPriv"}, + {"get" => ["1.0"], "hosts" => [{"host" => "udp:127.0.0.1/161", "version" => "3"}], "security_name" => "dellv3", "auth_protocol" => "md5", "auth_pass" => "myshapass", "priv_protocol" => "3des", "priv_pass" => "myprivpass", "security_level" => "authNoPriv"} + ] + } + + let(:invalid_configs) { + [ + {"get" => ["1.0"], "hosts" => [{"host" => "udp:127.0.0.1/161", "version" => "3"}], "security_name" => "ciscov3", "auth_protocol" => "badauth", "auth_pass" => "myshapass", "priv_protocol" => "aes", "priv_pass" => "myprivpass", "security_level" => "authNoPriv"}, + {"get" => ["1.0"], "hosts" => [{"host" => "udp:127.0.0.1/161", "version" => "3"}], "security_name" => "ciscov3", "auth_protocol" => "sha"} + ] + } + + it "validates v3_users" do valid_configs.each do |config| expect{ described_class.new(config).register }.not_to raise_error end invalid_configs.each do |config| expect{ described_class.new(config).register }.to raise_error(LogStash::ConfigurationError)