rvt 0.9.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/Rakefile +25 -0
  4. data/app/assets/javascripts/rvt/application.js +1 -0
  5. data/app/assets/javascripts/rvt/console_sessions.js +182 -0
  6. data/app/assets/stylesheets/rvt/application.css +13 -0
  7. data/app/assets/stylesheets/rvt/console_sessions.css.erb +6 -0
  8. data/app/controllers/rvt/application_controller.rb +13 -0
  9. data/app/controllers/rvt/console_sessions_controller.rb +47 -0
  10. data/app/models/rvt/console_session.rb +109 -0
  11. data/app/views/layouts/rvt/application.html.erb +14 -0
  12. data/app/views/rvt/console_sessions/index.html.erb +17 -0
  13. data/config/routes.rb +11 -0
  14. data/lib/assets/javascripts/rvt.js +41 -0
  15. data/lib/rvt.rb +21 -0
  16. data/lib/rvt/colors.rb +87 -0
  17. data/lib/rvt/colors/light.rb +24 -0
  18. data/lib/rvt/colors/monokai.rb +24 -0
  19. data/lib/rvt/colors/solarized.rb +47 -0
  20. data/lib/rvt/colors/tango.rb +24 -0
  21. data/lib/rvt/colors/xterm.rb +24 -0
  22. data/lib/rvt/engine.rb +85 -0
  23. data/lib/rvt/slave.rb +147 -0
  24. data/lib/rvt/version.rb +3 -0
  25. data/test/controllers/rvt/console_sessions_controller_test.rb +100 -0
  26. data/test/dummy/Rakefile +6 -0
  27. data/test/dummy/app/assets/javascripts/application.js +13 -0
  28. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  29. data/test/dummy/app/controllers/application_controller.rb +5 -0
  30. data/test/dummy/app/helpers/application_helper.rb +2 -0
  31. data/test/dummy/app/views/controller_helper_test/index.html.erb +1 -0
  32. data/test/dummy/app/views/exception_test/xhr.html.erb +1 -0
  33. data/test/dummy/app/views/helper_test/index.html.erb +220 -0
  34. data/test/dummy/app/views/layouts/application.html.erb +16 -0
  35. data/test/dummy/bin/bundle +3 -0
  36. data/test/dummy/bin/rails +4 -0
  37. data/test/dummy/bin/rake +4 -0
  38. data/test/dummy/config.ru +4 -0
  39. data/test/dummy/config/application.rb +44 -0
  40. data/test/dummy/config/boot.rb +5 -0
  41. data/test/dummy/config/database.yml +25 -0
  42. data/test/dummy/config/environment.rb +5 -0
  43. data/test/dummy/config/environments/development.rb +29 -0
  44. data/test/dummy/config/environments/production.rb +80 -0
  45. data/test/dummy/config/environments/test.rb +34 -0
  46. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  47. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  48. data/test/dummy/config/initializers/inflections.rb +16 -0
  49. data/test/dummy/config/initializers/mime_types.rb +5 -0
  50. data/test/dummy/config/initializers/secret_token.rb +12 -0
  51. data/test/dummy/config/initializers/session_store.rb +3 -0
  52. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  53. data/test/dummy/config/locales/en.yml +23 -0
  54. data/test/dummy/config/routes.rb +2 -0
  55. data/test/dummy/db/development.sqlite3 +0 -0
  56. data/test/dummy/db/schema.rb +16 -0
  57. data/test/dummy/db/test.sqlite3 +0 -0
  58. data/test/dummy/log/development.log +247222 -0
  59. data/test/dummy/log/test.log +963 -0
  60. data/test/dummy/public/404.html +58 -0
  61. data/test/dummy/public/422.html +58 -0
  62. data/test/dummy/public/500.html +57 -0
  63. data/test/dummy/public/favicon.ico +0 -0
  64. data/test/dummy/tmp/cache/assets/development/sprockets/0509a6e0e75d9ac5a88bba7291b04686 +0 -0
  65. data/test/dummy/tmp/cache/assets/development/sprockets/2bd9d10dae311aa2dfb6dea9c1e0ad50 +0 -0
  66. data/test/dummy/tmp/cache/assets/development/sprockets/2f41a6a41d0a16db31cabd2b8689ca00 +0 -0
  67. data/test/dummy/tmp/cache/assets/development/sprockets/4de66e84a0d6f009fac50cd608fb8581 +0 -0
  68. data/test/dummy/tmp/cache/assets/development/sprockets/56e8026311075410507152df2aea4307 +0 -0
  69. data/test/dummy/tmp/cache/assets/development/sprockets/9542de15712d45f70221931bf78c00e5 +0 -0
  70. data/test/dummy/tmp/cache/assets/development/sprockets/98cea396a602c53d876e79bf4b89de3b +0 -0
  71. data/test/dummy/tmp/cache/assets/development/sprockets/9df3968b0f171feec749766fffa50b2e +0 -0
  72. data/test/dummy/tmp/cache/assets/development/sprockets/aa5fc4cb46c5294192c9d3af8824f88b +0 -0
  73. data/test/dummy/tmp/cache/assets/development/sprockets/ac7197dc7dd9ab362d915d19e37a8e01 +0 -0
  74. data/test/dummy/tmp/cache/assets/development/sprockets/b238befd6eff46b26d56322c1450ea45 +0 -0
  75. data/test/dummy/tmp/cache/assets/development/sprockets/c69b8b79c21fd48ad84c3fad87945a5c +0 -0
  76. data/test/dummy/tmp/cache/assets/development/sprockets/da4318a4d8364d0616edd706508371bc +0 -0
  77. data/test/dummy/tmp/cache/assets/development/sprockets/dd71b14df42fd6dc95355cded9e4d0f9 +0 -0
  78. data/test/dummy/tmp/cache/assets/development/sprockets/eb06cae1627276e46965809e766aff13 +0 -0
  79. data/test/dummy/tmp/cache/assets/development/sprockets/edffb5017d27ddb65965203636286405 +0 -0
  80. data/test/dummy/tmp/cache/assets/development/sprockets/f0ced5f3d4a75fce1c596d6c3f97a42d +0 -0
  81. data/test/dummy/tmp/cache/assets/development/sprockets/fb9e611526e612ba797f0c11b987826b +0 -0
  82. data/test/models/console_session_test.rb +58 -0
  83. data/test/rvt/colors_test.rb +58 -0
  84. data/test/rvt/engine_test.rb +145 -0
  85. data/test/rvt/slave_test.rb +72 -0
  86. data/test/test_helper.rb +27 -0
  87. data/vendor/assets/javascripts/term.js +5771 -0
  88. metadata +284 -0
@@ -0,0 +1,3 @@
1
+ module RVT
2
+ VERSION = '0.9.9'
3
+ end
@@ -0,0 +1,100 @@
1
+ require 'test_helper'
2
+
3
+ module RVT
4
+ class ConsoleSessionsControllerTest < ActionController::TestCase
5
+ setup do
6
+ PTY.stubs(:spawn).returns([StringIO.new, StringIO.new, Random.rand(20000)])
7
+ @request.stubs(:remote_ip).returns('127.0.0.1')
8
+ end
9
+
10
+ test 'index is successful' do
11
+ get :index, use_route: 'rvt'
12
+ assert_response :success
13
+ end
14
+
15
+ test 'GET index creates new console session' do
16
+ assert_difference 'ConsoleSession::INMEMORY_STORAGE.size' do
17
+ get :index, use_route: 'rvt'
18
+ end
19
+ end
20
+
21
+ test 'PUT input validates for missing input' do
22
+ get :index, use_route: 'rvt'
23
+
24
+ assert_not_nil console_session = assigns(:console_session)
25
+
26
+ console_session.instance_variable_get(:@slave).stubs(:send_input).raises(ArgumentError)
27
+ put :input, id: console_session.pid, uid: console_session.uid, use_route: 'rvt'
28
+
29
+ assert_response :unprocessable_entity
30
+ end
31
+
32
+ test 'PUT input sends input to the slave' do
33
+ get :index, use_route: 'rvt'
34
+
35
+ assert_not_nil console_session = assigns(:console_session)
36
+
37
+ console_session.expects(:send_input)
38
+ put :input, input: ' ', id: console_session.pid, uid: console_session.uid, use_route: 'rvt'
39
+ end
40
+
41
+ test 'GET pending_output gives the slave pending output' do
42
+ get :index, use_route: 'rvt'
43
+
44
+ assert_not_nil console_session = assigns(:console_session)
45
+ console_session.expects(:pending_output)
46
+
47
+ get :pending_output, id: console_session.pid, uid: console_session.uid, use_route: 'rvt'
48
+ end
49
+
50
+ test 'GET pending_output raises 410 on exitted slave processes' do
51
+ get :index, use_route: 'rvt'
52
+
53
+ assert_not_nil console_session = assigns(:console_session)
54
+ console_session.stubs(:pending_output).raises(ConsoleSession::Unavailable)
55
+
56
+ get :pending_output, id: console_session.pid, uid: console_session.uid, use_route: 'rvt'
57
+ assert_response :gone
58
+ end
59
+
60
+ test 'PUT configuration adjust the terminal size' do
61
+ get :index, use_route: 'rvt'
62
+
63
+ assert_not_nil console_session = assigns(:console_session)
64
+ console_session.expects(:configure).with(
65
+ 'id' => console_session.pid.to_s,
66
+ 'uid' => console_session.uid,
67
+ 'width' => '80',
68
+ 'height' => '24',
69
+ )
70
+
71
+ put :configuration, id: console_session.pid, uid: console_session.uid, width: 80, height: 24, use_route: 'rvt'
72
+ assert_response :success
73
+ end
74
+
75
+ test 'blocks requests from non-whitelisted ips' do
76
+ @request.stubs(:remote_ip).returns('128.0.0.1')
77
+ get :index, use_route: 'rvt'
78
+ assert_response :unauthorized
79
+ end
80
+
81
+ test 'allows requests from whitelisted ips' do
82
+ @request.stubs(:remote_ip).returns('127.0.0.1')
83
+ get :index, use_route: 'rvt'
84
+ assert_response :success
85
+ end
86
+
87
+ test 'index generated path' do
88
+ assert_generates mount_path, {
89
+ use_route: 'rvt',
90
+ controller: 'console_sessions'
91
+ }, {}, {controller: 'console_sessions'}
92
+ end
93
+
94
+ private
95
+
96
+ def mount_path
97
+ RVT::Engine.config.rvt.default_mount_path
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+
6
+ Dummy::Application.load_tasks
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
+ // GO AFTER THE REQUIRES BELOW.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,13 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree .
13
+ */
@@ -0,0 +1,5 @@
1
+ class ApplicationController < ActionController::Base
2
+ # Prevent CSRF attacks by raising an exception.
3
+ # For APIs, you may want to use :null_session instead.
4
+ protect_from_forgery with: :exception
5
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1 @@
1
+ <h1>Controller Helper Test</h1>
@@ -0,0 +1 @@
1
+ <p>Do an XHR request!</p>
@@ -0,0 +1,220 @@
1
+ <%= console %>
2
+
3
+ <% content_for :head do %>
4
+ <style type="text/css" media="screen">
5
+ body {
6
+ margin: 0;
7
+ margin-bottom: 25px;
8
+ padding: 0;
9
+ background-color: #f0f0f0;
10
+ font-family: "Lucida Grande", "Bitstream Vera Sans", "Verdana";
11
+ font-size: 13px;
12
+ color: #333;
13
+ }
14
+
15
+ h1 {
16
+ font-size: 28px;
17
+ color: #000;
18
+ }
19
+
20
+ a {color: #03c}
21
+ a:hover {
22
+ background-color: #03c;
23
+ color: white;
24
+ text-decoration: none;
25
+ }
26
+
27
+
28
+ #page {
29
+ background-color: #f0f0f0;
30
+ width: 750px;
31
+ margin: 0;
32
+ margin-left: auto;
33
+ margin-right: auto;
34
+ }
35
+
36
+ #content {
37
+ float: left;
38
+ background-color: white;
39
+ border: 3px solid #aaa;
40
+ border-top: none;
41
+ padding: 25px;
42
+ width: 500px;
43
+ }
44
+
45
+ #sidebar {
46
+ float: right;
47
+ width: 175px;
48
+ }
49
+
50
+ #footer {
51
+ clear: both;
52
+ }
53
+
54
+
55
+ #header, #about, #getting-started {
56
+ padding-left: 75px;
57
+ padding-right: 30px;
58
+ }
59
+
60
+
61
+ #header {
62
+ height: 64px;
63
+ }
64
+ #header h1, #header h2 {margin: 0}
65
+ #header h2 {
66
+ color: #888;
67
+ font-weight: normal;
68
+ font-size: 16px;
69
+ }
70
+
71
+
72
+ #about h3 {
73
+ margin: 0;
74
+ margin-bottom: 10px;
75
+ font-size: 14px;
76
+ }
77
+
78
+ #about-content {
79
+ background-color: #ffd;
80
+ border: 1px solid #fc0;
81
+ margin-left: -55px;
82
+ margin-right: -10px;
83
+ }
84
+ #about-content table {
85
+ margin-top: 10px;
86
+ margin-bottom: 10px;
87
+ font-size: 11px;
88
+ border-collapse: collapse;
89
+ }
90
+ #about-content td {
91
+ padding: 10px;
92
+ padding-top: 3px;
93
+ padding-bottom: 3px;
94
+ }
95
+ #about-content td.name {color: #555}
96
+ #about-content td.value {color: #000}
97
+
98
+ #about-content ul {
99
+ padding: 0;
100
+ list-style-type: none;
101
+ }
102
+
103
+ #about-content.failure {
104
+ background-color: #fcc;
105
+ border: 1px solid #f00;
106
+ }
107
+ #about-content.failure p {
108
+ margin: 0;
109
+ padding: 10px;
110
+ }
111
+
112
+
113
+ #getting-started {
114
+ border-top: 1px solid #ccc;
115
+ margin-top: 25px;
116
+ padding-top: 15px;
117
+ }
118
+ #getting-started h1 {
119
+ margin: 0;
120
+ font-size: 20px;
121
+ }
122
+ #getting-started h2 {
123
+ margin: 0;
124
+ font-size: 14px;
125
+ font-weight: normal;
126
+ color: #333;
127
+ margin-bottom: 25px;
128
+ }
129
+ #getting-started ol {
130
+ margin-left: 0;
131
+ padding-left: 0;
132
+ }
133
+ #getting-started li {
134
+ font-size: 18px;
135
+ color: #888;
136
+ margin-bottom: 25px;
137
+ }
138
+ #getting-started li h2 {
139
+ margin: 0;
140
+ font-weight: normal;
141
+ font-size: 18px;
142
+ color: #333;
143
+ }
144
+ #getting-started li p {
145
+ color: #555;
146
+ font-size: 13px;
147
+ }
148
+
149
+
150
+ #sidebar ul {
151
+ margin-left: 0;
152
+ padding-left: 0;
153
+ }
154
+ #sidebar ul h3 {
155
+ margin-top: 25px;
156
+ font-size: 16px;
157
+ padding-bottom: 10px;
158
+ border-bottom: 1px solid #ccc;
159
+ }
160
+ #sidebar li {
161
+ list-style-type: none;
162
+ }
163
+ #sidebar ul.links li {
164
+ margin-bottom: 5px;
165
+ }
166
+
167
+ </style>
168
+ <% end %>
169
+
170
+ <div id="page">
171
+ <div id="sidebar">
172
+ <ul id="sidebar-items">
173
+ <li>
174
+ <h3>Browse the documentation</h3>
175
+ <ul class="links">
176
+ <li><a href="http://api.rubyonrails.org/">Rails API</a></li>
177
+ <li><a href="http://stdlib.rubyonrails.org/">Ruby standard library</a></li>
178
+ <li><a href="http://corelib.rubyonrails.org/">Ruby core</a></li>
179
+ <li><a href="http://guides.rubyonrails.org/">Rails Guides</a></li>
180
+ </ul>
181
+ </li>
182
+ </ul>
183
+ </div>
184
+
185
+ <div id="content">
186
+ <div id="header">
187
+ <h1>Welcome aboard</h1>
188
+ <h2>You&rsquo;re riding Ruby on Rails!</h2>
189
+ </div>
190
+
191
+ <div id="about">
192
+ <h3><a href="rails/info/properties" onclick="about(); return false">About your application&rsquo;s environment</a></h3>
193
+ <div id="about-content" style="display: none"></div>
194
+ </div>
195
+
196
+ <div id="getting-started">
197
+ <h1>Getting started</h1>
198
+ <h2>Here&rsquo;s how to get rolling:</h2>
199
+
200
+ <ol>
201
+ <li>
202
+ <h2>Use <code>rails generate</code> to create your models and controllers</h2>
203
+ <p>To see all available options, run it without parameters.</p>
204
+ </li>
205
+
206
+ <li>
207
+ <h2>Set up a default route and remove or rename this file</h2>
208
+ <p>Routes are set up in config/routes.rb.</p>
209
+ </li>
210
+
211
+ <li>
212
+ <h2>Create your database</h2>
213
+ <p>Run <code>rake db:migrate</code> to create your database. If you're not using SQLite (the default), edit <code>config/database.yml</code> with your username and password.</p>
214
+ </li>
215
+ </ol>
216
+ </div>
217
+ </div>
218
+
219
+ <div id="footer">&nbsp;</div>
220
+ </div>
@@ -0,0 +1,16 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
6
+ <%= javascript_include_tag "application", "data-turbolinks-track" => true %>
7
+ <%= csrf_meta_tags %>
8
+ <%= yield :head %>
9
+
10
+ </head>
11
+ <body>
12
+
13
+ <%= yield %>
14
+
15
+ </body>
16
+ </html>
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
+ load Gem.bin_path('bundler', 'bundle')
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
3
+ require_relative '../config/boot'
4
+ require 'rails/commands'
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../config/boot'
3
+ require 'rake'
4
+ Rake.application.run
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Rails.application
@@ -0,0 +1,44 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require 'rails/all'
4
+
5
+ Bundler.require(*Rails.groups)
6
+ require 'rvt'
7
+
8
+ module Dummy
9
+ class Application < Rails::Application
10
+ # Automatically mount the console to tests the terminal side as well.
11
+ config.rvt.automount = true
12
+
13
+ if ENV['LONG_POLLING']
14
+ # You have to explicitly enable the concurrency, as in development mode,
15
+ # the falsy config.cache_classes implies no concurrency support.
16
+ #
17
+ # The concurrency is enabled by removing the Rack::Lock middleware, which
18
+ # wraps each request in a mutex, effectively making the request handling
19
+ # synchronous.
20
+ config.allow_concurrency = true
21
+
22
+ # For long-polling 45 seconds timeout seems reasonable.
23
+ config.rvt.timeout = 45.seconds
24
+ end
25
+
26
+ config.rvt.style.colors =
27
+ if ENV['SOLARIZED_LIGHT']
28
+ 'solarized_light'
29
+ elsif ENV['SOLARIZED_DARK']
30
+ 'solarized_dark'
31
+ elsif ENV['TANGO']
32
+ 'tango'
33
+ elsif ENV['XTERM']
34
+ 'xterm'
35
+ elsif ENV['MONOKAI']
36
+ 'monokai'
37
+ else
38
+ 'light'
39
+ end
40
+
41
+ # The test order can be random after 4.1.
42
+ config.active_support.test_order = :random
43
+ end
44
+ end