rack_check 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/rack-check +4 -0
- data/lib/rack_check/helpers.rb +18 -0
- data/lib/rack_check/server_manager.rb +62 -0
- data/lib/rack_check/spec/env.rb +267 -0
- data/lib/rack_check/spec/rackup.rb +18 -0
- data/lib/rack_check/spec.rb +29 -0
- data/lib/rack_check/version.rb +3 -0
- data/lib/rack_check.rb +14 -0
- data/rack_check.gemspec +28 -0
- metadata +134 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 48f2ac2cc6b95a389c7de1172c08a8a95b8bd7a1
|
4
|
+
data.tar.gz: 878e042ca38b7437b9909a2e3d88cc8081a57fd2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8851e0bdf1022371b30818f4f0247356c0ec1b36a6dd2f179eadc372e8b715a3e1c6b8307dcb986ffe10313dc62c70a74196b23fa8f7db44d27b1a6dc8ddac9f
|
7
|
+
data.tar.gz: 4885c0fc6b66dc9808e2deef17b7e9390eaa97f0998c30787b906310b1370fddd28a18f6ae90a0e97ecac80cccddc8e60cbd9177253ed122c91c140c71a62233
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at TODO: Write your email address. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 TODO: Write your name
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# RackCheck
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rack_check`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'rack_check'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install rack_check
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rack_check. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "rack_check"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/exe/rack-check
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
module RackCheck::Helpers
|
2
|
+
|
3
|
+
$environments_count = 0
|
4
|
+
|
5
|
+
def with_environment(ru_file)
|
6
|
+
dir_name = "/tmp/rack-check/environment-#{$environments_count += 1}"
|
7
|
+
previous_wd = FileUtils.getwd
|
8
|
+
|
9
|
+
FileUtils.mkdir_p dir_name
|
10
|
+
File.write(dir_name + '/config.ru', ru_file)
|
11
|
+
|
12
|
+
yield(dir_name)
|
13
|
+
|
14
|
+
ensure
|
15
|
+
FileUtils.rm_rf dir_name
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module RackCheck
|
2
|
+
|
3
|
+
class ServerManager
|
4
|
+
include RackCheck::Helpers
|
5
|
+
|
6
|
+
attr_reader :context, :ru_file
|
7
|
+
|
8
|
+
def initialize(context, ru_file)
|
9
|
+
@ru_file = ru_file
|
10
|
+
@stop_var = Concurrent::MVar.new
|
11
|
+
@context = context
|
12
|
+
end
|
13
|
+
|
14
|
+
def run
|
15
|
+
Thread.new do
|
16
|
+
begin
|
17
|
+
with_environment(ru_file) do |dir|
|
18
|
+
@pid = Process.spawn context.app_server_command,
|
19
|
+
in: '/dev/null',
|
20
|
+
out: '/dev/null',
|
21
|
+
err: '/dev/null',
|
22
|
+
chdir: dir
|
23
|
+
@stop_var.take
|
24
|
+
Process.kill 'TERM', @pid
|
25
|
+
Process.wait @pid
|
26
|
+
@pid = nil
|
27
|
+
end
|
28
|
+
rescue => e
|
29
|
+
$stderr.puts "App server thread exited: #{e.message}\n#{e.backtrace.join("\n")}"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
port = wait_for_port
|
34
|
+
|
35
|
+
"http://localhost:#{port}"
|
36
|
+
end
|
37
|
+
|
38
|
+
def stop
|
39
|
+
@stop_var.put true
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def wait_for_port
|
45
|
+
time = Time.now
|
46
|
+
while Time.now - time < context.startup_timeout && !check_port
|
47
|
+
sleep 0.1
|
48
|
+
end
|
49
|
+
|
50
|
+
if !check_port
|
51
|
+
Process.kill 'TERM', @pid if @pid
|
52
|
+
raise "Application server did not start up in time"
|
53
|
+
end
|
54
|
+
|
55
|
+
context.app_server_port
|
56
|
+
end
|
57
|
+
|
58
|
+
def check_port
|
59
|
+
`lsof -n -i :#{context.app_server_port}`.lines.count > 0
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,267 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module RackCheck::Spec
|
4
|
+
RSpec.describe "Rack env variables" do
|
5
|
+
ENV_RU = %Q{
|
6
|
+
require 'json'
|
7
|
+
run ->(env) { [200, {"Content-Type" => "application/json"}, [JSON.dump(env)]] }
|
8
|
+
}
|
9
|
+
|
10
|
+
def with_server(ru_file)
|
11
|
+
yield start_server(ru_file)
|
12
|
+
ensure
|
13
|
+
stop_server
|
14
|
+
end
|
15
|
+
|
16
|
+
def start_server(ru_file)
|
17
|
+
@server = ServerManager.new(RackCheck::Spec::server_context, ru_file)
|
18
|
+
@endpoint = @server.run
|
19
|
+
end
|
20
|
+
|
21
|
+
def stop_server
|
22
|
+
@server.stop
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "CGI style variables" do
|
26
|
+
before :all do
|
27
|
+
start_server(ENV_RU)
|
28
|
+
end
|
29
|
+
|
30
|
+
after :all do
|
31
|
+
stop_server
|
32
|
+
end
|
33
|
+
|
34
|
+
it "includes the request method" do
|
35
|
+
result = JSON.load HTTP.get(@endpoint).to_s
|
36
|
+
expect(result['REQUEST_METHOD']).to eq "GET"
|
37
|
+
|
38
|
+
result = JSON.load HTTP.post(@endpoint).to_s
|
39
|
+
expect(result['REQUEST_METHOD']).to eq "POST"
|
40
|
+
end
|
41
|
+
|
42
|
+
it "includes parts extracted from the url" do
|
43
|
+
result = JSON.load HTTP.get(@endpoint + '/bladiebla?querystring').to_s
|
44
|
+
expect(result['SCRIPT_NAME']).to eq ""
|
45
|
+
expect(result['PATH_INFO']).to eq "/bladiebla"
|
46
|
+
expect(result['QUERY_STRING']).to eq "querystring"
|
47
|
+
end
|
48
|
+
|
49
|
+
it "includes information about the server address" do
|
50
|
+
result = JSON.load HTTP.get(@endpoint).to_s
|
51
|
+
expect(result['SERVER_NAME']).to eq "localhost"
|
52
|
+
expect(result['SERVER_PORT']).to eq "54123"
|
53
|
+
end
|
54
|
+
|
55
|
+
it "includes any client supplied headers" do
|
56
|
+
result = JSON.load HTTP.headers(random: 'bla').get(@endpoint).to_s
|
57
|
+
expect(result['HTTP_RANDOM']).to eq "bla"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "special rack variables" do
|
62
|
+
it "includes information about the server" do
|
63
|
+
with_server(ENV_RU) do |endpoint|
|
64
|
+
result = JSON.load HTTP.get(endpoint).to_s
|
65
|
+
expect(result['rack.version'].first).to be >= 1
|
66
|
+
|
67
|
+
expect(result['rack.url_scheme']).to eq 'http'
|
68
|
+
expect(result).to include('rack.multithread')
|
69
|
+
expect(result).to include('rack.multiprocess')
|
70
|
+
expect(result).to include('rack.run_once')
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe "includes an input stream" do
|
75
|
+
it "exposes an input stream that can be 'gets'ed until it returns nil" do
|
76
|
+
with_server(%Q{
|
77
|
+
require 'json'
|
78
|
+
run ->(env) {
|
79
|
+
result = ""
|
80
|
+
while !(next_value = env['rack.input'].gets).nil?
|
81
|
+
result << next_value
|
82
|
+
end
|
83
|
+
[200, {"Content-Type" => "application/json"}, [result]]
|
84
|
+
}
|
85
|
+
}) do |endpoint|
|
86
|
+
example = "multiline\nbody"
|
87
|
+
expect(HTTP.post(endpoint, body: example).to_s).to eq(example)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
it "exposes an input stream that can be rewinded" do
|
92
|
+
with_server(%Q{
|
93
|
+
require 'json'
|
94
|
+
run ->(env) {
|
95
|
+
result = ""
|
96
|
+
while !(next_value = env['rack.input'].gets).nil?
|
97
|
+
result << next_value
|
98
|
+
end
|
99
|
+
env['rack.input'].rewind
|
100
|
+
while !(next_value = env['rack.input'].gets).nil?
|
101
|
+
result << next_value
|
102
|
+
end
|
103
|
+
[200, {"Content-Type" => "application/json"}, [result]]
|
104
|
+
}
|
105
|
+
}) do |endpoint|
|
106
|
+
example = "multiline\nbody"
|
107
|
+
expect(HTTP.post(endpoint, body: example).to_s).to eq(example + example)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
describe "that exposes an input stream with a #read like IO#read" do
|
112
|
+
it "reads until EOF when called without an argument" do
|
113
|
+
with_server(%Q{
|
114
|
+
require 'json'
|
115
|
+
run ->(env) {
|
116
|
+
result = env['rack.input'].read
|
117
|
+
[200, {"Content-Type" => "application/json"}, [result]]
|
118
|
+
}
|
119
|
+
}) do |endpoint|
|
120
|
+
example = "multiline\nbody"
|
121
|
+
expect(HTTP.post(endpoint, body: example).to_s).to eq(example)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
it "returns '' if no argument given and EOF written" do
|
126
|
+
with_server(%Q{
|
127
|
+
require 'json'
|
128
|
+
run ->(env) {
|
129
|
+
env['rack.input'].read
|
130
|
+
result = env['rack.input'].read
|
131
|
+
[200, {"Content-Type" => "application/json"}, [result.class.name + result.to_s]]
|
132
|
+
}
|
133
|
+
}) do |endpoint|
|
134
|
+
example = "multiline\nbody"
|
135
|
+
expect(HTTP.post(endpoint, body: example).to_s).to eq('String')
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
it "returns '' if no argument given and EOF written" do
|
140
|
+
with_server(%Q{
|
141
|
+
require 'json'
|
142
|
+
run ->(env) {
|
143
|
+
env['rack.input'].read
|
144
|
+
result = env['rack.input'].read(1024)
|
145
|
+
[200, {"Content-Type" => "application/json"}, [result.class.name + result.to_s]]
|
146
|
+
}
|
147
|
+
}) do |endpoint|
|
148
|
+
example = "multiline\nbody"
|
149
|
+
expect(HTTP.post(endpoint, body: example).to_s).to eq('NilClass')
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
it "can read up to an amount of bytes when length is given" do
|
154
|
+
with_server(%Q{
|
155
|
+
require 'json'
|
156
|
+
run ->(env) {
|
157
|
+
buffer = "*********************************"
|
158
|
+
env['rack.input'].read(9, buffer)
|
159
|
+
[200, {"Content-Type" => "application/json"}, [buffer]]
|
160
|
+
}
|
161
|
+
}) do |endpoint|
|
162
|
+
example = "multiline\nbody"
|
163
|
+
expect(HTTP.post(endpoint, body: example).to_s).to eq('multiline')
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
|
168
|
+
it "places results in a buffer if given" do
|
169
|
+
with_server(%Q{
|
170
|
+
require 'json'
|
171
|
+
run ->(env) {
|
172
|
+
buffer = "*********************************"
|
173
|
+
env['rack.input'].read(9, buffer)
|
174
|
+
[200, {"Content-Type" => "application/json"}, [buffer]]
|
175
|
+
}
|
176
|
+
}) do |endpoint|
|
177
|
+
example = "multiline\nbody"
|
178
|
+
expect(HTTP.post(endpoint, body: example).to_s).to eq('multiline')
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
describe "includes an error stream" do
|
185
|
+
it "has a #puts that takes an object that responds to `to_s`" do
|
186
|
+
with_server(%Q{
|
187
|
+
require 'json'
|
188
|
+
run ->(env) {
|
189
|
+
class S < BasicObject
|
190
|
+
def to_s
|
191
|
+
"result"
|
192
|
+
end
|
193
|
+
end
|
194
|
+
env['rack.errors'].puts S.new
|
195
|
+
[200, {"Content-Type" => "application/json"}, ["Ok"]]
|
196
|
+
}
|
197
|
+
}) do |endpoint|
|
198
|
+
expect(HTTP.get(endpoint).to_s).to eq('Ok')
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
it "has a #write that takes a String" do
|
203
|
+
with_server(%Q{
|
204
|
+
require 'json'
|
205
|
+
run ->(env) {
|
206
|
+
env['rack.errors'].puts 'result'
|
207
|
+
[200, {"Content-Type" => "application/json"}, ["Ok"]]
|
208
|
+
}
|
209
|
+
}) do |endpoint|
|
210
|
+
expect(HTTP.get(endpoint).to_s).to eq('Ok')
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
it "has a #flush that takes no arguments" do
|
215
|
+
with_server(%Q{
|
216
|
+
require 'json'
|
217
|
+
run ->(env) {
|
218
|
+
env['rack.errors'].flush
|
219
|
+
[200, {"Content-Type" => "application/json"}, ["Ok"]]
|
220
|
+
}
|
221
|
+
}) do |endpoint|
|
222
|
+
expect(HTTP.get(endpoint).to_s).to eq('Ok')
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
def supports_hijack?
|
228
|
+
if @supports_hijack.nil?
|
229
|
+
result = ''
|
230
|
+
with_server(ENV_RU) do |endpoint|
|
231
|
+
result = JSON.load HTTP.get(endpoint).to_s
|
232
|
+
end
|
233
|
+
@supports_hijack = result['rack.hijack?']
|
234
|
+
end
|
235
|
+
@supports_hijack
|
236
|
+
end
|
237
|
+
|
238
|
+
describe "might support rack hijack" do
|
239
|
+
before :all do
|
240
|
+
skip("Hijack not supported") if not supports_hijack?
|
241
|
+
end
|
242
|
+
|
243
|
+
it "exposes whether it supports rack hijack" do
|
244
|
+
expect(@supports_hijack).to eq(true)
|
245
|
+
end
|
246
|
+
|
247
|
+
it "responds to #call which returns an io that is also rack.hijack_io" do
|
248
|
+
with_server(%Q{
|
249
|
+
require 'json'
|
250
|
+
run ->(env) {
|
251
|
+
io = env['rack.hijack'].call
|
252
|
+
equals = env['rack.hijack_io'] == io
|
253
|
+
io.write("HTTP/1.1 200 OK\r\n")
|
254
|
+
io.write("Connection: Closed\r\n")
|
255
|
+
io.write("Content-Type: text/plain\r\n")
|
256
|
+
io.write("\r\n")
|
257
|
+
io.write("Equals: " + equals.to_s)
|
258
|
+
io.close
|
259
|
+
}
|
260
|
+
}) do |endpoint|
|
261
|
+
expect(HTTP.get(endpoint).to_s).to eq('Equals: true')
|
262
|
+
end
|
263
|
+
end
|
264
|
+
end
|
265
|
+
end
|
266
|
+
end
|
267
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module RackCheck::Spec
|
2
|
+
RSpec.describe "Running rackup files" do
|
3
|
+
it "runs hello world rack applications" do
|
4
|
+
begin
|
5
|
+
s = ServerManager.new RackCheck::Spec::server_context, %Q{
|
6
|
+
run ->(env) { [200, {"Content-Type" => "text/html"}, ["Hello World!"]] }
|
7
|
+
}
|
8
|
+
|
9
|
+
endpoint = s.run
|
10
|
+
result = HTTP.get(endpoint).to_s
|
11
|
+
|
12
|
+
expect(result).to eq "Hello World!"
|
13
|
+
ensure
|
14
|
+
s.stop
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module RackCheck::Spec
|
2
|
+
include RackCheck
|
3
|
+
|
4
|
+
class Context
|
5
|
+
attr_reader :app_server_command, :app_server_port, :startup_timeout
|
6
|
+
|
7
|
+
def initialize(app_server_command, app_server_port, startup_timeout)
|
8
|
+
@app_server_port = app_server_port
|
9
|
+
@app_server_command = app_server_command
|
10
|
+
@startup_timeout = startup_timeout
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
STARTUP_TIMEOUT = 10
|
15
|
+
|
16
|
+
def self.run(app_server_command, app_server_port)
|
17
|
+
@@context = Context.new(app_server_command, app_server_port, STARTUP_TIMEOUT)
|
18
|
+
|
19
|
+
# TODO there must be a better way to pass context to a rspec suite
|
20
|
+
RSpec::Core::Runner.run([])
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.server_context
|
24
|
+
@@context
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
require 'rack_check/spec/rackup'
|
29
|
+
require 'rack_check/spec/env'
|
data/lib/rack_check.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'concurrent'
|
4
|
+
require 'http'
|
5
|
+
|
6
|
+
require 'rack_check'
|
7
|
+
require 'rack_check/version'
|
8
|
+
require 'rack_check/helpers'
|
9
|
+
require 'rack_check/server_manager'
|
10
|
+
require 'rack_check/spec'
|
11
|
+
|
12
|
+
module RackCheck
|
13
|
+
# Your code goes here...
|
14
|
+
end
|
data/rack_check.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rack_check/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rack_check"
|
8
|
+
spec.version = RackCheck::VERSION
|
9
|
+
spec.authors = ["Tinco Andringa"]
|
10
|
+
spec.email = ["tinco@phusion.nl"]
|
11
|
+
|
12
|
+
spec.summary = %q{Tool that checks a Ruby application server for Rack compliancy}
|
13
|
+
spec.homepage = "https://github.com/phusion/rack_check"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
spec.bindir = "exe"
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_runtime_dependency "rspec", "~> 3.0"
|
26
|
+
spec.add_runtime_dependency "concurrent-ruby", "~> 1.0"
|
27
|
+
spec.add_runtime_dependency "http", "~> 2.2"
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack_check
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tinco Andringa
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-03-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: concurrent-ruby
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: http
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.2'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.2'
|
83
|
+
description:
|
84
|
+
email:
|
85
|
+
- tinco@phusion.nl
|
86
|
+
executables:
|
87
|
+
- rack-check
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- ".rspec"
|
93
|
+
- ".travis.yml"
|
94
|
+
- CODE_OF_CONDUCT.md
|
95
|
+
- Gemfile
|
96
|
+
- LICENSE.txt
|
97
|
+
- README.md
|
98
|
+
- Rakefile
|
99
|
+
- bin/console
|
100
|
+
- bin/setup
|
101
|
+
- exe/rack-check
|
102
|
+
- lib/rack_check.rb
|
103
|
+
- lib/rack_check/helpers.rb
|
104
|
+
- lib/rack_check/server_manager.rb
|
105
|
+
- lib/rack_check/spec.rb
|
106
|
+
- lib/rack_check/spec/env.rb
|
107
|
+
- lib/rack_check/spec/rackup.rb
|
108
|
+
- lib/rack_check/version.rb
|
109
|
+
- rack_check.gemspec
|
110
|
+
homepage: https://github.com/phusion/rack_check
|
111
|
+
licenses:
|
112
|
+
- MIT
|
113
|
+
metadata: {}
|
114
|
+
post_install_message:
|
115
|
+
rdoc_options: []
|
116
|
+
require_paths:
|
117
|
+
- lib
|
118
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
requirements: []
|
129
|
+
rubyforge_project:
|
130
|
+
rubygems_version: 2.5.2
|
131
|
+
signing_key:
|
132
|
+
specification_version: 4
|
133
|
+
summary: Tool that checks a Ruby application server for Rack compliancy
|
134
|
+
test_files: []
|