Skip to content

Commit

Permalink
Merge pull request #952 from ninoseki/apply-rubocop
Browse files Browse the repository at this point in the history
refactor: apply rubocop
  • Loading branch information
ninoseki authored Dec 31, 2023
2 parents 30ee609 + 88e9d52 commit f5d57b9
Show file tree
Hide file tree
Showing 31 changed files with 59 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ RSpec/MultipleMemoizedHelpers:
RSpec/ExampleLength:
Max: 20
require:
- rubocop-factory_bot
- rubocop-rake
- rubocop-rspec
- rubocop-yard
1 change: 1 addition & 0 deletions lib/mihari/clients/the_hive.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module Clients
#
class TheHive < Base
attr_reader :api_version

#
# @param [String] base_url
# @param [String, nil] api_key
Expand Down
2 changes: 2 additions & 0 deletions lib/mihari/commands/sidekiq.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Mihari
module Commands
#
Expand Down
2 changes: 1 addition & 1 deletion lib/mihari/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def on_error(_request, error)
#
class Factory
class << self
USER_AGENT = "mihari/#{Mihari::VERSION}"
USER_AGENT = "mihari/#{Mihari::VERSION}".freeze
#
# @param [Integer, nil] timeout
# @param [Hash] headers
Expand Down
2 changes: 1 addition & 1 deletion lib/mihari/models/artifact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def set_data_type
end

def set_rule_id
@rule_id ||= nil
@set_rule_id ||= nil
end

def mmdb
Expand Down
2 changes: 2 additions & 0 deletions lib/mihari/models/concerns/searchable.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Mihari
module Models
module Concerns
Expand Down
2 changes: 1 addition & 1 deletion lib/mihari/rule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ def serial_analyzers

# @return [Array<Dry::Monads::Result::Success<Array<Mihari::Models::Artifact>>, Dry::Monads::Result::Failure>]
def analyzer_results
parallel_results = Parallel.map(parallel_analyzers) { |analyzer| analyzer.result }
parallel_results = Parallel.map(parallel_analyzers, &:result)
serial_results = serial_analyzers.map(&:result)
parallel_results + serial_results
end
Expand Down
2 changes: 2 additions & 0 deletions lib/mihari/services/creators.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Mihari
module Services
#
Expand Down
2 changes: 2 additions & 0 deletions lib/mihari/services/destroyers.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Mihari
module Services
class AlertDestroyer < Service
Expand Down
2 changes: 2 additions & 0 deletions lib/mihari/services/enrichers.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Mihari
module Services
class ArtifactEnricher < Service
Expand Down
2 changes: 2 additions & 0 deletions lib/mihari/services/feed.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "csv"

require "jr/cli/core_ext"
Expand Down
2 changes: 2 additions & 0 deletions lib/mihari/services/getters.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Mihari
module Services
class ArtifactGetter < Service
Expand Down
2 changes: 2 additions & 0 deletions lib/mihari/services/initializers.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Mihari
module Services
class RuleInitializer < Service
Expand Down
2 changes: 2 additions & 0 deletions lib/mihari/services/searchers.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Mihari
module Services
class ResultValue
Expand Down
2 changes: 2 additions & 0 deletions lib/mihari/sidekiq/application.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "sidekiq"

require "mihari/sidekiq/jobs"
Expand Down
2 changes: 2 additions & 0 deletions lib/mihari/sidekiq/jobs.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "sidekiq"

module Mihari
Expand Down
2 changes: 1 addition & 1 deletion lib/mihari/structs/google_public_dns.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Structs
module GooglePublicDNS
INT_TYPE_TO_TYPE =
{ 1 => :A, 38 => :A6, 28 => :AAAA, 18 => :AFSDB, 255 => :ANY, 42 => :APL, 34 => :ATMA, 252 => :AXFR, 37 => :CERT,
5 => :CNAME, 49 => :DHCID, 32_769 => :DLV, 39 => :DNAME, 48 => :DNSKEY, 43 => :DS, 31 => :EID, 102 => :GID, 27 => :GPOS, 13 => :HINFO, 45 => :IPSECKEY, 20 => :ISDN, 251 => :IXFR, 25 => :KEY, 36 => :KX, 29 => :LOC, 254 => :MAILA, 253 => :MAILB, 7 => :MB, 3 => :MD, 4 => :MF, 8 => :MG, 14 => :MINFO, 9 => :MR, 15 => :MX, 35 => :NAPTR, 32 => :NIMLOC, 2 => :NS, 22 => :NSAP, 23 => :NSAP_PTR, 47 => :NSEC, 50 => :NSEC3, 51 => :NSEC3PARAMS, 10 => :NULL, 30 => :NXT, 41 => :OPT, 12 => :PTR, 26 => :PX, 17 => :RP, 46 => :RRSIG, 21 => :RT, 24 => :SIG, 40 => :SINK, 6 => :SOA, 33 => :SRV, 44 => :SSHFP, 250 => :TSIG, 16 => :TXT, 101 => :UID, 100 => :UINFO, 103 => :UNSPEC, 11 => :WKS, 19 => :X25 }
5 => :CNAME, 49 => :DHCID, 32_769 => :DLV, 39 => :DNAME, 48 => :DNSKEY, 43 => :DS, 31 => :EID, 102 => :GID, 27 => :GPOS, 13 => :HINFO, 45 => :IPSECKEY, 20 => :ISDN, 251 => :IXFR, 25 => :KEY, 36 => :KX, 29 => :LOC, 254 => :MAILA, 253 => :MAILB, 7 => :MB, 3 => :MD, 4 => :MF, 8 => :MG, 14 => :MINFO, 9 => :MR, 15 => :MX, 35 => :NAPTR, 32 => :NIMLOC, 2 => :NS, 22 => :NSAP, 23 => :NSAP_PTR, 47 => :NSEC, 50 => :NSEC3, 51 => :NSEC3PARAMS, 10 => :NULL, 30 => :NXT, 41 => :OPT, 12 => :PTR, 26 => :PX, 17 => :RP, 46 => :RRSIG, 21 => :RT, 24 => :SIG, 40 => :SINK, 6 => :SOA, 33 => :SRV, 44 => :SSHFP, 250 => :TSIG, 16 => :TXT, 101 => :UID, 100 => :UINFO, 103 => :UNSPEC, 11 => :WKS, 19 => :X25 }.freeze

class Answer < Dry::Struct
# @!attribute [r] name
Expand Down
2 changes: 2 additions & 0 deletions mihari.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "rspec-parameterized", "~> 1.0"
spec.add_development_dependency "rubocop-rspec", "~> 2.25"
spec.add_development_dependency "rubocop-yard", "~> 0.9"
spec.add_development_dependency "rubocop-rake", "~> 0.6"
spec.add_development_dependency "rubocop-factory_bot", "~> 2.24"
spec.add_development_dependency "simplecov-lcov", "~> 0.8"
spec.add_development_dependency "standard", "~> 1.33"
spec.add_development_dependency "test-prof", "~> 1.3"
Expand Down
2 changes: 2 additions & 0 deletions spec/cli/alert_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "tempfile"

RSpec.describe Mihari::CLI::Alert do
Expand Down
2 changes: 2 additions & 0 deletions spec/cli/config_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

RSpec.describe Mihari::CLI::Config do
let!(:key) { Mihari.config.keys.first }

Expand Down
2 changes: 2 additions & 0 deletions spec/enrichers/google_public_dns_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

RSpec.describe Mihari::Enrichers::GooglePublicDNS, :vcr do
describe ".query_by_type" do
subject(:enricher) { described_class.new }
Expand Down
2 changes: 2 additions & 0 deletions spec/factories/alerts.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

FactoryBot.define do
factory :alert, class: "Mihari::Models::Alert" do
rule
Expand Down
2 changes: 2 additions & 0 deletions spec/factories/artifacts.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

FactoryBot.define do
factory :autonomous_system, class: "Mihari::Models::AutonomousSystem" do
artifact
Expand Down
2 changes: 2 additions & 0 deletions spec/factories/rules.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

FactoryBot.define do
factory :rule, class: "Mihari::Models::Rule" do
id { Faker::Internet.unique.uuid }
Expand Down
2 changes: 2 additions & 0 deletions spec/factories/tags.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

FactoryBot.define do
factory :tag, class: "Mihari::Models::Tag" do
name { Faker::Internet.unique.slug }
Expand Down
2 changes: 2 additions & 0 deletions spec/services/feed_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

RSpec.describe Mihari::Services::FeedParser do
let!(:data) do
{
Expand Down
2 changes: 2 additions & 0 deletions spec/services/initializers_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

RSpec.describe Mihari::Services::RuleInitializer do
describe "#call" do
let!(:files) { Dry::Files.new(memory: true) }
Expand Down
2 changes: 2 additions & 0 deletions spec/sidekiq/artifact_enrich_job_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

RSpec.describe Mihari::Jobs::ArtifactEnrichJob do
include_context "with faked Sidekiq configuration"

Expand Down
2 changes: 2 additions & 0 deletions spec/sidekiq/search_job_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

RSpec.describe Mihari::Jobs::SearchJob do
include_context "with faked Sidekiq configuration"

Expand Down
6 changes: 4 additions & 2 deletions spec/support/httpbin.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "forwardable"

class HTTPBin
Expand Down Expand Up @@ -32,8 +34,8 @@ def call

def headers
http_headers = req.env.select { |k, _v| k.start_with?("HTTP_") }
http_headers.each_with_object({}) do |(k, v), a|
a[k.sub(/^HTTP_/, "").downcase.gsub(/(^|_)\w/) { |word| word.upcase }.tr("_", "-")] = v
http_headers.transform_keys do |k|
k.sub(/^HTTP_/, "").downcase.gsub(/(^|_)\w/, &:upcase).tr("_", "-")
end
end

Expand Down
2 changes: 2 additions & 0 deletions spec/support/shared_contexts/httpbin_context.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "capybara"

require_relative "../httpbin"
Expand Down

0 comments on commit f5d57b9

Please sign in to comment.