script_core 0.0.3 → 0.0.4

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: acc4a16cf06d2962a37e47bea35c60f12f5f633322de6870e325b4f960788699
4
- data.tar.gz: 7bbfe4e82affb630ed5e1689b04dc03c80075488eef9e47cb5036ee3ab99083c
3
+ metadata.gz: bfb29eda17a289a639eaeda3bd447732d774ea5c9a6f7ec5e3d71406891d3376
4
+ data.tar.gz: 4245f1728f35920db4d370805ad38951f9ae9695807a7a090ba799207f8a6acf
5
5
  SHA512:
6
- metadata.gz: d52a8137ca745d1a7c8f7a8791df4b26f5ba8ba338a7562ab308c7bef576e799d81d89c22ad00ff1ea006daa1adc56f0a359b90c0bf50915fd34c6d31dc9bb3e
7
- data.tar.gz: c046025045f9b7d4eabc86828dfdaea75afefe19bf073446c1f2b356fad54974691d9d8313162a6b521e268ea295f2ab6449998ba599bd3a7a2a258d087eb0f9
6
+ metadata.gz: c9d7e1a4acfe78e4a05371e44955bc6032b4844384eacac24a188bd3f9a2737be592f0ee39845d16bec1ee18244a63d5627492275593a2953844f57f6b9fbe7f
7
+ data.tar.gz: 463bfd37532feea17dbad1c91e3cd5c35aecb93162c1fe40209198f7fdd4d43b4fe5f899d24a37f79fd39ff75afba5969a3eb90c04ee247b60d2b7671cba2564
@@ -20,7 +20,7 @@ module ScriptCore
20
20
  @instructions = File.exist?(preload_instructions_path) ? File.binread(preload_instructions_path) : nil
21
21
  end
22
22
 
23
- def eval(sources, input: nil, instruction_quota_start: nil)
23
+ def eval(sources, input: nil, instruction_quota_start: nil, environment_variables: {})
24
24
  @executable.run(
25
25
  input: input || {},
26
26
  sources: sources,
@@ -28,7 +28,8 @@ module ScriptCore
28
28
  timeout: @timeout,
29
29
  instruction_quota: @instruction_quota,
30
30
  instruction_quota_start: instruction_quota_start || @instruction_quota_start,
31
- memory_quota: @memory_quota
31
+ memory_quota: @memory_quota,
32
+ environment_variables: environment_variables
32
33
  )
33
34
  end
34
35
  end
@@ -12,7 +12,9 @@ module ScriptCore
12
12
  @executable_path = executable_path.to_s
13
13
  end
14
14
 
15
- def run(input:, sources:, instructions: nil, timeout: 1, instruction_quota: 100_000, instruction_quota_start: 0, memory_quota: 8 << 20)
15
+ def run(input:, sources:, instructions: nil,
16
+ timeout: 1, instruction_quota: 100_000, instruction_quota_start: 0, memory_quota: 8 << 20,
17
+ environment_variables: {})
16
18
  packer = ScriptCore::Protocol.packer_factory.packer
17
19
 
18
20
  payload = {input: input, sources: sources}
@@ -28,7 +30,8 @@ module ScriptCore
28
30
  spawner,
29
31
  instruction_quota,
30
32
  instruction_quota_start,
31
- memory_quota
33
+ memory_quota,
34
+ environment_variables
32
35
  )
33
36
  runner = ScriptCore::Runner.new(
34
37
  timeout: timeout,
@@ -2,14 +2,15 @@
2
2
 
3
3
  module ScriptCore
4
4
  class ServiceProcess
5
- attr_reader(:path, :spawner, :instruction_quota, :instruction_quota_start, :memory_quota)
5
+ attr_reader(:path, :spawner, :instruction_quota, :instruction_quota_start, :memory_quota, :environment_variables)
6
6
 
7
- def initialize(path, spawner, instruction_quota, instruction_quota_start, memory_quota)
7
+ def initialize(path, spawner, instruction_quota, instruction_quota_start, memory_quota, environment_variables = {})
8
8
  @path = path
9
9
  @spawner = spawner
10
10
  @instruction_quota = instruction_quota
11
11
  @instruction_quota_start = instruction_quota_start
12
12
  @memory_quota = memory_quota
13
+ @environment_variables = environment_variables
13
14
  end
14
15
 
15
16
  def open
@@ -17,6 +18,7 @@ module ScriptCore
17
18
  out_reader, out_writer = IO.pipe
18
19
 
19
20
  pid = spawner.spawn(
21
+ environment_variables,
20
22
  path,
21
23
  "-i", instruction_quota.to_s,
22
24
  "-C", instruction_quota_start.to_s,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ScriptCore
4
- VERSION = "0.0.3"
4
+ VERSION = "0.0.4"
5
5
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  RSpec.describe(ScriptCore::ServiceProcess) do
4
4
  let(:pid) { rand(1 << 16) }
5
+ let(:environment_variables) { {"TZ" => "US/Pacific"} }
5
6
  let(:service_path) { "bin/my-subprocess" }
6
7
  let(:pipe_pairs) { [] }
7
8
 
@@ -13,13 +14,14 @@ RSpec.describe(ScriptCore::ServiceProcess) do
13
14
  end
14
15
 
15
16
  let(:service_process) do
16
- ScriptCore::ServiceProcess.new(service_path, spawner, 100_000, 2, 4 << 20)
17
+ ScriptCore::ServiceProcess.new(service_path, spawner, 100_000, 2, 4 << 20, environment_variables)
17
18
  end
18
19
 
19
20
  it "creates a channel to communicate with the subprocess" do
20
21
  in_reader = nil
21
22
  out_writer = nil
22
- expect(spawner).to receive(:spawn) do |path, **options|
23
+ expect(spawner).to receive(:spawn) do |env, path, **options|
24
+ expect(env).to eq(environment_variables)
23
25
  expect(path).to eq(service_path)
24
26
  in_reader = options[:in].dup
25
27
  expect(in_reader).to be_an(IO)
@@ -41,7 +43,7 @@ RSpec.describe(ScriptCore::ServiceProcess) do
41
43
 
42
44
  it "open passes arguments to process" do
43
45
  expect(spawner)
44
- .to receive(:spawn).once.with(instance_of(String), "-i", 100_000.to_s, "-C", 2.to_s, "-m", (4 << 20).to_s, instance_of(Hash))
46
+ .to receive(:spawn).once.with(instance_of(Hash), instance_of(String), "-i", 100_000.to_s, "-C", 2.to_s, "-m", (4 << 20).to_s, instance_of(Hash))
45
47
  service_process.open do |c|
46
48
  end
47
49
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: script_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - jasl
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-14 00:00:00.000000000 Z
11
+ date: 2018-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: msgpack
@@ -3597,7 +3597,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
3597
3597
  version: '0'
3598
3598
  requirements: []
3599
3599
  rubyforge_project:
3600
- rubygems_version: 2.7.6
3600
+ rubygems_version: 2.7.4
3601
3601
  signing_key:
3602
3602
  specification_version: 4
3603
3603
  summary: A script engine powered by a mruby sandboxie, It's forked by Shopify's ESS.