virustotal_api 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1bed8beb641ac85649be4628d37065079d3f2c881499a67065200eeba57f2176
4
- data.tar.gz: a55ce4ed4bdc573607389e20578efd53f10d7ab1597b3deb05644571dac752c6
3
+ metadata.gz: 549e10acf953216ded9295c21129e76fc737bd63f29703af799499c6feed2c6e
4
+ data.tar.gz: d20c12d67d748d329e3b0e340a4857115d516d942af5e3a282bb72e80a90e373
5
5
  SHA512:
6
- metadata.gz: 13c8674a48591fd1c063a4d76040555aeace01a19981feb558241ff1843984f2e8052c6169bec8a1ec4f63519e14bf9b3a109fcf7f8fc667d8a1e0cbfe7f99aa
7
- data.tar.gz: b64cfe0bfa5fa79927d22d591534f2b7db2b3ca7f572e8360b0423c3de5def7948f3264381e001596c095c66ec04187fe5fddf1d4148ad21bcf66a08eaf981ac
6
+ metadata.gz: 394ad7a9dbf0f4c59d7e286acd57974e042427f0f4c82d1c652195b0dca4d17a0eeed28cd82946da2a072679a824060bacf184c741ecd0578e383386295c328d
7
+ data.tar.gz: 0f9b0e2bc76a11d1b496ac1b0fb266875ed36cbfb51b27396396b555c3e47d5e411073e8bef956e1e44d08ec395e1165a45df8e525b24af6a0ae915d2c9c1b79
data/README.md CHANGED
@@ -117,7 +117,7 @@ vturl_report.exists?
117
117
 
118
118
  # URL for Report (if it exists)
119
119
  vturl_report.report_url
120
- # => "https://www.virustotal.com/api/v3/urls/dd014af5ed6b38d9130e3f466f850e46d21b951199d53a18ef29ee9341614eaf/"
120
+ # => "https://www.virustotal.com/api/v3/urls/dd014af5ed6b38d9130e3f466f850e46d21b951199d53a18ef29ee9341614eaf"
121
121
 
122
122
  # Report results (if they exist) are available via #report
123
123
  vturl_report.report['data']['attributes']['last_analysis_results']['Avira']
@@ -161,6 +161,10 @@ vtip_report = VirustotalAPI::IP.find(ip, api_key)
161
161
  vtip_report.exists?
162
162
  # => true
163
163
 
164
+ # URL for Report (if it exists)
165
+ vtip_report.report_url
166
+ # => "https://www.virustotal.com/api/v3/ip_addresses/8.8.8.8"
167
+
164
168
  # Report results (if they exist) are available via #report
165
169
  vtip_report.report
166
170
  # => Hash of report results
@@ -180,6 +184,10 @@ vtdomain_report = VirustotalAPI::Domain.find(domain, api_key)
180
184
  vtdomain_report.exists?
181
185
  # => true
182
186
 
187
+ # URL for Report (if it exists)
188
+ vtdomain_report.report_url
189
+ # => "https://www.virustotal.com/api/v3/domains/virustotal.com"
190
+
183
191
  # Report results (if they exist) are available via #report
184
192
  vtdomain_report.report
185
193
  # => Hash of report results
@@ -5,13 +5,6 @@ require_relative 'base'
5
5
  module VirustotalAPI
6
6
  # A class for '/analyses' API
7
7
  class Analysis < Base
8
- attr_reader :report
9
-
10
- # rubocop:disable Lint/MissingSuper
11
- def initialize(report)
12
- @report = report
13
- end
14
-
15
8
  # @param [String] id The Virustotal ID to get the report for.
16
9
  # @param [String] api_key The key for virustotal
17
10
  # @return [VirustotalAPI::IP] Report
@@ -21,4 +14,3 @@ module VirustotalAPI
21
14
  end
22
15
  end
23
16
  end
24
- # rubocop:enable Lint/MissingSuper
@@ -9,10 +9,12 @@ require 'base64'
9
9
  module VirustotalAPI
10
10
  # The base class implementing the raw calls to Virustotal API V3.
11
11
  class Base
12
- attr_reader :report
12
+ attr_reader :report, :report_url, :id
13
13
 
14
14
  def initialize(report)
15
15
  @report = report
16
+ @report_url = report&.dig('data', 'links', 'self')
17
+ @id = report&.dig('data', 'id')
16
18
  end
17
19
 
18
20
  # @return [String] string of API URI class method
@@ -5,11 +5,6 @@ require_relative 'base'
5
5
  module VirustotalAPI
6
6
  # A class for '/domains' API
7
7
  class Domain < Base
8
- # rubocop:disable Lint/UselessMethodDefinition
9
- def initialize(report)
10
- super(report)
11
- end
12
-
13
8
  # Find a domain.
14
9
  #
15
10
  # @param [String] domain The domain to search
@@ -21,4 +16,3 @@ module VirustotalAPI
21
16
  end
22
17
  end
23
18
  end
24
- # rubocop:enable Lint/UselessMethodDefinition
@@ -5,14 +5,6 @@ require_relative 'base'
5
5
  module VirustotalAPI
6
6
  # A class for '/files' API
7
7
  class File < Base
8
- attr_reader :id, :report_url
9
-
10
- def initialize(report)
11
- super(report)
12
- @id = report&.dig('data', 'id')
13
- @report_url = report&.dig('data', 'links', 'self')
14
- end
15
-
16
8
  # Find a hash.
17
9
  #
18
10
  # @param [String] resource file as a md5/sha1/sha256 hash
@@ -5,14 +5,6 @@ require_relative 'base'
5
5
  module VirustotalAPI
6
6
  # A class for '/groups' API
7
7
  class Group < Base
8
- attr_reader :report_url, :id
9
-
10
- def initialize(report)
11
- super(report)
12
- @report_url = report&.dig('data', 'links', 'self')
13
- @id = report&.dig('data', 'id')
14
- end
15
-
16
8
  # Find a Group.
17
9
  #
18
10
  # @param [String] group_id to find
@@ -5,11 +5,6 @@ require_relative 'base'
5
5
  module VirustotalAPI
6
6
  # A class for '/ip_addresses' API
7
7
  class IP < Base
8
- # rubocop:disable Lint/UselessMethodDefinition
9
- def initialize(report)
10
- super(report)
11
- end
12
-
13
8
  # Find an IP.
14
9
  #
15
10
  # @param [String] ip address The IP to find.
@@ -21,4 +16,3 @@ module VirustotalAPI
21
16
  end
22
17
  end
23
18
  end
24
- # rubocop:enable Lint/UselessMethodDefinition
@@ -5,14 +5,6 @@ require_relative 'base'
5
5
  module VirustotalAPI
6
6
  # A class for '/urls' API
7
7
  class URL < Base
8
- attr_reader :report_url, :id
9
-
10
- def initialize(report)
11
- super(report)
12
- @report_url = report&.dig('data', 'links', 'self')
13
- @id = report&.dig('data', 'id')
14
- end
15
-
16
8
  # Find a URL.
17
9
  #
18
10
  # @param [String] resource as an ip/domain/url
@@ -5,14 +5,6 @@ require_relative 'base'
5
5
  module VirustotalAPI
6
6
  # A class for '/users' API
7
7
  class User < Base
8
- attr_reader :report_url, :id
9
-
10
- def initialize(report)
11
- super(report)
12
- @report_url = report&.dig('data', 'links', 'self')
13
- @id = report&.dig('data', 'id')
14
- end
15
-
16
8
  # Find a User.
17
9
  #
18
10
  # @param [String] user_key with id or api_key
@@ -2,5 +2,5 @@
2
2
 
3
3
  module VirustotalAPI
4
4
  # The GEM version
5
- VERSION = '0.5.2'
5
+ VERSION = '0.5.3'
6
6
  end
@@ -11,13 +11,16 @@ class VirustotalAPIAnalysisTest < Minitest::Test
11
11
  def test_todo
12
12
  VCR.use_cassette('url_find') do
13
13
  vtreport = VirustotalAPI::URL.find(@url, @api_key)
14
+
14
15
  @id = vtreport.id
15
- assert @id
16
+ assert @id.is_a?(String)
16
17
  end
17
18
 
18
19
  VCR.use_cassette('analysis') do
19
20
  analysis = VirustotalAPI::Analysis.find(@id, @api_key)
21
+
20
22
  assert analysis.exists?
23
+ assert analysis.id.is_a?(String)
21
24
  end
22
25
  end
23
26
  end
@@ -17,16 +17,11 @@ class VirustotalAPIDomainTest < Minitest::Test
17
17
  vtdomain_report = VirustotalAPI::Domain.find(@domain, @api_key)
18
18
 
19
19
  # Make sure that the JSON was parsed
20
+ assert vtdomain_report.exists?
20
21
  assert vtdomain_report.is_a?(VirustotalAPI::Domain)
21
22
  assert vtdomain_report.report.is_a?(Hash)
22
- end
23
- end
24
-
25
- def test_exists?
26
- VCR.use_cassette('domain') do
27
- vtdomain_report = VirustotalAPI::Domain.find(@domain, @api_key)
28
-
29
- assert vtdomain_report.exists?
23
+ assert vtdomain_report.id.is_a?(String)
24
+ assert vtdomain_report.report_url.is_a?(String)
30
25
  end
31
26
  end
32
27
  end
@@ -4,9 +4,9 @@ require './test/test_helper'
4
4
 
5
5
  class VirustotalAPIFileTest < Minitest::Test
6
6
  def setup
7
- @sha256 = '01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b'
7
+ @sha256 = '01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b'
8
8
  @file_path = File.expand_path('test/fixtures/null_file')
9
- @api_key = 'testapikey'
9
+ @api_key = 'testapikey'
10
10
  end
11
11
 
12
12
  def test_class_exists
@@ -15,57 +15,49 @@ class VirustotalAPIFileTest < Minitest::Test
15
15
 
16
16
  def test_report_response
17
17
  VCR.use_cassette('file_find') do
18
- virustotal_report = VirustotalAPI::File.find(@sha256, @api_key)
18
+ vt_file_report = VirustotalAPI::File.find(@sha256, @api_key)
19
19
 
20
20
  # Make sure that the JSON was parsed
21
- assert virustotal_report.is_a?(VirustotalAPI::File)
22
- assert virustotal_report.report.is_a?(Hash)
21
+ assert vt_file_report.exists?
22
+ assert vt_file_report.is_a?(VirustotalAPI::File)
23
+ assert vt_file_report.report.is_a?(Hash)
24
+ assert vt_file_report.id.is_a?(String)
25
+ assert vt_file_report.report_url.is_a?(String)
23
26
  end
24
27
  end
25
28
 
26
29
  def test_find
27
- permalink = 'https://www.virustotal.com/api/v3/files/' \
28
- '01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b'
30
+ id = '01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b'
31
+ permalink = "https://www.virustotal.com/api/v3/files/#{id}"
32
+
29
33
  VCR.use_cassette('file_find') do
30
- virustotal_report = VirustotalAPI::File.find(@sha256, @api_key)
34
+ vt_file_report = VirustotalAPI::File.find(@sha256, @api_key)
31
35
 
32
- assert virustotal_report.report_url.is_a?(String)
33
- assert_equal permalink, virustotal_report.report_url
34
- assert virustotal_report.detected_by('Avira')
35
- assert !virustotal_report.detected_by('Acronis')
36
- assert !virustotal_report.detected_by('Yeyeyeye') # not present in file
36
+ assert_equal permalink, vt_file_report.report_url
37
+ assert_equal id, vt_file_report.id
38
+ assert vt_file_report.detected_by('Avira')
39
+ assert !vt_file_report.detected_by('Acronis')
40
+ assert !vt_file_report.detected_by('Yeyeyeye') # not present in file
37
41
  end
38
42
  end
39
43
 
40
44
  def test_upload
41
45
  VCR.use_cassette('file_upload') do
42
- virustotal_upload = VirustotalAPI::File.upload(@file_path, @api_key)
43
-
44
- assert virustotal_upload.report.is_a?(Hash)
45
- end
46
- end
47
-
48
- def test_upload_id
49
- VCR.use_cassette('file_upload') do
50
- virustotal_upload = VirustotalAPI::File.upload(@file_path, @api_key)
46
+ vt_file_upload = VirustotalAPI::File.upload(@file_path, @api_key)
51
47
 
52
- assert virustotal_upload.id.is_a?(String)
48
+ assert vt_file_upload.exists?
49
+ assert vt_file_upload.report.is_a?(Hash)
50
+ assert vt_file_upload.id.is_a?(String)
53
51
  end
54
52
  end
55
53
 
56
54
  def test_analyse
57
55
  VCR.use_cassette('file_analyse') do
58
- virustotal_analyse = VirustotalAPI::File.analyse(@sha256, @api_key)
59
-
60
- assert virustotal_analyse.report.is_a?(Hash)
61
- end
62
- end
63
-
64
- def test_analyse_id
65
- VCR.use_cassette('file_analyse') do
66
- virustotal_analyse = VirustotalAPI::File.analyse(@sha256, @api_key)
56
+ vt_file_analyse = VirustotalAPI::File.analyse(@sha256, @api_key)
67
57
 
68
- assert virustotal_analyse.id.is_a?(String)
58
+ assert vt_file_analyse.exists?
59
+ assert vt_file_analyse.report.is_a?(Hash)
60
+ assert vt_file_analyse.id.is_a?(String)
69
61
  end
70
62
  end
71
63
  end
@@ -17,15 +17,10 @@ class VirustotalAPIGroupReportTest < Minitest::Test
17
17
  vtgroup_report = VirustotalAPI::Group.find(@group_id, @api_key)
18
18
 
19
19
  # Make sure that the JSON was parsed
20
+ assert vtgroup_report.exists?
20
21
  assert vtgroup_report.is_a?(VirustotalAPI::Group)
21
22
  assert vtgroup_report.report.is_a?(Hash)
22
- end
23
- end
24
-
25
- def test_find
26
- VCR.use_cassette('group_find') do
27
- vtgroup_report = VirustotalAPI::Group.find(@group_id, @api_key)
28
-
23
+ assert vtgroup_report.id.is_a?(String)
29
24
  assert vtgroup_report.report_url.is_a?(String)
30
25
  end
31
26
  end
@@ -19,6 +19,8 @@ class VirustotalAPIIPReportTest < Minitest::Test
19
19
  # Make sure that the JSON was parsed
20
20
  assert vtip_report.is_a?(VirustotalAPI::IP)
21
21
  assert vtip_report.report.is_a?(Hash)
22
+ assert vtip_report.id.is_a?(String)
23
+ assert vtip_report.report_url.is_a?(String)
22
24
  end
23
25
  end
24
26
  end
@@ -18,24 +18,11 @@ class VirustotalAPIURLReportTest < Minitest::Test
18
18
  vturl_report = VirustotalAPI::URL.find(@url, @api_key)
19
19
 
20
20
  # Make sure that the JSON was parsed
21
+ assert vturl_report.exists?
21
22
  assert vturl_report.is_a?(VirustotalAPI::URL)
22
23
  assert vturl_report.report.is_a?(Hash)
23
- end
24
- end
25
-
26
- def test_find
27
- VCR.use_cassette('url_find') do
28
- vturl_report = VirustotalAPI::URL.find(@url, @api_key)
29
-
30
- assert vturl_report.report_url.is_a?(String)
31
- end
32
- end
33
-
34
- def test_scan_url
35
- VCR.use_cassette('url_find') do
36
- vturl_report = VirustotalAPI::URL.find(@url, @api_key)
37
-
38
24
  assert vturl_report.id.is_a?(String)
25
+ assert vturl_report.report_url.is_a?(String)
39
26
  end
40
27
  end
41
28
 
@@ -43,23 +30,18 @@ class VirustotalAPIURLReportTest < Minitest::Test
43
30
  VCR.use_cassette('unscanned_url_find') do
44
31
  vturl_report = VirustotalAPI::URL.find(@unscanned_url, @api_key)
45
32
 
33
+ assert !vturl_report.exists?
46
34
  assert_empty vturl_report.report
47
35
  end
48
36
  end
49
37
 
50
38
  def test_analyse
51
39
  VCR.use_cassette('url_analyse') do
52
- vturl_scan = VirustotalAPI::URL.analyse(@url, @api_key)
53
-
54
- assert vturl_scan.report.is_a?(Hash)
55
- end
56
- end
57
-
58
- def test_analyse_id
59
- VCR.use_cassette('url_analyse') do
60
- vturl_scan = VirustotalAPI::URL.analyse(@url, @api_key)
40
+ vturl_analyse = VirustotalAPI::URL.analyse(@url, @api_key)
61
41
 
62
- assert vturl_scan.id.is_a?(String)
42
+ assert vturl_analyse.exists?
43
+ assert vturl_analyse.report.is_a?(Hash)
44
+ assert vturl_analyse.id.is_a?(String)
63
45
  end
64
46
  end
65
47
  end
@@ -16,15 +16,10 @@ class VirustotalAPIUserReportTest < Minitest::Test
16
16
  vtuser_report = VirustotalAPI::User.find(@api_key, @api_key)
17
17
 
18
18
  # Make sure that the JSON was parsed
19
+ assert vtuser_report.exists?
19
20
  assert vtuser_report.is_a?(VirustotalAPI::User)
20
21
  assert vtuser_report.report.is_a?(Hash)
21
- end
22
- end
23
-
24
- def test_find
25
- VCR.use_cassette('user_find') do
26
- vtuser_report = VirustotalAPI::User.find(@api_key, @api_key)
27
-
22
+ assert vtuser_report.id.is_a?(String)
28
23
  assert vtuser_report.report_url.is_a?(String)
29
24
  end
30
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: virustotal_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - pwelch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-08 00:00:00.000000000 Z
11
+ date: 2020-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json