metasploit-credential 0.7.11 → 0.7.12

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,22 +5,51 @@ describe Metasploit::Credential::Importer::Multi do
5
5
  include_context 'metasploit_credential_importer_zip_file'
6
6
 
7
7
  UNSUPPORTED_FILE = 'bad.txt'
8
+ INVALID_CSV_FILE = 'malformed.csv'
9
+ VALID_CSV_FILE = 'well-formed.csv'
8
10
 
9
11
  let(:import_origin){ FactoryGirl.create :metasploit_credential_origin_import }
12
+ let(:supported_file){ FactoryGirl.generate :metasploit_credential_importer_zip_file }
13
+ let(:unsupported_file){ File.open("#{Dir.tmpdir}/#{UNSUPPORTED_FILE}", 'wb') }
14
+
15
+ let(:invalid_csv){ FactoryGirl.generate(:malformed_csv)}
16
+ let(:valid_csv){ FactoryGirl.generate(:well_formed_csv_compliant_header)}
17
+
18
+ let(:valid_csv_file) do
19
+ File.open("#{Dir.tmpdir}/#{VALID_CSV_FILE}", 'w') do |file|
20
+ file << valid_csv.read
21
+ end
22
+ end
10
23
 
11
24
  describe "validation" do
12
25
  describe "when given a file that is not a zip or a CSV" do
13
- let(:unsupported_file){ File.open("#{Dir.tmpdir}/#{UNSUPPORTED_FILE}", 'wb') }
14
- subject(:multi_importer){ Metasploit::Credential::Importer::Multi.new(input: unsupported_file, origin: import_origin)}
26
+ subject(:multi_importer){ Metasploit::Credential::Importer::Multi.new(input: File.open(unsupported_file), origin: import_origin)}
15
27
 
16
28
  it { should_not be_valid }
17
29
  end
18
30
 
19
31
  context "when given zip file" do
20
- let(:supported_file){ FactoryGirl.generate :metasploit_credential_importer_zip_file }
21
- subject(:multi_importer){ Metasploit::Credential::Importer::Multi.new(input: supported_file, origin: import_origin)}
32
+ subject(:multi_importer){ Metasploit::Credential::Importer::Multi.new(input: File.open(supported_file), origin: import_origin)}
22
33
 
23
34
  it { should be_valid }
24
35
  end
36
+
37
+ describe "#csv?" do
38
+ describe 'when the file can be opened as a CSV' do
39
+ subject(:multi_importer){ Metasploit::Credential::Importer::Multi.new(input: File.open(valid_csv_file), origin: import_origin)}
40
+
41
+ it 'should return true' do
42
+ multi_importer.csv?.should be_true
43
+ end
44
+ end
45
+
46
+ describe 'when the file is not a well-formed CSV' do
47
+ subject(:multi_importer){ Metasploit::Credential::Importer::Multi.new(input: File.open(unsupported_file), origin: import_origin)}
48
+
49
+ it 'should return true' do
50
+ multi_importer.csv?.should be_false
51
+ end
52
+ end
53
+ end
25
54
  end
26
55
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metasploit-credential
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.11
4
+ version: 0.7.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luke Imhoff