test_server 0.2.4 → 0.3.1

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 (106) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +3 -0
  3. data/Gemfile +54 -29
  4. data/README.rdoc +28 -0
  5. data/Rakefile +3 -3
  6. data/app/assets/images/.keep +0 -0
  7. data/app/assets/javascripts/application.js +14 -0
  8. data/app/assets/javascripts/errors.js +2 -0
  9. data/app/assets/stylesheets/application.scss +83 -0
  10. data/app/assets/stylesheets/errors.css +4 -0
  11. data/app/controllers/concerns/.keep +0 -0
  12. data/app/controllers/test_server/application_controller.rb +34 -0
  13. data/app/controllers/test_server/dashboard_controller.rb +9 -0
  14. data/app/controllers/test_server/errors_controller.rb +22 -0
  15. data/app/controllers/test_server/generator_controller.rb +40 -0
  16. data/app/controllers/test_server/static_controller.rb +16 -0
  17. data/app/controllers/test_server/streaming_controller.rb +56 -0
  18. data/app/controllers/test_server/string_controller.rb +39 -0
  19. data/app/helpers/application_helper.rb +2 -0
  20. data/app/helpers/errors_helper.rb +2 -0
  21. data/app/mailers/.keep +0 -0
  22. data/app/models/.keep +0 -0
  23. data/app/models/concerns/.keep +0 -0
  24. data/app/views/layouts/application.html.haml +59 -0
  25. data/app/views/shared/_overview.html.haml +16 -0
  26. data/app/views/test_server/dashboard/show.html.haml +7 -0
  27. data/app/views/test_server/errors/not_found.html.haml +2 -0
  28. data/app/views/test_server/errors/show.html.haml +6 -0
  29. data/app/views/test_server/generator/_overview.html.haml +1 -0
  30. data/app/views/test_server/generator/index.html.haml +1 -0
  31. data/app/views/{xhr/show.haml → test_server/generator/xhr.html.haml} +15 -12
  32. data/app/views/test_server/static/_overview.html.haml +1 -0
  33. data/app/views/test_server/static/index.html.haml +1 -0
  34. data/app/views/test_server/streaming/_overview.html.haml +1 -0
  35. data/app/views/test_server/streaming/index.html.haml +1 -0
  36. data/app/views/test_server/string/_overview.html.haml +1 -0
  37. data/app/views/test_server/string/index.html.haml +1 -0
  38. data/config.ru +3 -50
  39. data/config/application.rb +44 -0
  40. data/config/boot.rb +4 -0
  41. data/config/database.yml +25 -0
  42. data/config/environment.rb +5 -0
  43. data/config/environments/development.rb +37 -0
  44. data/config/environments/production.rb +87 -0
  45. data/config/environments/profile.rb +85 -0
  46. data/config/environments/test.rb +39 -0
  47. data/config/initializers/backtrace_silencers.rb +7 -0
  48. data/config/initializers/breadbrumb_builder.rb +24 -0
  49. data/config/initializers/change_values.rb +5 -0
  50. data/config/initializers/cookies_serializer.rb +3 -0
  51. data/config/initializers/filter_parameter_logging.rb +4 -0
  52. data/config/initializers/inflections.rb +16 -0
  53. data/config/initializers/mime_types.rb +4 -0
  54. data/config/initializers/session_store.rb +3 -0
  55. data/config/initializers/to_bool.rb +23 -0
  56. data/config/initializers/wrap_parameters.rb +14 -0
  57. data/config/locales/en.yml +23 -0
  58. data/config/routes.rb +78 -0
  59. data/config/secrets.yml +22 -0
  60. data/lib/assets/.keep +0 -0
  61. data/lib/tasks/.keep +0 -0
  62. data/lib/test_server.rb +13 -15
  63. data/lib/test_server/error_handler.rb +15 -11
  64. data/lib/test_server/error_messages.rb +16 -6
  65. data/lib/test_server/exceptions.rb +6 -0
  66. data/lib/test_server/locales/en.yml +55 -2
  67. data/lib/test_server/permitted_params.rb +107 -0
  68. data/lib/test_server/version.rb +1 -1
  69. data/lib/test_server/web_helper.rb +7 -31
  70. data/log/.keep +0 -0
  71. data/log/development.log +0 -0
  72. data/log/test.log +1 -0
  73. data/public/404.html +67 -0
  74. data/public/422.html +67 -0
  75. data/public/500.html +66 -0
  76. data/public/favicon.ico +0 -0
  77. data/public/robots.txt +5 -0
  78. data/public/static/plain.html +11 -0
  79. data/script/bundle +3 -0
  80. data/script/rails +8 -0
  81. data/script/rake +8 -0
  82. data/script/spring +18 -0
  83. data/spec/controllers/errors_controller_spec.rb +12 -0
  84. data/spec/error_handler_spec.rb +42 -9
  85. data/spec/features/dashboard_spec.rb +35 -0
  86. data/spec/features/fetch_data_via_javascript_spec.rb +14 -14
  87. data/spec/features/fetch_test_data_plain_spec.rb +11 -29
  88. data/spec/features/fetch_test_data_via_streaming_spec.rb +6 -6
  89. data/spec/features/helper_spec.rb +23 -31
  90. data/spec/helpers/errors_helper_spec.rb +15 -0
  91. data/spec/permitted_params_spec.rb +64 -0
  92. data/spec/spec_helper.rb +44 -3
  93. data/spec/support/capybara.rb +4 -0
  94. data/spec/support/rails.rb +33 -0
  95. data/spec/views/errors/not_found.html.haml_spec.rb +5 -0
  96. data/test_server.gemspec +18 -17
  97. data/vendor/assets/components/open-sans/scss/_base.scss +5 -5
  98. data/vendor/assets/javascripts/.keep +0 -0
  99. data/vendor/assets/stylesheets/.keep +0 -0
  100. metadata +133 -116
  101. data/app/controllers/application_controller.rb +0 -76
  102. data/app/controllers/assets_controller.rb +0 -73
  103. data/app/controllers/javascript_controller.rb +0 -36
  104. data/app/controllers/streaming_controller.rb +0 -52
  105. data/app/controllers/string_controller.rb +0 -51
  106. data/app/views/layouts/application.haml +0 -19
data/lib/assets/.keep ADDED
File without changes
data/lib/tasks/.keep ADDED
File without changes
data/lib/test_server.rb CHANGED
@@ -1,25 +1,22 @@
1
+ #require 'sass'
2
+ #require 'haml'
3
+ #require 'rack/contrib/locale'
4
+ #require 'rack/contrib/nested_params'
5
+ #require 'rack/contrib/post_body_content_type_parser'
6
+ #require 'sprockets-helpers'
7
+ #require 'uglifier'
8
+ #require 'rack/protection'
9
+ #require 'rack/cors'
10
+ #require 'rails'
11
+
1
12
  require 'psych'
2
- require 'sass'
3
- require 'haml'
4
13
  require 'i18n'
5
14
  require 'i18n/backend/fallbacks'
6
- require 'rack/contrib/locale'
7
- require 'rack/contrib/nested_params'
8
- require 'rack/contrib/post_body_content_type_parser'
9
- require 'sprockets-helpers'
10
- require 'sinatra'
11
- require 'sinatra/param'
12
- require 'sinatra/json'
13
- require 'sinatra/streaming'
14
15
  require 'json'
15
- require 'uglifier'
16
- require 'rack/protection'
17
- require 'rack/cors'
18
- require 'thor'
19
16
  require 'base64'
17
+ require 'thor'
20
18
  require 'zlib'
21
19
  require 'digest/sha1'
22
- require 'padrino'
23
20
 
24
21
  require 'active_support/core_ext/kernel/reporting'
25
22
  require 'active_support/core_ext/object/blank'
@@ -35,6 +32,7 @@ require 'addressable/uri'
35
32
  require 'securerandom'
36
33
  require 'erb'
37
34
 
35
+ require 'test_server/permitted_params'
38
36
 
39
37
  require 'test_server/access_logger'
40
38
  require 'test_server/null_access_logger'
@@ -11,19 +11,19 @@ module TestServer
11
11
 
12
12
  private
13
13
 
14
- attr_reader :details_i18n, :summary_i18n, :exit_code
14
+ attr_reader :details_i18n, :summary_i18n
15
15
 
16
16
  public
17
17
 
18
- attr_reader :exception
19
- attr_accessor :original_message
20
- attr_accessor :backtrace
18
+ attr_reader :exception, :status_code, :exit_code
19
+ attr_accessor :original_message, :backtrace
21
20
 
22
21
  def initialize(options = {})
23
22
  @exception = options.fetch(:exception)
24
23
  @details_i18n = options.fetch(:details)
25
24
  @summary_i18n = options.fetch(:summary)
26
- @exit_code = options.fetch(:exit_code)
25
+ @exit_code = options.fetch(:exit_code, 1)
26
+ @status_code = options.fetch(:status_code, :internal_server_error)
27
27
  rescue KeyError => e
28
28
  raise ArgumentError, e.message
29
29
  end
@@ -93,17 +93,21 @@ module TestServer
93
93
  Kernel.exit exit_code
94
94
  end
95
95
 
96
- def to_json
96
+ def to_hash
97
97
  ErrorHandler.mutex.synchronize do
98
98
  @details ||= I18n.t(details_i18n)
99
99
  @summary ||= I18n.t(summary_i18n)
100
100
  end
101
101
 
102
- JSON.dump(
103
- error_summary: summary,
104
- error_details: details,
105
- result: :failure,
106
- )
102
+ {
103
+ error_summary: summary,
104
+ error_details: details,
105
+ result: :failure,
106
+ }
107
+ end
108
+
109
+ def to_json
110
+ JSON.dump(to_hash)
107
111
  end
108
112
  end
109
113
  end
@@ -1,11 +1,14 @@
1
1
  # encoding: utf-8
2
2
  module TestServer
3
3
  module ErrorMessages
4
+ # See http://futureshock-ed.com/2011/03/04/http-status-code-symbols-for-rails/
5
+ # for list of symbols for status codes
4
6
  ErrorHandler.create(
5
7
  exception: StandardError,
6
8
  summary: 'errors.default.summary',
7
9
  details: 'errors.default.details',
8
10
  exit_code: 99,
11
+ status_code: :internal_server_error,
9
12
  )
10
13
 
11
14
  ErrorHandler.create(
@@ -13,6 +16,7 @@ module TestServer
13
16
  details: 'errors.internal_error.details',
14
17
  summary: 'errors.internal_error.summary',
15
18
  exit_code: 1,
19
+ status_code: :internal_server_error,
16
20
  )
17
21
 
18
22
  ErrorHandler.create(
@@ -20,6 +24,7 @@ module TestServer
20
24
  details: 'errors.unreadable_config_file.details',
21
25
  summary: 'errors.unreadable_config_file.summary',
22
26
  exit_code: 2,
27
+ status_code: :internal_server_error,
23
28
  )
24
29
 
25
30
  ErrorHandler.create(
@@ -27,20 +32,22 @@ module TestServer
27
32
  details: 'errors.user_error.details',
28
33
  summary: 'errors.user_error.summary',
29
34
  exit_code: 3,
35
+ status_code: :internal_server_error,
30
36
  )
31
37
 
32
- ErrorHandler.create(
33
- exception: Sinatra::Param::InvalidParameterError,
34
- details: 'errors.invalid_parameter.details',
35
- summary: 'errors.invalid_parameter.summary',
36
- exit_code: 4,
37
- )
38
+ #ErrorHandler.create(
39
+ # exception: Sinatra::Param::InvalidParameterError,
40
+ # details: 'errors.invalid_parameter.details',
41
+ # summary: 'errors.invalid_parameter.summary',
42
+ # exit_code: 4,
43
+ #)
38
44
 
39
45
  ErrorHandler.create(
40
46
  exception: Exceptions::PidFileDoesNotExist,
41
47
  details: 'errors.invalid_proxy_pac.details',
42
48
  summary: 'errors.invalid_proxy_pac.summary',
43
49
  exit_code: 5,
50
+ status_code: :internal_server_error,
44
51
  )
45
52
 
46
53
  ErrorHandler.create(
@@ -48,6 +55,7 @@ module TestServer
48
55
  details: 'errors.invalid_url.details',
49
56
  summary: 'errors.invalid_url.summary',
50
57
  exit_code: 6,
58
+ status_code: :internal_server_error,
51
59
  )
52
60
 
53
61
  ErrorHandler.create(
@@ -55,6 +63,7 @@ module TestServer
55
63
  details: 'errors.invalid_listen_statement.details',
56
64
  summary: 'errors.invalid_listen_statement.summary',
57
65
  exit_code: 8,
66
+ status_code: :internal_server_error,
58
67
  )
59
68
 
60
69
  ErrorHandler.create(
@@ -62,6 +71,7 @@ module TestServer
62
71
  details: 'errors.invalid_access_log_path.details',
63
72
  summary: 'errors.invalid_access_log_path.summary',
64
73
  exit_code: 9,
74
+ status_code: :internal_server_error,
65
75
  )
66
76
  end
67
77
  end
@@ -35,5 +35,11 @@ module TestServer
35
35
 
36
36
  # raised if variable cannot be looked up
37
37
  class VariableUnknown < InternalError; end
38
+
39
+ # raised if developer misses to define controller in parameter list
40
+ class ControllerNotDefinedInParameterList < InternalError; end
41
+
42
+ # raised if developer misses to define action for controller in parameter list
43
+ class ActionNotDefinedInParameterList < InternalError; end
38
44
  end
39
45
  end
@@ -56,10 +56,63 @@ en:
56
56
  link: Home
57
57
  test:
58
58
  link: Tests
59
- javascript:
59
+ string:
60
+ title: String Tests
61
+ link: String
62
+ index:
63
+ title: Overview for streaming tests
64
+ link: Overview
65
+ sleep:
66
+ title: Sleeps for a "count" amount of time and sends back string
67
+ link: Sleep and Send
68
+ random:
69
+ title: Sends random data back
70
+ link: Random Data
71
+ plain:
72
+ title: Sends plain static string back
73
+ link: Plain Data
74
+ eicar:
75
+ title: Sends eicar test string back
76
+ link: Eicar Test File
77
+ streaming:
78
+ title: Streaming Tests
79
+ link: Streaming
80
+ index:
81
+ title: Overview for streaming tests
82
+ link: Overview
83
+ random:
84
+ title: Sends random data back
85
+ link: Random Data
86
+ plain:
87
+ title: Sends plain static string back
88
+ link: Plain Data
89
+ eicar:
90
+ title: Sends eicar test string back
91
+ link: Eicar Test File
92
+
93
+ dashboard:
94
+ title: Dashboard
95
+ link: Dashboard
96
+ show:
97
+ title: Dashboard
98
+ link: Dashboard
99
+ static:
100
+ link: Static
101
+ title: Static content
102
+ index:
103
+ title: Overview for static files
104
+ link: Overview
105
+ plain:
106
+ title: Plain static content
107
+ generator:
108
+ title: Generators
109
+ link: Generators
110
+ index:
111
+ title: Overview for Generators
112
+ link: Overview
60
113
  xhr:
114
+ title: Send requests via Javascript
61
115
  link: XHR
62
- title: 'Javascript Tests'
63
116
  fields: &fields
64
117
  url: URL
65
118
  count: Count
@@ -0,0 +1,107 @@
1
+ # encoding: utf-8
2
+ module TestServer
3
+ class PermittedParams
4
+ private
5
+
6
+ attr_reader :database
7
+
8
+ public
9
+
10
+ attr_reader :params
11
+
12
+ def initialize(params)
13
+ @params = params
14
+
15
+ @database = {
16
+ dashboard: {
17
+ show: [],
18
+ },
19
+ static: {
20
+ index: [],
21
+ },
22
+ streaming: {
23
+ plain: [:encodable, :streamable, :cachable, :countable],
24
+ random: [:encodable, :streamable, :cachable, :countable],
25
+ eicar: [:encodable, :streamable, :cachable],
26
+ index: [],
27
+ },
28
+ string: {
29
+ plain: [:encodable, :streamable, :cachable, :countable],
30
+ random: [:encodable, :streamable, :cachable, :countable],
31
+ sleep: [:encodable, :streamable, :cachable, :countable],
32
+ eicar: [:encodable, :streamable, :cachable],
33
+ index: [],
34
+ },
35
+ generator: {
36
+ xhr: [:generatable, :repeatable],
37
+ index: [],
38
+ },
39
+ }
40
+ end
41
+
42
+ def params_for_controller(name, action, defaults)
43
+ name = name.to_sym
44
+ action = action.to_sym
45
+
46
+ raise Exceptions::ControllerNotDefinedInParameterList unless database.key? name
47
+ raise Exceptions::ActionNotDefinedInParameterList unless database[name].key? action
48
+
49
+ generate_params(defaults, params_for(database[name][action]))
50
+ end
51
+
52
+ def known_params_for_controller(name, action)
53
+ name = name.to_sym
54
+ action = action.to_sym
55
+
56
+ raise Exceptions::ControllerNotDefinedInParameterList, JSON.dump(controller: name) unless database.key? name
57
+ raise Exceptions::ActionNotDefinedInParameterList, JSON.dump(action: action) unless database[name].key? action
58
+
59
+ params_for(database[name][action]).to_a.sort
60
+ end
61
+
62
+ private
63
+
64
+ def params_for(*roles)
65
+ roles = roles.flatten
66
+ attributes = Set.new
67
+
68
+ attributes = attributes + countable_params if roles.include? :countable
69
+ attributes = attributes + encodable_params if roles.include? :encodable
70
+ attributes = attributes + cachable_params if roles.include? :cachable
71
+ attributes = attributes + repeatable_params if roles.include? :repeatable
72
+ attributes = attributes + generatable_params if roles.include? :generatable
73
+
74
+ attributes
75
+ end
76
+
77
+ def generate_params(defaults, attributes)
78
+ params = self.params.permit(*attributes)
79
+ params.modify_values { |v| v.to_bool }
80
+ params.reverse_merge defaults if defaults
81
+ end
82
+
83
+ def generatable_params
84
+ [:count, :timeout, :url]
85
+ end
86
+
87
+ def repeatable_params
88
+ [:repeat]
89
+ end
90
+
91
+ def streamable_params
92
+ [:wait]
93
+ end
94
+
95
+ def encodable_params
96
+ [:base64, :base64_strict, :gzip]
97
+ end
98
+
99
+ def countable_params
100
+ [:count]
101
+ end
102
+
103
+ def cachable_params
104
+ [:expires]
105
+ end
106
+ end
107
+ end
@@ -1,4 +1,4 @@
1
1
  #main TestServer
2
2
  module TestServer
3
- VERSION = '0.2.4'
3
+ VERSION = '0.3.1'
4
4
  end
@@ -1,30 +1,14 @@
1
1
  # encoding: utf-8
2
2
  module TestServer
3
3
  module WebHelper
4
- def base_url
5
- mutex = Mutex.new
6
-
7
- mutex.synchronize do
8
- @base_url ||= "#{request.env['rack.url_scheme']}://#{request.env['HTTP_HOST']}"
9
- end
10
- end
11
-
12
- def h(text)
13
- Rack::Utils.escape_html(text)
14
- end
15
-
16
- def t(*args)
17
- I18n.t(*args)
18
- end
19
-
20
4
  def generate_string(count, string = "Plain Data\n")
21
- string * count
5
+ string * count.to_i
22
6
  end
23
7
 
24
8
  def generate_random_string(count)
25
9
  o = [('a'..'z'), ('A'..'Z'), (1..9), %w{° ^ ! " § $ % & / ( ) = ? * + ~ ` ´ ' # > < | @ ł € ¶ ŧ ← ↓ → ŋ đ ð ſ ð đ ŋ ħ “ „ ¢ « | » « ¢ „ “ ” µ · … – ĸ ¹ ² ³ ¼ ½ ¬ \{ [ ] \}}].map { |i| i.to_a }.flatten
26
10
 
27
- (0...count).map { o[rand(o.length)] }.join
11
+ (0...count.to_i).map { o[rand(o.length)] }.join
28
12
  end
29
13
 
30
14
  def generate_eicar
@@ -36,29 +20,21 @@ module TestServer
36
20
  '+', 'H', '*' ]
37
21
  end
38
22
 
39
- def configure_caching(params)
40
- options = []
41
-
23
+ def configure_caching
42
24
  if params.key? 'expires'
43
- options << :must_revalidate
44
- options << :no_cache
45
- options << { max_age: params[:expires] }
25
+ expires_in params[:expires].to_i, public: true, must_revalidate: true
46
26
  else
47
- options << :must_revalidate if params.key? 'must_revalidate'
48
- options << :no_cache if params.key? 'no_cache'
49
- options << { max_age: params[:max_age] } if params.key? 'max_age'
27
+ expires_now
50
28
  end
51
-
52
- cache_control(*options)
53
29
  end
54
30
 
55
- def encode(&block)
31
+ def encode(params, &block)
56
32
  encoders = []
57
33
  encoders << Encoders::Base64.new
58
34
  encoders << Encoders::Base64Strict.new
59
35
  encoders << Encoders::Gzip.new
60
36
 
61
- encoders_to_run = params.keys.map(&:to_sym) & encoders.collect { |e| e.name }
37
+ encoders_to_run = params.symbolize_keys.keep_if {|_,v| v.to_bool == true }.keys & encoders.collect { |e| e.name }
62
38
 
63
39
  if encoders_to_run.blank?
64
40
  real_encoders = [Encoders::Null.new]