eval_in 0.1.0 → 0.1.1

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
  SHA1:
3
- metadata.gz: 233dd4fa01b53aaaee164ea7805c97c0e3b334c8
4
- data.tar.gz: b3e36f9036a0b3c36ab51bfa862bf0a811f851c9
3
+ metadata.gz: e5a172a314e520fe820972f9dbf6ba76c16a49ab
4
+ data.tar.gz: a7a6a571f986ca1296dd389f7476bfce7ac92bee
5
5
  SHA512:
6
- metadata.gz: 95b82288f75842f9927fbbd67515f704b60cb355d967f8a773277ccd212e503cc011678544bc937648a17653dfc2a14fbb107fc93305950f84608b48d8d086cd
7
- data.tar.gz: f20e17beab81a2e5b9de1d392b3765cea6333edc09944584d7d7eb08aedb161f6359c13eb72778b3087a4c7081336acf079a634cbd94426f60cbd02edcf6d5df
6
+ metadata.gz: e2bbd5233868060a9d66f85e7ce75f8879276c8527d2d74587736eff267e78d5e31a5ce7a4c457076a54a5dfce1156b8c22a8cb5fddbdd596d1a44d1ea2763be
7
+ data.tar.gz: 3c688f0b063b24c5f938ae0ba06c4cfd7f7fda897be7f1842782e9757c2b0b7597ec536aa49a88e484061d3af8aa5cf1bf53c69802191aa4bf645ad887eb9120
data/.travis.yml ADDED
@@ -0,0 +1,15 @@
1
+ language: ruby
2
+ script: bundle exec rspec
3
+ rvm:
4
+ - 1.9.3
5
+ - 2.0.0
6
+ - 2.1.2
7
+ - ruby-head
8
+ - rbx-2
9
+ - jruby
10
+ - jruby-head
11
+
12
+ matrix:
13
+ allow_failures:
14
+ - rvm: ruby-head
15
+ - rvm: jruby-head
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- eval_in (0.1.0)
4
+ eval_in (0.1.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -28,6 +28,7 @@ GEM
28
28
  crack (>= 0.3.2)
29
29
 
30
30
  PLATFORMS
31
+ java
31
32
  ruby
32
33
 
33
34
  DEPENDENCIES
data/Readme.md CHANGED
@@ -1,10 +1,31 @@
1
+ [![Build Status](https://secure.travis-ci.org/JoshCheek/seeing_eval_in.png?branch=master)](http://travis-ci.org/JoshCheek/eval_in)
2
+
1
3
  EvalIn
2
4
  ======
3
5
 
4
6
  Safely evaluates code (Ruby and others) by sending it through https://eval.in
5
7
 
6
- Languages and Versions
7
- ----------------------
8
+ Example
9
+ -------
10
+
11
+ It's this simple:
12
+
13
+ ```ruby
14
+ require 'eval_in'
15
+
16
+ result = EvalIn.call 'puts "hello, #{gets}"', stdin: 'world', language: "ruby/mri-2.1"
17
+
18
+ result.output # => "hello, world\n"
19
+ result.exitstatus # => 0
20
+ result.language # => "ruby/mri-2.1"
21
+ result.language_friendly # => "Ruby — MRI 2.1"
22
+ result.code # => "puts \"hello, \#{gets}\""
23
+ result.status # => "OK (0.052 sec real, 0.059 sec wall, 9 MB, 21 syscalls)"
24
+ ```
25
+
26
+
27
+ What languages can this run?
28
+ ----------------------------
8
29
 
9
30
  <table>
10
31
  <tr>
@@ -130,39 +151,6 @@ Languages and Versions
130
151
  </tr>
131
152
  </table>
132
153
 
133
-
134
- Example
135
- -------
136
-
137
- It's this simple:
138
-
139
- ```ruby
140
- require 'eval_in'
141
-
142
- result = EvalIn.call 'puts "hello, #{gets}"', stdin: 'world', language: "ruby/mri-2.1"
143
-
144
- result.exitstatus # => 0
145
- result.language # => "ruby/mri-2.1"
146
- result.language_friendly # => "Ruby — MRI 2.1"
147
- result.code # => "puts \"hello, \#{gets}\""
148
- result.output # => "hello, world\n"
149
- result.status # => "OK (0.052 sec real, 0.059 sec wall, 9 MB, 21 syscalls)"
150
- ```
151
-
152
- Essentially a wrapper around:
153
-
154
- ```sh
155
- curl https://eval.in/ \
156
- -i \
157
- -d utf8=√ \
158
- -d code='print "hello #{gets}"' \
159
- -d execute=on \
160
- -d lang=ruby/mri-1.9.3 \
161
- -d input=world \
162
- | ruby -ane 'puts "#{$F[1]}.json" if /^Loc/' \
163
- | xargs curl
164
- ```
165
-
166
154
  Attribution
167
155
  -----------
168
156
 
@@ -1,3 +1,3 @@
1
1
  module EvalIn
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
data/lib/eval_in.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require 'uri'
2
4
  require 'json'
3
5
  require 'net/http'
@@ -8,6 +10,7 @@ module EvalIn
8
10
  RequestError = Class.new EvalInError
9
11
  ResultNotFound = Class.new EvalInError
10
12
 
13
+ # curl https://eval.in | ruby -rnokogiri -e 'puts Nokogiri::HTML($stdin.read).css("option").map { |o| o["value"] }'
11
14
  KNOWN_LANGUAGES = %w[
12
15
  c/gcc-4.4.3
13
16
  c/gcc-4.9.1
@@ -59,7 +62,20 @@ module EvalIn
59
62
  uri = URI(options.fetch(:url, "https://eval.in/"))
60
63
  input = options.fetch(:stdin, "")
61
64
  language = options.fetch(:language)
62
- result = Net::HTTP.post_form(uri, "utf8" => "√", "code" => code, "execute" => "on", "lang" => language, "input" => input)
65
+ path = uri.path
66
+ path = '/' if path.empty?
67
+
68
+ # stole this out of implementation for post_form https://github.com/ruby/ruby/blob/trunk/lib/net/http.rb#L503
69
+ request = Net::HTTP::Post.new(path)
70
+ request.form_data = {"utf8" => "√", "code" => code, "execute" => "on", "lang" => language, "input" => input}
71
+ request['User-Agent'] = 'http://rubygems.org/gems/eval_in'
72
+ req.basic_auth uri.user, uri.password if uri.user
73
+ net = Net::HTTP.new(uri.hostname, uri.port)
74
+ # net.set_debug_output $stdout
75
+ result = Net::HTTP.start(uri.hostname, uri.port, use_ssl: (uri.scheme == 'https')) { |http|
76
+ http.request(request)
77
+ }
78
+
63
79
  if result.code == '302'
64
80
  location = result['location']
65
81
  location += '.json' unless location.end_with? '.json'
@@ -84,6 +100,7 @@ module EvalIn
84
100
  status = response_json['status']
85
101
  exitstatus = if !status then nil # let it choose default
86
102
  elsif status =~ /status (\d+)$/ then $1.to_i
103
+ elsif status =~ /^Forbidden/ then 1
87
104
  else 0
88
105
  end
89
106
 
data/spec/eval_in_spec.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require 'eval_in'
2
4
  require 'webmock'
3
5
  WebMock.disable_net_connect!
@@ -107,7 +109,7 @@ RSpec.describe 'post_code' do
107
109
  # \r
108
110
  def stub_eval_in(data=expected_data)
109
111
  stub_request(:post, url)
110
- .with(:body => data)
112
+ .with(body: data)
111
113
  .to_return(status: 302, headers: {'Location' => result_location})
112
114
  end
113
115
 
@@ -123,12 +125,26 @@ RSpec.describe 'post_code' do
123
125
  EvalIn.post_code code, stdin: stdin, language: language
124
126
  end
125
127
 
128
+ it 'sets the user agent to its gem homepage' do
129
+ stub_request(:post, url)
130
+ .with(headers: {'User-Agent' => 'http://rubygems.org/gems/eval_in'})
131
+ .to_return(status: 302, headers: {'Location' => result_location})
132
+ EvalIn.post_code code, language: language
133
+ end
134
+
126
135
  it 'returns the redirect location jsonified' do
127
136
  stub_eval_in expected_data
128
137
  result = EvalIn.post_code code, stdin: stdin, language: language
129
138
  expect(result).to eq "#{result_location}.json"
130
139
  end
131
140
 
141
+ it "Doesn't jsonify the redirect location if it already has a json suffix" do
142
+ result_location << '.json'
143
+ stub_eval_in expected_data
144
+ result = EvalIn.post_code code, stdin: stdin, language: language
145
+ expect(result).to eq result_location
146
+ end
147
+
132
148
  it 'sets input to empty string if not provided' do
133
149
  stub_eval_in expected_data.merge('input' => '')
134
150
  EvalIn.post_code code, language: language
@@ -206,9 +222,10 @@ RSpec.describe 'build_result' do
206
222
  status: status
207
223
  end
208
224
 
209
- # exit: https://eval.in/182586.json
210
- # raise: https://eval.in/182587.json
211
- # in C: https://eval.in/182588.json
225
+ # exit: https://eval.in/182586.json
226
+ # raise: https://eval.in/182587.json
227
+ # in C: https://eval.in/182588.json
228
+ # Forbidden: https://eval.in/182599.json
212
229
  it 'sets the exit status to that of the program when it is available' do
213
230
  result = EvalIn.build_result response_json.merge('status' => "Exited with error status 123")
214
231
  expect(result.exitstatus).to eq 123
@@ -223,4 +240,9 @@ RSpec.describe 'build_result' do
223
240
  result = EvalIn.build_result response_json.merge('status' => 'OK (0.012 sec real, 0.013 sec wall, 7 MB, 22 syscalls)')
224
241
  expect(result.exitstatus).to eq 0
225
242
  end
243
+
244
+ it 'sets the exit status to 1 when there is an error' do
245
+ result = EvalIn.build_result response_json.merge('status' => 'Forbidden access to file `/usr/local/bin/gem')
246
+ expect(result.exitstatus).to eq 1
247
+ end
226
248
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eval_in
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Cheek
@@ -11,28 +11,28 @@ cert_chain: []
11
11
  date: 2014-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rspec
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
16
  - - "~>"
18
17
  - !ruby/object:Gem::Version
19
18
  version: '3.0'
20
- type: :development
21
19
  prerelease: false
20
+ name: rspec
21
+ type: :development
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: webmock
29
28
  requirement: !ruby/object:Gem::Requirement
30
29
  requirements:
31
30
  - - "~>"
32
31
  - !ruby/object:Gem::Version
33
32
  version: '1.18'
34
- type: :development
35
33
  prerelease: false
34
+ name: webmock
35
+ type: :development
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
@@ -75,6 +75,7 @@ extensions: []
75
75
  extra_rdoc_files: []
76
76
  files:
77
77
  - ".gitignore"
78
+ - ".travis.yml"
78
79
  - Gemfile
79
80
  - Gemfile.lock
80
81
  - Readme.md