Module: Aikido::Zen::Sinks::PG::Helpers

Defined in:
lib/aikido/zen/sinks/pg.rb

Class Method Summary collapse

Class Method Details

.safe(&block) ⇒ Object

For some reason, the ActiveRecord pg adaptor does not wrap exceptions in ActiveRecord::StatementInvalid, leading to inconsistent handling. This guarantees that Aikido::Zen::SQLInjectionErrors are wrapped in an ActiveRecord::StatementInvalid.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/aikido/zen/sinks/pg.rb', line 13

def self.safe(&block)
  # Code coverage is disabled here because this ActiveRecord behavior is
  # exercised in end-to-end tests, which are not covered by SimpleCov.
  # :nocov:
  if !defined?(ActiveRecord::StatementInvalid)
    Sinks::DSL.safe(&block)
  else
    begin
      Sinks::DSL.safe(&block)
    rescue Aikido::Zen::SQLInjectionError => err
      raise ActiveRecord::StatementInvalid, cause: err
    end
  end
  # :nocov:
end

.scan(query, operation) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/aikido/zen/sinks/pg.rb', line 29

def self.scan(query, operation)
  SINK.scan(
    query: query,
    dialect: :postgresql,
    operation: operation
  )
end