agile-proxy 0.1.11 → 0.1.12

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 74ae4ece459f7aec91a77ac5daefe1b1978de480
4
- data.tar.gz: 1b1e68ecff0556340c41281a1f24faa3a6b75202
3
+ metadata.gz: 02e133024599ce6fd5e4fddbb5e033a946a2dc0b
4
+ data.tar.gz: 4e2ee23220437dbaaf7c0b5e77037ae5795cb7f6
5
5
  SHA512:
6
- metadata.gz: e604574ae397091d8909ad20981f4d4a03dac2fbc28c7885fb588a071234f6b6ab5be27aef4750158f0857d522742cac69add078f09dc4c783b7e647460152bc
7
- data.tar.gz: af0e99b04466f2c5120f552f8fa78e4753eae7273552fc4ca2d0a41cd8e5fd49e6c1f1686db4370c4b9989acb974d20d052228eeda12177c2089883292cab911
6
+ metadata.gz: e69dfa8694ca9c1263cb2c74aeb55bac639c14ddd378026e2b9ec159e8aba5f7a2f6d74e7c396b7f7b7c805b2a8524500ad8014237906bafe462e357325e5567
7
+ data.tar.gz: 596085914e190623edbb8613ee094c6b7001f753b325dd7aa103c93a649b91fd68c7a984d522ac66f35c8aaec69b88ceef34f430178aaf31c22a7eefa70e954a
data/.travis.yml CHANGED
@@ -6,3 +6,4 @@ rvm:
6
6
  script:
7
7
  - bundle exec rake db:migrate ENV=test
8
8
  - bundle exec rspec spec/unit
9
+ - bundle exec rspec spec/integration
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- agile-proxy (0.1.11)
4
+ agile-proxy (0.1.12)
5
5
  activerecord (~> 4.1.6)
6
6
  em-http-request (~> 1.1.2)
7
7
  em-synchrony (~> 1.0.3)
@@ -94,6 +94,7 @@ GEM
94
94
  equalizer (0.0.9)
95
95
  erubis (2.7.0)
96
96
  eventmachine (1.0.3)
97
+ eventmachine (1.0.3-x86-mingw32)
97
98
  eventmachine_httpserver (0.2.1)
98
99
  faker (1.2.0)
99
100
  i18n (~> 0.5)
@@ -219,6 +220,7 @@ GEM
219
220
  simplecov-html (0.8.0)
220
221
  slop (3.6.0)
221
222
  sqlite3 (1.3.10)
223
+ sqlite3 (1.3.10-x86-mingw32)
222
224
  thin (1.6.3)
223
225
  daemons (~> 1.0, >= 1.0.9)
224
226
  eventmachine (~> 1.0)
data/README.md CHANGED
@@ -103,4 +103,9 @@ http://public-app-1:password@localhost:3100
103
103
  ## History
104
104
  v0.1.8 Added support for plain text params parser - As DWR uses this (and maybe others)
105
105
  v0.1.9 Plain text params parser bug fixed - now handles params with a key and no value
106
- v0.1.10 Now using dependent: :destroy to tidy up better when all specs for an application are deleted (common occurence)
106
+ v0.1.10 Now using dependent: :destroy to tidy up better when all specs for an application are deleted (common occurence)
107
+ v0.1.11 Further improved database tidy up.
108
+ AGILE_PROXY_ENV can now set the environment at server startup
109
+ conditions handling improved in routing
110
+ v0.1.12 Added a 'Direct' server which is a simple HTTP server that response to the stubs - also allows
111
+ for static dirs to be hosted.
data/bin/agile_proxy CHANGED
@@ -1,118 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
- require 'agile_proxy'
3
- require 'thor'
4
- require 'rake'
5
- require 'active_record'
6
- require_relative '../db/seed'
7
- module AgileProxy
8
- include ActiveRecord::Tasks
9
- class Cli < Thor
10
- class << self
11
- def data_dir_base
12
- if RUBY_PLATFORM =~ /win32/
13
- ENV['APPDATA']
14
- elsif RUBY_PLATFORM =~ /linux/
15
- ENV['HOME']
16
- elsif RUBY_PLATFORM =~ /darwin/
17
- ENV['HOME']
18
- elsif RUBY_PLATFORM =~ /freebsd/
19
- ENV['HOME']
20
- else
21
- ENV['HOME']
22
- end
23
- end
24
-
25
- def data_dir
26
- if Dir.pwd == File.expand_path('..', File.dirname(__FILE__))
27
- Dir.pwd
28
- else
29
- File.join data_dir_base, '.agile_proxy'
30
- end
31
- end
32
-
33
- def environment
34
- ENV['AGILE_PROXY_ENV'] || (Dir.pwd == File.expand_path('..', File.dirname(__FILE__)) ? 'development' : 'production')
35
- end
36
- end
37
- package_name 'Http Flexible Proxy'
38
- desc 'start PROXY_PORT WEBSERVER_PORT', 'Runs the agile proxy'
39
- method_options data_dir: data_dir, database_config_file: 'db.yml', env: environment
40
- def start(proxy_port = nil, webserver_port = nil)
41
- ensure_database_config_file_exists database_config_file(options)
42
- puts "Data dir is #{options.data_dir}, environment is #{options.env}"
43
- setup_for_migrations(options)
44
- ::AgileProxy.configure do |config|
45
- config.proxy_port = proxy_port unless proxy_port.nil?
46
- config.webserver_port = webserver_port unless webserver_port.nil?
47
- config.environment = options.env
48
- config.database_config_file = database_config_file(options)
49
- end
50
- server = AgileProxy::Server.new
51
- update_db
52
- server.start
53
- end
54
-
55
- private
56
-
57
- def setup_for_migrations(options)
58
- ActiveRecord::Tasks::DatabaseTasks.db_dir = options.data_dir
59
- ActiveRecord::Tasks::DatabaseTasks.migrations_paths = [File.expand_path('../db/migrations', File.dirname(__FILE__))]
60
- ActiveRecord::Tasks::DatabaseTasks.env = options.env
61
- ActiveRecord::Tasks::DatabaseTasks.root = File.expand_path('..', __FILE__)
62
- ActiveRecord::Migrator.migrations_paths = ActiveRecord::Tasks::DatabaseTasks.migrations_paths
63
- end
64
- def run_migrations
65
- ActiveRecord::Migration.verbose = true
66
- ActiveRecord::Migrator.migrate(ActiveRecord::Migrator.migrations_paths, nil) do |migration|
67
- ENV["SCOPE"].blank? || (ENV["SCOPE"] == migration.scope)
68
- end
69
- end
70
-
71
- def seed_database
72
- Seed.load_seed
73
- end
74
-
75
- def server
76
- AgileProxy::Server.new
77
- end
78
-
79
- def update_db
80
- ActiveRecord::Tasks::DatabaseTasks.create_current
81
- run_migrations
82
- seed_database
83
- # Rake::Task['db:create'].invoke
84
- # Rake::Task['db:migrate'].invoke
85
-
86
-
87
- end
88
-
89
- def ensure_database_config_file_exists(fn)
90
- return if File.exist? fn
91
- FileUtils.mkdir_p File.dirname fn
92
- db = {
93
- :development => {
94
- adapter: 'sqlite3',
95
- database: File.join(File.dirname(fn), 'db', 'development.db')
96
- },
97
- :test => {
98
- adapter: 'sqlite3',
99
- database: File.join(File.dirname(fn), 'db', 'test.db')
100
- },
101
- :production => {
102
- adapter: 'sqlite3',
103
- database: File.join(File.dirname(fn), 'db', 'production.db')
104
- }
105
- }
106
- File.open(fn, 'w') {|f| f.write(db.to_yaml) }
107
- end
108
- def database_config_file(options)
109
- if File.exist? options.database_config_file
110
- options.database_config_file
111
- else
112
- File.join(options.data_dir, options.database_config_file)
113
- end
114
- end
115
- end
116
- end
2
+ require 'agile_proxy/cli'
117
3
  AgileProxy::Cli.start(ARGV)
118
4
  # AgileProxy::Server.new.start(false)
data/config.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  development:
2
2
  adapter: sqlite3
3
- database: ':memory:'
3
+ database: 'db/development.db'
4
4
  test:
5
5
  adapter: sqlite3
6
6
  database: 'db/test.db'
@@ -0,0 +1,116 @@
1
+ require 'agile_proxy'
2
+ require 'thor'
3
+ require 'active_record'
4
+ require_relative '../../db/seed'
5
+
6
+ module AgileProxy
7
+ include ActiveRecord::Tasks
8
+ class Cli < Thor
9
+ class << self
10
+ def data_dir_base
11
+ if RUBY_PLATFORM =~ /win32/
12
+ ENV['APPDATA']
13
+ elsif RUBY_PLATFORM =~ /linux/
14
+ ENV['HOME']
15
+ elsif RUBY_PLATFORM =~ /darwin/
16
+ ENV['HOME']
17
+ elsif RUBY_PLATFORM =~ /freebsd/
18
+ ENV['HOME']
19
+ else
20
+ ENV['HOME']
21
+ end
22
+ end
23
+
24
+ def data_dir
25
+ if Dir.pwd == File.expand_path('../..', File.dirname(__FILE__))
26
+ Dir.pwd
27
+ else
28
+ File.join data_dir_base, '.agile_proxy'
29
+ end
30
+ end
31
+
32
+ def environment
33
+ ENV['AGILE_PROXY_ENV'] || (Dir.pwd == File.expand_path('../..', File.dirname(__FILE__)) ? 'development' : 'production')
34
+ end
35
+ end
36
+ package_name 'Http Flexible Proxy'
37
+ desc 'start PROXY_PORT WEBSERVER_PORT', 'Runs the agile proxy'
38
+ method_options data_dir: data_dir, database_config_file: 'db.yml', env: environment
39
+ def start(proxy_port = nil, server_port = nil, webserver_port = nil)
40
+ ensure_database_config_file_exists database_config_file(options)
41
+ puts "Data dir is #{options.data_dir}, environment is #{options.env}"
42
+ setup_for_migrations(options)
43
+ ::AgileProxy.configure do |config|
44
+ config.proxy_port = proxy_port unless proxy_port.nil?
45
+ config.server_port = server_port unless server_port.nil?
46
+ config.webserver_port = webserver_port unless webserver_port.nil?
47
+ config.environment = options.env
48
+ config.database_config_file = database_config_file(options)
49
+ end
50
+ server = AgileProxy::Server.new
51
+ update_db
52
+ server.start
53
+ end
54
+
55
+ private
56
+
57
+ def setup_for_migrations(options)
58
+ ActiveRecord::Tasks::DatabaseTasks.db_dir = options.data_dir
59
+ ActiveRecord::Tasks::DatabaseTasks.migrations_paths = [File.expand_path('../../db/migrations', File.dirname(__FILE__))]
60
+ ActiveRecord::Tasks::DatabaseTasks.env = options.env
61
+ ActiveRecord::Tasks::DatabaseTasks.root = File.expand_path('../..', __FILE__)
62
+ ActiveRecord::Migrator.migrations_paths = ActiveRecord::Tasks::DatabaseTasks.migrations_paths
63
+ end
64
+ def run_migrations
65
+ ActiveRecord::Migration.verbose = true
66
+ ActiveRecord::Migrator.migrate(ActiveRecord::Migrator.migrations_paths, nil) do |migration|
67
+ ENV["SCOPE"].blank? || (ENV["SCOPE"] == migration.scope)
68
+ end
69
+ end
70
+
71
+ def seed_database
72
+ Seed.load_seed
73
+ end
74
+
75
+ def server
76
+ AgileProxy::Server.new
77
+ end
78
+
79
+ def update_db
80
+ ActiveRecord::Tasks::DatabaseTasks.create_current
81
+ run_migrations
82
+ seed_database
83
+ # Rake::Task['db:create'].invoke
84
+ # Rake::Task['db:migrate'].invoke
85
+
86
+
87
+ end
88
+
89
+ def ensure_database_config_file_exists(fn)
90
+ return if File.exist? fn
91
+ FileUtils.mkdir_p File.dirname fn
92
+ db = {
93
+ :development => {
94
+ adapter: 'sqlite3',
95
+ database: File.join(File.dirname(fn), 'db', 'development.db')
96
+ },
97
+ :test => {
98
+ adapter: 'sqlite3',
99
+ database: File.join(File.dirname(fn), 'db', 'test.db')
100
+ },
101
+ :production => {
102
+ adapter: 'sqlite3',
103
+ database: File.join(File.dirname(fn), 'db', 'production.db')
104
+ }
105
+ }
106
+ File.open(fn, 'w') {|f| f.write(db.to_yaml) }
107
+ end
108
+ def database_config_file(options)
109
+ if File.exist? options.database_config_file
110
+ options.database_config_file
111
+ else
112
+ File.join(options.data_dir, options.database_config_file)
113
+ end
114
+ end
115
+ end
116
+ end
@@ -12,7 +12,7 @@ module AgileProxy
12
12
  :persist_cache, :ignore_cache_port, :non_successful_cache_disabled, :non_successful_error_level,
13
13
  :non_whitelisted_requests_disabled, :cache_path, :proxy_port, :proxied_request_inactivity_timeout,
14
14
  :proxied_request_connect_timeout, :dynamic_jsonp, :dynamic_jsonp_keys,
15
- :webserver_host, :webserver_port, :database_config_file, :environment
15
+ :webserver_host, :webserver_port, :server_host, :server_port, :database_config_file, :environment
16
16
 
17
17
  def initialize
18
18
  @logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
@@ -39,6 +39,8 @@ module AgileProxy
39
39
  @proxied_request_connect_timeout = 5
40
40
  @webserver_port = 3020
41
41
  @webserver_host = 'localhost'
42
+ @server_port = 3030
43
+ @server_host = 'localhost'
42
44
  @database_config_file = File.join(File.dirname(__FILE__), '..', '..', 'config.yml')
43
45
  @environment = ENV['AGILE_PROXY_ENV']
44
46
  end
@@ -77,7 +77,12 @@ module AgileProxy
77
77
  end
78
78
 
79
79
  def collection(username, password)
80
- Application.where(username: username, password: password).first.request_specs
80
+ #An empty string and NULL are the same thing here. The UI has no way of sending NULL when creating an application
81
+ if (username.nil? && password.nil?)
82
+ Application.where('(username = ? OR username IS NULL) AND (password = ? OR password IS NULL)', '', '').first.request_specs
83
+ else
84
+ Application.where(username: username, password: password).first.request_specs
85
+ end
81
86
  end
82
87
 
83
88
  def short_list(username, password, _method, url)
@@ -122,6 +127,8 @@ module AgileProxy
122
127
 
123
128
  def call(env)
124
129
  request = ActionDispatch::Request.new(env)
130
+ request.params #Might seem odd, but action dispatch request is a bit naughty and adds the appropriate
131
+ # bits to ENV during access to this getter when used for the first time
125
132
  env['action_dispatch.request.parameters'].merge!(
126
133
  env['action_dispatch.request.request_parameters']
127
134
  ) unless request.content_length.zero?
@@ -8,6 +8,7 @@ require 'grape'
8
8
  require 'agile_proxy/api/root'
9
9
  require 'agile_proxy/servers/api'
10
10
  require 'agile_proxy/servers/request_spec'
11
+ require 'agile_proxy/servers/request_spec_direct'
11
12
  require 'forwardable'
12
13
  module AgileProxy
13
14
  #
@@ -44,6 +45,12 @@ module AgileProxy
44
45
  "http://#{webserver_host}:#{webserver_port}"
45
46
  end
46
47
 
48
+ # The url that the direct web server can be accessed from
49
+ # @return [String] The URL
50
+ def server_url
51
+ "http://#{server_host}:#{server_port}"
52
+ end
53
+
47
54
  # The host that the proxy server is running on
48
55
  # @return [String] The host
49
56
  def host
@@ -68,6 +75,18 @@ module AgileProxy
68
75
  AgileProxy.config.webserver_port
69
76
  end
70
77
 
78
+ # The host that the direct server is running on
79
+ # @return [String] The host
80
+ def server_host
81
+ AgileProxy.config.server_host
82
+ end
83
+
84
+ # The port that the direct server is running on
85
+ # @return [String] The port
86
+ def server_port
87
+ AgileProxy.config.server_port
88
+ end
89
+
71
90
  protected
72
91
 
73
92
  def main_loop
@@ -77,8 +96,9 @@ module AgileProxy
77
96
  puts e.backtrace.join("\n")
78
97
  end
79
98
  AgileProxy::Servers::Api.start(webserver_host, webserver_port)
99
+ AgileProxy::Servers::RequestSpecDirect.start(server_host, server_port)
80
100
  @request_spec_server = AgileProxy::Servers::RequestSpec.start
81
- AgileProxy.log(:info, "agile-proxy: Proxy listening on #{url} and webserver listening on #{webserver_url}")
101
+ AgileProxy.log(:info, "agile-proxy: Proxy listening on #{url}, API webserver listening on #{webserver_url} and Direct webserver listening on #{server_url}")
82
102
  end
83
103
  end
84
104
  end
@@ -0,0 +1,39 @@
1
+ require 'rack'
2
+ require 'thin'
3
+
4
+ module AgileProxy
5
+ module Servers
6
+ #
7
+ # The API Server
8
+ #
9
+ # This server is a RACK server responsible for providing access to the system
10
+ # using REST requests.
11
+ # This allows remote programming of the proxy using either a client adapter or the built in user interface
12
+ module RequestSpecDirect
13
+ ROOT = File.expand_path '../../../', File.dirname(__FILE__)
14
+ class << self
15
+ #
16
+ # Starts the server on the given host and port
17
+ # @param server_host [String] The host for the server to run on
18
+ # @param server_port [Integer] The port for the server to run on
19
+ def start(server_host, server_port, static_dirs = [])
20
+ # The sinatra web server
21
+ dispatch = Rack::Builder.app do
22
+ use Rack::Static, root: File.join(ROOT, 'assets'), urls: static_dirs, index: 'index.html' unless static_dirs.empty?
23
+ map '/' do
24
+ run ::AgileProxy::StubHandler.new
25
+ end
26
+ end
27
+ # Start the web server.
28
+ ::Rack::Server.start(
29
+ app: dispatch,
30
+ server: 'thin',
31
+ Host: server_host,
32
+ Port: server_port,
33
+ signals: false
34
+ )
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -2,5 +2,5 @@
2
2
  #
3
3
  # The Agile Proxy module is a common namespace for all classes / sub modules.
4
4
  module AgileProxy
5
- VERSION = '0.1.11'
5
+ VERSION = '0.1.12'
6
6
  end
@@ -1,39 +1,46 @@
1
+ require 'rest_client'
1
2
  module AgileProxy
2
3
  module Test
3
4
  module Integration
4
5
  # A helper for 'request spec' integration tests
5
6
  module RequestSpecHelper
6
7
  def load_small_set_of_request_specs(options = {})
7
- let(:recordings_resource) { RestClient::Resource.new "http://localhost:3020/api/v1/users/1/applications/#{@recording_application_id}/recordings", headers: { content_type: 'application/json' } }
8
+ let(:recordings_resource) { RestClient::Resource.new "http://localhost:#{api_port}/api/v1/users/1/applications/#{@recording_application_id}/recordings", headers: { content_type: 'application/json' } }
8
9
  before :context do
9
10
 
10
11
  def configure_applications
11
12
  application_resource.delete # Delete all applications
12
13
  @non_recording_application_id = JSON.parse(application_resource.post user_id: 1, name: 'Non recording app', username: 'anonymous', password: 'password')['id']
13
14
  @recording_application_id = JSON.parse(application_resource.post user_id: 1, name: 'Recording app', username: 'recording', password: 'password', record_requests: true)['id']
15
+ @direct_application_id = JSON.parse(application_resource.post user_id: 1, name: 'Direct app', username: nil, password: nil, record_requests: false)['id']
14
16
  end
15
17
 
16
18
  def application_resource
17
- @__application_resource ||= RestClient::Resource.new 'http://localhost:3020/api/v1/users/1/applications', headers: { content_type: 'application/json' }
19
+ @__application_resource ||= RestClient::Resource.new "http://localhost:#{api_port}/api/v1/users/1/applications", headers: { content_type: 'application/json' }
18
20
  end
19
21
 
20
22
  def create_request_spec(attrs)
21
23
  non_recording_resource.post ActiveSupport::JSON.encode attrs
22
24
  recording_resource.post ActiveSupport::JSON.encode attrs
25
+ direct_resource.post ActiveSupport::JSON.encode attrs
23
26
  end
24
27
 
25
28
  def non_recording_resource
26
- @__non_recording_resource ||= RestClient::Resource.new "http://localhost:3020/api/v1/users/1/applications/#{@non_recording_application_id}/request_specs", headers: { content_type: 'application/json' }
29
+ @__non_recording_resource ||= RestClient::Resource.new "http://localhost:#{api_port}/api/v1/users/1/applications/#{@non_recording_application_id}/request_specs", headers: { content_type: 'application/json' }
27
30
  end
28
31
 
29
32
  def recording_resource
30
- @__recording_resource ||= RestClient::Resource.new "http://localhost:3020/api/v1/users/1/applications/#{@recording_application_id}/request_specs", headers: { content_type: 'application/json' }
33
+ @__recording_resource ||= RestClient::Resource.new "http://localhost:#{api_port}/api/v1/users/1/applications/#{@recording_application_id}/request_specs", headers: { content_type: 'application/json' }
34
+ end
35
+
36
+ def direct_resource
37
+ @__direct_resource ||= RestClient::Resource.new "http://localhost:#{api_port}/api/v1/users/1/applications/#{@direct_application_id}/request_specs", headers: { content_type: 'application/json' }
31
38
  end
32
39
 
33
40
  # Delete all first
34
41
  configure_applications
35
42
  # Now, add some stubs via the REST interface
36
- [@http_url, @https_url].each do |url|
43
+ [@http_url, @https_url, @http_url_no_proxy, @https_url_no_proxy].each do |url|
37
44
  create_request_spec url: "#{url}/index.html", response: { content_type: 'text/html', content: '<html><body>This Is An Older Mock</body></html>' } #This is intentional - the system should always use the latest
38
45
  create_request_spec url: "#{url}/index.html", response: { content_type: 'text/html', content: '<html><body>Mocked Content</body></html>' }
39
46
  create_request_spec url: "#{url}/api/forums", response: { content_type: 'application/json', content: JSON.pretty_generate(forums: [], total: 0) }
@@ -339,7 +339,7 @@ shared_examples_for 'a cache' do
339
339
  end.to_not change { r.body }
340
340
  end
341
341
  end
342
- describe AgileProxy::Server do
342
+ describe AgileProxy::Server, :type => :integration do
343
343
  extend AgileProxy::Test::Integration::RequestSpecHelper
344
344
  describe 'Without recording' do
345
345
  load_small_set_of_request_specs
@@ -347,12 +347,17 @@ describe AgileProxy::Server do
347
347
  # Adding non-valid Faraday options throw an error: https://github.com/arsduo/koala/pull/311
348
348
  # Valid options: :request, :proxy, :ssl, :builder, :url, :parallel_manager, :params, :headers, :builder_class
349
349
  faraday_options = {
350
- proxy: { uri: 'http://anonymous:password@localhost:3100' },
351
- request: { timeout: 10.0 }
350
+ request: {timeout: 10.0}
352
351
  }
353
- @http = Faraday.new @http_url, faraday_options
354
- @https = Faraday.new @https_url, faraday_options.merge(ssl: { verify: false })
355
- @http_error = Faraday.new @error_url, faraday_options
352
+ faraday_options_with_proxy = faraday_options.merge({
353
+ proxy: { uri: "http://anonymous:password@localhost:#{proxy_port}" }
354
+ })
355
+ @http = Faraday.new @http_url, faraday_options_with_proxy
356
+ @https = Faraday.new @https_url, faraday_options_with_proxy.merge(ssl: { verify: false })
357
+ @http_no_proxy = Faraday.new @http_url_no_proxy, faraday_options
358
+ @https_no_proxy = Faraday.new @https_url_no_proxy, faraday_options.merge(ssl: { verify: false })
359
+ @http_error = Faraday.new @error_url, faraday_options_with_proxy
360
+ @http_error_no_proxy = Faraday.new @error_url, faraday_options_with_proxy
356
361
  end
357
362
  context 'proxying' do
358
363
  context 'HTTP' do
@@ -365,18 +370,27 @@ describe AgileProxy::Server do
365
370
  end
366
371
  end
367
372
  context 'stubbing' do
368
- context 'HTTP' do
369
- let!(:url) { @http_url }
370
- let!(:http) { @http }
371
- it_should_behave_like 'a request stub'
372
- end
373
+ context 'In Proxy Mode' do
374
+ context 'HTTP' do
375
+ let!(:url) { @http_url }
376
+ let!(:http) { @http }
377
+ it_should_behave_like 'a request stub'
378
+ end
373
379
 
374
- context 'HTTPS' do
375
- let!(:url) { @https_url }
376
- let!(:http) { @https }
377
- it_should_behave_like 'a request stub'
380
+ context 'HTTPS' do
381
+ let!(:url) { @https_url }
382
+ let!(:http) { @https }
383
+ it_should_behave_like 'a request stub'
384
+ end
385
+ end
386
+ #Server mode only supports http - no real point for https at the moment
387
+ context 'In Server Mode' do
388
+ context 'HTTP' do
389
+ let!(:url) { @http_url_no_proxy }
390
+ let!(:http) { @http_no_proxy }
391
+ it_should_behave_like 'a request stub'
392
+ end
378
393
  end
379
-
380
394
  end
381
395
  end
382
396
  describe 'With recording' do
@@ -385,7 +399,7 @@ describe AgileProxy::Server do
385
399
  # Adding non-valid Faraday options throw an error: https://github.com/arsduo/koala/pull/311
386
400
  # Valid options: :request, :proxy, :ssl, :builder, :url, :parallel_manager, :params, :headers, :builder_class
387
401
  faraday_options = {
388
- proxy: { uri: 'http://recording:password@localhost:3100' },
402
+ proxy: { uri: 'http://recording:password@localhost:3101' },
389
403
  request: { timeout: 10.0 }
390
404
  }
391
405
 
@@ -1,5 +1,4 @@
1
1
  require 'require_all'
2
- require 'airborne'
3
2
 
4
3
  require 'agile_proxy'
5
4
  require_all 'spec/support/**/*.rb'
@@ -7,12 +6,10 @@ require_all 'lib/agile_proxy/model'
7
6
  require_all 'spec/integration/helpers'
8
7
  require 'faker'
9
8
  RSpec.configure do |config|
10
- include AgileProxy::TestServer
11
- config.before :all do
9
+ config.include AgileProxy::TestServer, :type => :integration
10
+ config.before :all, :type => :integration do
12
11
  start_test_servers
12
+ start_proxy_server
13
13
  end
14
14
 
15
15
  end
16
- Airborne.configure do |config|
17
- config.base_url = 'http://localhost:3020'
18
- end
@@ -1,6 +1,7 @@
1
1
  require 'eventmachine'
2
2
  require 'thin'
3
3
  require 'faraday'
4
+ require 'agile_proxy/cli'
4
5
 
5
6
  module Thin
6
7
  module Backends
@@ -18,6 +19,15 @@ module AgileProxy
18
19
  def initialize
19
20
  Thin::Logging.silent = true
20
21
  end
22
+ def proxy_port
23
+ 3101
24
+ end
25
+ def api_port
26
+ 3021
27
+ end
28
+ def server_port
29
+ 3022
30
+ end
21
31
 
22
32
  def start_test_servers
23
33
  q = Queue.new
@@ -40,6 +50,15 @@ module AgileProxy
40
50
  @http_url = "http://localhost:#{q.pop}"
41
51
  @https_url = "https://localhost:#{q.pop}"
42
52
  @error_url = "http://localhost:#{q.pop}"
53
+ @http_url_no_proxy = "http://localhost:#{server_port}"
54
+ @https_url_no_proxy = "https://localhost:#{server_port}"
55
+ end
56
+
57
+ def start_proxy_server
58
+ Thread.new do
59
+ cli = Cli.start(['start', proxy_port.to_s, server_port.to_s, api_port.to_s, '--env', 'test'])
60
+ end
61
+ sleep 1
43
62
  end
44
63
 
45
64
  def echo_app_setup(response_code = 200)
@@ -92,6 +92,7 @@ describe AgileProxy::StubHandler do
92
92
  it 'Should match with a post on the same domain but not with a get or a post on a different domain' do
93
93
  expect(handler.call(request_for(method: 'POST', url: 'http://example.com').env)).to eql([200, {}, ''])
94
94
  expect(handler.call(request_for(method: 'POST', url: 'http://example.com/').env)).to eql([200, {}, ''])
95
+ expect(handler.call(request_for(method: 'POST', url: 'http://example.com/', headers: {'Content-Type' => 'text/plain'}, body: "a=1\nb=2\nc=3").env)).to eql([200, {}, ''])
95
96
  expect(handler.call(request_for(url: 'http://example.com/').env)).to eql route_not_found_response
96
97
  expect(handler.call(request_for(method: 'POST', url: 'http://subdomain.example.com/').env)).to eql route_not_found_response
97
98
  end
@@ -12,6 +12,7 @@ describe AgileProxy::Server do
12
12
  end
13
13
  end
14
14
  let(:request_spec_server_class) { Class.new }
15
+ let(:request_spec_direct_server_class) { Class.new }
15
16
  let(:api_server_class) { Class.new }
16
17
  let(:em_class) { Class.new }
17
18
  let(:socket_class) { Class.new }
@@ -20,6 +21,7 @@ describe AgileProxy::Server do
20
21
  stub_const('::EM', em_class)
21
22
  stub_const('AgileProxy::Servers::Api', api_server_class)
22
23
  stub_const('AgileProxy::Servers::RequestSpec', request_spec_server_class)
24
+ stub_const('AgileProxy::Servers::RequestSpecDirect', request_spec_direct_server_class)
23
25
  end
24
26
  context 'Initialization' do
25
27
  context 'In test environment' do
@@ -64,6 +66,7 @@ describe AgileProxy::Server do
64
66
  inner_loop = blk
65
67
  end
66
68
  expect(request_spec_server_class).to receive(:start).and_return request_spec_server_class.new
69
+ expect(request_spec_direct_server_class).to receive(:start).and_return request_spec_direct_server_class.new
67
70
  subject.start
68
71
  inner_loop.call
69
72
  end
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+ describe AgileProxy::Servers::RequestSpecDirect do
3
+ let(:subject) { AgileProxy::Servers::RequestSpecDirect }
4
+ let(:rack_builder_class) { Class.new }
5
+ let(:rack_server_class) { Class.new }
6
+ let(:rack_static_class) { Class.new }
7
+ let(:stub_handler_class) { Class.new }
8
+ before :each do
9
+ stub_const('Rack::Builder', rack_builder_class)
10
+ stub_const('Rack::Static', rack_static_class)
11
+ stub_const('Rack::Server', rack_server_class)
12
+ stub_const('AgileProxy::StubHandler', stub_handler_class)
13
+ end
14
+ it 'Should start a rack server with a static handler when the start method is called' do
15
+ builder_block = nil
16
+ expect(rack_builder_class).to receive(:app) do |&blk|
17
+ builder_block = blk
18
+ rack_builder_class.new.instance_eval(&blk)
19
+ end
20
+ expect_any_instance_of(rack_builder_class).to receive(:use).with(rack_static_class, root: instance_of(String), urls: ['/ui', '/images'], index: 'index.html')
21
+ expect_any_instance_of(rack_builder_class).to receive(:map) do |_instance, path, &blk|
22
+ expect(path).to eql '/'
23
+ expect_any_instance_of(rack_builder_class).to receive(:run).with(kind_of(stub_handler_class))
24
+ rack_builder_class.new.instance_eval(&blk)
25
+
26
+ end
27
+ expect(rack_server_class).to receive(:start)
28
+ subject.start('localhost', '3030', ['/ui', '/images'])
29
+
30
+ end
31
+ it 'Should start a rack server with no static handler if the start method is called with 2 params' do
32
+ builder_block = nil
33
+ expect(rack_builder_class).to receive(:app) do |&blk|
34
+ builder_block = blk
35
+ rack_builder_class.new.instance_eval(&blk)
36
+ end
37
+ expect_any_instance_of(rack_builder_class).not_to receive(:use)
38
+ expect_any_instance_of(rack_builder_class).to receive(:map) do |_instance, path, &blk|
39
+ expect(path).to eql '/'
40
+ expect_any_instance_of(rack_builder_class).to receive(:run).with(kind_of(stub_handler_class))
41
+ rack_builder_class.new.instance_eval(&blk)
42
+ end
43
+ expect(rack_server_class).to receive(:start)
44
+ subject.start('localhost', '3030')
45
+
46
+ end
47
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: agile-proxy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.11
4
+ version: 0.1.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gary Taylor
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-10 00:00:00.000000000 Z
11
+ date: 2014-12-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -2132,6 +2132,7 @@ files:
2132
2132
  - lib/agile_proxy/api/recordings.rb
2133
2133
  - lib/agile_proxy/api/request_specs.rb
2134
2134
  - lib/agile_proxy/api/root.rb
2135
+ - lib/agile_proxy/cli.rb
2135
2136
  - lib/agile_proxy/config.rb
2136
2137
  - lib/agile_proxy/handlers/handler.rb
2137
2138
  - lib/agile_proxy/handlers/proxy_handler.rb
@@ -2150,6 +2151,7 @@ files:
2150
2151
  - lib/agile_proxy/server.rb
2151
2152
  - lib/agile_proxy/servers/api.rb
2152
2153
  - lib/agile_proxy/servers/request_spec.rb
2154
+ - lib/agile_proxy/servers/request_spec_direct.rb
2153
2155
  - lib/agile_proxy/version.rb
2154
2156
  - load_proxy.js
2155
2157
  - log/.gitkeep
@@ -2174,6 +2176,7 @@ files:
2174
2176
  - spec/unit/agile_proxy/model/response_spec.rb
2175
2177
  - spec/unit/agile_proxy/server_spec.rb
2176
2178
  - spec/unit/agile_proxy/servers/api_spec.rb
2179
+ - spec/unit/agile_proxy/servers/request_spec_direct_spec.rb
2177
2180
  - spec/unit/agile_proxy/servers/request_spec_spec.rb
2178
2181
  homepage: https://github.com/garytaylor/agileproxy
2179
2182
  licenses: []
@@ -2221,5 +2224,6 @@ test_files:
2221
2224
  - spec/unit/agile_proxy/model/response_spec.rb
2222
2225
  - spec/unit/agile_proxy/server_spec.rb
2223
2226
  - spec/unit/agile_proxy/servers/api_spec.rb
2227
+ - spec/unit/agile_proxy/servers/request_spec_direct_spec.rb
2224
2228
  - spec/unit/agile_proxy/servers/request_spec_spec.rb
2225
2229
  has_rdoc: