File: no_unsafe_spec.rb

package info (click to toggle)
ruby-concurrent 1.1.6%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 30,284 kB
  • sloc: ruby: 30,875; java: 6,117; ansic: 288; makefile: 9; sh: 6
file content (27 lines) | stat: -rw-r--r-- 881 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
if defined?(JRUBY_VERSION) && ENV['TEST_NO_UNSAFE']
  # to be used like this: rake test TEST_NO_UNSAFE=true
  load 'test/package.jar'
  java_import 'thread_safe.SecurityManager'
  manager = SecurityManager.new

  # Prevent accessing internal classes
  manager.deny(java.lang.RuntimePermission.new('accessClassInPackage.sun.misc'))
  java.lang.System.setSecurityManager(manager)

  module Concurrent
    describe 'no_unsafe' do
      it 'security_manager_is_used' do
        begin
          java_import 'sun.misc.Unsafe'
          fail
        rescue SecurityError
        end
      end

      it 'no_unsafe_version_of_chmv8_is_used' do
        require 'concurrent/thread_safe/jruby_cache_backend' # make sure the jar has been loaded
        expect(!Java::OrgJrubyExtThread_safe::JRubyMapBackendLibrary::JRubyMapBackend::CAN_USE_UNSAFE_CHM).to be_truthy
      end
    end
  end
end