Module: Straycall::Minitest

Defined in:
lib/straycall/minitest.rb

Defined Under Namespace

Modules: Hooks

Class Method Summary collapse

Class Method Details

.configure_hooksObject



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/straycall/minitest.rb', line 39

def configure_hooks
  ::Minitest::Test.prepend(Hooks)
  ::Minitest.after_run do
    begin
      Straycall::Minitest.ensure_supervisor!
      raise Error, "syscall violations were detected; see the straycall report" if Target.violation?
    ensure
      Target.stop
    end
  end
end

.ensure_supervisor!Object

Raises:



51
52
53
54
55
# File 'lib/straycall/minitest.rb', line 51

def ensure_supervisor!
  return unless Seccomp::Notify.supervisor_alive? == false

  raise Error, "straycall supervisor stopped; refusing to continue with an unmonitored suite"
end

.installObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/straycall/minitest.rb', line 19

def install
  if RUBY_PLATFORM.include?("linux") && RUBY_ENGINE == "ruby"
    require "seccomp/notify"
    require_relative "target"
    return configure_hooks if Seccomp::Notify.supervisor_alive?
  end
  unless Straycall.available?
    Straycall.warn_unavailable!
    return
  end

  require "seccomp/notify"
  require_relative "in_process"
  require_relative "target"
  supervisor_socket, target_socket = UNIXSocket.pair
  InProcess.install(Straycall.config, report_socket: supervisor_socket, inherited_report_socket: target_socket)
  Target.start(target_socket)
  configure_hooks
end