exception_spec.rb 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. require 'rspec'
  2. RSpec.describe 'Metasploit Exceptions' do
  3. describe Msf::OptionValidateError do
  4. describe '#new' do
  5. it 'supports no options being provided' do
  6. subject = described_class.new
  7. expect(subject.options).to eq([])
  8. expect(subject.reasons).to eq({})
  9. end
  10. it 'supports a custom message' do
  11. subject = described_class.new(message: 'custom message')
  12. expect(subject.options).to eq([])
  13. expect(subject.reasons).to eq({})
  14. expect(subject.message).to eq 'custom message'
  15. end
  16. it 'supports a default message' do
  17. subject = described_class.new(['OptionName'])
  18. expect(subject.options).to eq(['OptionName'])
  19. expect(subject.reasons).to eq({})
  20. expect(subject.message).to eq 'The following options failed to validate: OptionName.'
  21. end
  22. it 'supports only options being provided' do
  23. subject = described_class.new(['RHOSTS'])
  24. expect(subject.options).to eq(['RHOSTS'])
  25. expect(subject.reasons).to eq({})
  26. end
  27. it 'supports a hash of options being provided, with associated string error reasons' do
  28. subject = described_class.new(
  29. {
  30. 'RHOSTS' => 'Human readable description'
  31. }
  32. )
  33. expect(subject.options).to eq(['RHOSTS'])
  34. expect(subject.reasons).to eq(
  35. {
  36. 'RHOSTS' => ['Human readable description']
  37. }
  38. )
  39. end
  40. it 'supports a hash of options being provided, with an array of string error reasons' do
  41. subject = described_class.new(
  42. {
  43. 'RHOSTS' => [
  44. 'Human readable description 1',
  45. 'Human readable description 2',
  46. ]
  47. }
  48. )
  49. expect(subject.options).to eq(['RHOSTS'])
  50. expect(subject.reasons).to eq(
  51. {
  52. 'RHOSTS' => [
  53. 'Human readable description 1',
  54. 'Human readable description 2',
  55. ]
  56. }
  57. )
  58. end
  59. it 'supports both options and error reasons being provided' do
  60. subject = described_class.new(
  61. [
  62. 'RHOSTS',
  63. 'RPORT'
  64. ],
  65. reasons: {
  66. 'RHOSTS' => 'Human readable description'
  67. }
  68. )
  69. expect(subject.options).to eq(['RHOSTS', 'RPORT'])
  70. expect(subject.reasons).to eq(
  71. {
  72. 'RHOSTS' => ['Human readable description']
  73. }
  74. )
  75. end
  76. end
  77. end
  78. end