/spec/lib/msf/core/data_store_spec.rb

https://github.com/debbiemezyene/metasploit-framework · Ruby · 79 lines · 65 code · 12 blank · 2 comment · 11 complexity · 17813279df7515ddad09022162187d97 MD5 · raw file

  1. # -*- coding:binary -*-
  2. require 'spec_helper'
  3. require 'msf/core/data_store'
  4. shared_examples "datastore" do
  5. it "should have options" do
  6. subject["foo"].should == "bar"
  7. subject["fizz"].should == "buzz"
  8. end
  9. it "should have case-insensitive keys" do
  10. # Sorted by gray code, just for fun
  11. subject["foo"].should == "bar"
  12. subject["Foo"].should == "bar"
  13. subject["FOo"].should == "bar"
  14. subject["fOo"].should == "bar"
  15. subject["fOO"].should == "bar"
  16. subject["FOO"].should == "bar"
  17. subject["FoO"].should == "bar"
  18. subject["foO"].should == "bar"
  19. end
  20. context "#to_h" do
  21. it "should return a Hash with correct values" do
  22. subject.to_h.should == { "foo" => "bar", "fizz" => "buzz" }
  23. end
  24. end
  25. end
  26. describe Msf::DataStore do
  27. describe "#import_option" do
  28. subject do
  29. s = described_class.new
  30. s.import_option("foo", "bar")
  31. s.import_option("fizz", "buzz")
  32. s
  33. end
  34. it_behaves_like "datastore"
  35. end
  36. describe "#import_options_from_hash" do
  37. subject do
  38. hash = { "foo" => "bar", "fizz" => "buzz" }
  39. s = described_class.new
  40. s.import_options_from_hash(hash)
  41. s
  42. end
  43. it_behaves_like "datastore"
  44. end
  45. describe "#import_options_from_s" do
  46. subject do
  47. str = "foo=bar fizz=buzz"
  48. s = described_class.new
  49. s.import_options_from_s(str)
  50. s
  51. end
  52. it_behaves_like "datastore"
  53. end
  54. describe "#from_file" do
  55. subject do
  56. ini_instance = double
  57. ini_instance.stub(:group?).and_return(true)
  58. ini_instance.stub(:[]).and_return( { "foo" => "bar", "fizz" => "buzz" } )
  59. ini = stub_const("Rex::Parser::Ini", Class.new)
  60. ini.stub(:from_file).and_return(ini_instance)
  61. s = described_class.new
  62. s.from_file("path")
  63. s
  64. end
  65. it_behaves_like "datastore"
  66. end
  67. end