proxy_tester 0.0.1 → 0.0.2

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 (49) hide show
  1. data/Gemfile +2 -0
  2. data/Gemfile.lock +18 -1
  3. data/README.md +88 -4
  4. data/bin/proxy_tester +11 -0
  5. data/config.yaml +0 -0
  6. data/features/.keep +0 -0
  7. data/features/add_test_case.feature +41 -0
  8. data/features/step_definitions.rb +30 -0
  9. data/features/support/debugging.rb +3 -0
  10. data/features/support/env.rb +12 -0
  11. data/features/support/environment.rb +22 -0
  12. data/features/support/filesystem.rb +19 -0
  13. data/lib/proxy_tester.rb +11 -1
  14. data/lib/proxy_tester/actions/add_test_case.rb +40 -0
  15. data/lib/proxy_tester/actions/clear_environment.rb +21 -0
  16. data/lib/proxy_tester/actions/fetch_urls.rb +94 -0
  17. data/lib/proxy_tester/actions/handle_error.rb +10 -6
  18. data/lib/proxy_tester/capybara_proxy.rb +1 -1
  19. data/lib/proxy_tester/cli/main.rb +10 -3
  20. data/lib/proxy_tester/cli/test.rb +79 -0
  21. data/lib/proxy_tester/config.rb +1 -1
  22. data/lib/proxy_tester/error_handler.rb +16 -7
  23. data/lib/proxy_tester/error_messages.rb +45 -3
  24. data/lib/proxy_tester/exceptions.rb +31 -2
  25. data/lib/proxy_tester/git_repository.rb +6 -7
  26. data/lib/proxy_tester/http_proxy.rb +48 -0
  27. data/lib/proxy_tester/locales/en.yml +18 -0
  28. data/lib/proxy_tester/main.rb +1 -1
  29. data/lib/proxy_tester/models/user.rb +2 -2
  30. data/lib/proxy_tester/remote_repository.rb +55 -0
  31. data/lib/proxy_tester/reporters/fetch_urls.rb +34 -0
  32. data/lib/proxy_tester/version.rb +2 -1
  33. data/proxy_tester.gemspec +2 -0
  34. data/script/ci +4 -0
  35. data/script/test_web +5 -2
  36. data/spec/actions/add_test_case_spec.rb +81 -0
  37. data/spec/actions/fetch_urls_spec.rb +52 -0
  38. data/spec/actions/handle_error_spec.rb +1 -1
  39. data/spec/capybara_proxy_spec.rb +1 -1
  40. data/spec/git_repository_spec.rb +22 -0
  41. data/spec/http_proxy_spec.rb +47 -0
  42. data/spec/remote_repository_spec.rb +103 -0
  43. data/spec/reporters/fetch_urls_spec.rb +58 -0
  44. data/spec/support/filesystem.rb +2 -0
  45. data/spec/support/reporting.rb +6 -0
  46. data/spec/user_spec.rb +10 -2
  47. metadata +66 -5
  48. data/lib/proxy_tester/actions/clone_repository.rb +0 -39
  49. data/spec/actions/clone_repository_spec.rb +0 -83
@@ -0,0 +1,103 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe RemoteRepository do
5
+ context '#source' do
6
+ it 'builds fqu for rugged' do
7
+ path = '/path/to/source_repo.git'
8
+ remote_repo = RemoteRepository.new(path)
9
+ expect(remote_repo.source).to eq('file://' + path)
10
+ end
11
+
12
+ it 'builds fqu for rugged from relative path' do
13
+ path = 'path/to/source_repo.git'
14
+
15
+ remote_repo = in_working_directory do
16
+ RemoteRepository.new(path)
17
+ end
18
+
19
+ expect(remote_repo.source).to eq('file://' + File.join(working_directory, path))
20
+ end
21
+
22
+ it 'builds fqu for rugged from relative path with dot' do
23
+ path = 'source_repo.git'
24
+
25
+ remote_repo = in_working_directory do
26
+ RemoteRepository.new(path)
27
+ end
28
+
29
+ expect(remote_repo.source).to eq('file://' + File.join(working_directory, path))
30
+ end
31
+
32
+ it 'handles http as well' do
33
+ path = 'http://host/path/to/source_repo.git'
34
+ remote_repo = RemoteRepository.new(path)
35
+ expect(remote_repo.source).to eq(path)
36
+ end
37
+
38
+ it 'handles git as well' do
39
+ path = 'git://host/path/to/source_repo.git'
40
+ remote_repo = RemoteRepository.new(path)
41
+ expect(remote_repo.source).to eq(path)
42
+ end
43
+
44
+ it 'handles git with useras well' do
45
+ path = 'git://user@host/path/to/source_repo.git'
46
+ remote_repo = RemoteRepository.new(path)
47
+ expect(remote_repo.source).to eq(path)
48
+ end
49
+
50
+ it 'handles ssh git as well' do
51
+ path = 'ssh://user@host:/opt/nwm-sec/www/repos-git/applications/test_server.git/'
52
+ remote_repo = RemoteRepository.new(path)
53
+ expect(remote_repo.source).to eq(path)
54
+ end
55
+
56
+ it 'handles ssh git as well without prefix' do
57
+ path = 'user@host:/opt/nwm-sec/www/repos-git/applications/test_server.git'
58
+ remote_repo = RemoteRepository.new(path)
59
+ expect(remote_repo.source).to eq(path)
60
+ end
61
+ end
62
+
63
+ context '#base' do
64
+ it 'handles http as well' do
65
+ path = 'http://host/path/to/source_repo.git'
66
+ remote_repo = RemoteRepository.new(path)
67
+ expect(remote_repo.base).to eq('source_repo')
68
+ end
69
+
70
+ it 'handles git as well' do
71
+ path = 'git://host/path/to/source_repo.git'
72
+ remote_repo = RemoteRepository.new(path)
73
+ expect(remote_repo.base).to eq('source_repo')
74
+ end
75
+
76
+ it 'handles git with useras well' do
77
+ path = 'git://user@host/path/to/source_repo.git'
78
+ remote_repo = RemoteRepository.new(path)
79
+ expect(remote_repo.base).to eq('source_repo')
80
+ end
81
+
82
+ it 'handles ssh git as well' do
83
+ path = 'ssh://user@host:/opt/nwm-sec/www/repos-git/applications/source_repo.git/'
84
+ remote_repo = RemoteRepository.new(path)
85
+ expect(remote_repo.base).to eq('source_repo')
86
+ end
87
+
88
+ it 'handles ssh git as well without prefix' do
89
+ path = 'user@host:/opt/nwm-sec/www/repos-git/applications/source_repo.git'
90
+ remote_repo = RemoteRepository.new(path)
91
+ expect(remote_repo.base).to eq('source_repo')
92
+ end
93
+ it 'extracts basename without .git' do
94
+ remote_repo = RemoteRepository.new('/path/to/source_repo.git')
95
+ expect(remote_repo.base).to eq('source_repo')
96
+ end
97
+
98
+ it 'resolves ~' do
99
+ remote_repo = RemoteRepository.new('~/source_repo.git')
100
+ expect(remote_repo.base).to eq('source_repo')
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,58 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Reporters::FetchUrls do
5
+ context '#initialize' do
6
+ it 'does not require any parameter' do
7
+ expect {
8
+ Reporters::FetchUrls.new
9
+ }.not_to raise_error
10
+ end
11
+
12
+ it 'accepts an io object' do
13
+ expect {
14
+ Reporters::FetchUrls.new(StringIO.new)
15
+ }.not_to raise_error
16
+ end
17
+
18
+ end
19
+
20
+ context '#data' do
21
+ let(:data) {
22
+ {
23
+ headers: {
24
+ "Date" => "Fri, 21 Mar 2014 09:49:09 GMT",
25
+ "Server" => "Apache",
26
+ "Location" => "http://www.sg-zertifikate.de/dwr/call/plainpoll/ReverseAjax.dwr",
27
+ "Content-Length" => "271",
28
+ "Content-Type" => "text/html; charset=iso-8859-1",
29
+ "Connection" => "close",
30
+ "Age" => "1"
31
+ },
32
+ status: 301,
33
+ url: 'http://www.sg-zertifikate.de/dwr/call/plainpoll/ReverseAjax.dwr',
34
+ proxy: 'proxy:3128',
35
+ }
36
+ }
37
+
38
+ it 'generates output' do
39
+ reporter = Reporters::FetchUrls.new
40
+
41
+ result = capture :stdout do
42
+ reporter.data(data)
43
+ end
44
+
45
+ expect(result).to match(/url\s+:/)
46
+ end
47
+
48
+ it 'uses io object' do
49
+ output = StringIO.new
50
+ reporter = Reporters::FetchUrls.new(output)
51
+
52
+ reporter.data(data)
53
+
54
+ expect(output.string).to match(/url\s+:/)
55
+ end
56
+ end
57
+
58
+ end
@@ -8,6 +8,8 @@ module ProxyTester
8
8
  def root_directory
9
9
  ::File.expand_path('../../../', __FILE__)
10
10
  end
11
+
12
+ alias_method :in_working_directory, :switch_to_working_directory
11
13
  end
12
14
  end
13
15
  end
@@ -1 +1,7 @@
1
1
  require 'active_support/core_ext/kernel/reporting'
2
+
3
+ RSpec.configure do |c|
4
+ c.before(:each) do
5
+ ProxyTester.ui_logger.level = :unknown
6
+ end
7
+ end
@@ -51,12 +51,20 @@ describe User do
51
51
  end
52
52
 
53
53
  context '#to_s' do
54
- it 'returns the user as textual representation' do
54
+ it 'returns the user as textual representation in cleartext' do
55
55
  user = create(:user,
56
56
  name: 'name',
57
57
  password: 'password',
58
58
  )
59
- expect(user.to_string).to eq('name:password')
59
+ expect(user.to_string(cleartext: true)).to eq('name:password')
60
+ end
61
+
62
+ it 'returns the user as textual representation without password' do
63
+ user = create(:user,
64
+ name: 'name',
65
+ password: 'password',
66
+ )
67
+ expect(user.to_string).to eq('name:****')
60
68
  end
61
69
  end
62
70
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: proxy_tester
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-03-20 00:00:00.000000000 Z
12
+ date: 2014-03-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -219,6 +219,38 @@ dependencies:
219
219
  - - ! '>='
220
220
  - !ruby/object:Gem::Version
221
221
  version: '0'
222
+ - !ruby/object:Gem::Dependency
223
+ name: excon
224
+ requirement: !ruby/object:Gem::Requirement
225
+ none: false
226
+ requirements:
227
+ - - ! '>='
228
+ - !ruby/object:Gem::Version
229
+ version: '0'
230
+ type: :runtime
231
+ prerelease: false
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ none: false
234
+ requirements:
235
+ - - ! '>='
236
+ - !ruby/object:Gem::Version
237
+ version: '0'
238
+ - !ruby/object:Gem::Dependency
239
+ name: highline
240
+ requirement: !ruby/object:Gem::Requirement
241
+ none: false
242
+ requirements:
243
+ - - ! '>='
244
+ - !ruby/object:Gem::Version
245
+ version: '0'
246
+ type: :runtime
247
+ prerelease: false
248
+ version_requirements: !ruby/object:Gem::Requirement
249
+ none: false
250
+ requirements:
251
+ - - ! '>='
252
+ - !ruby/object:Gem::Version
253
+ version: '0'
222
254
  description: Test proxies to be sure it works
223
255
  email:
224
256
  - dg1@vrnetze.de
@@ -238,7 +270,15 @@ files:
238
270
  - README.md
239
271
  - Rakefile
240
272
  - bin/proxy_tester
273
+ - config.yaml
241
274
  - db/migrate/20140314_create_environment.rb
275
+ - features/.keep
276
+ - features/add_test_case.feature
277
+ - features/step_definitions.rb
278
+ - features/support/debugging.rb
279
+ - features/support/env.rb
280
+ - features/support/environment.rb
281
+ - features/support/filesystem.rb
242
282
  - files/config.yaml
243
283
  - files/example-config.erb
244
284
  - files/example-spec_helper.rb.erb
@@ -247,16 +287,19 @@ files:
247
287
  - files/example-user_file.erb
248
288
  - lib/proxy_tester.rb
249
289
  - lib/proxy_tester/actions/add_examples_to_test_cases_directory.rb
250
- - lib/proxy_tester/actions/clone_repository.rb
290
+ - lib/proxy_tester/actions/add_test_case.rb
291
+ - lib/proxy_tester/actions/clear_environment.rb
251
292
  - lib/proxy_tester/actions/create_directory.rb
252
293
  - lib/proxy_tester/actions/create_file.rb
253
294
  - lib/proxy_tester/actions/create_output.rb
295
+ - lib/proxy_tester/actions/fetch_urls.rb
254
296
  - lib/proxy_tester/actions/handle_error.rb
255
297
  - lib/proxy_tester/actions/initialize_application.rb
256
298
  - lib/proxy_tester/actions/show_config.rb
257
299
  - lib/proxy_tester/capybara_proxy.rb
258
300
  - lib/proxy_tester/capybara_proxy_pac.rb
259
301
  - lib/proxy_tester/cli/main.rb
302
+ - lib/proxy_tester/cli/test.rb
260
303
  - lib/proxy_tester/config.rb
261
304
  - lib/proxy_tester/data.rb
262
305
  - lib/proxy_tester/database_session.rb
@@ -269,11 +312,14 @@ files:
269
312
  - lib/proxy_tester/git_null_file.rb
270
313
  - lib/proxy_tester/git_repository.rb
271
314
  - lib/proxy_tester/handle_error.rb
315
+ - lib/proxy_tester/http_proxy.rb
272
316
  - lib/proxy_tester/locales/en-rails.yml
273
317
  - lib/proxy_tester/locales/en.yml
274
318
  - lib/proxy_tester/main.rb
275
319
  - lib/proxy_tester/models/user.rb
276
320
  - lib/proxy_tester/pac_result.rb
321
+ - lib/proxy_tester/remote_repository.rb
322
+ - lib/proxy_tester/reporters/fetch_urls.rb
277
323
  - lib/proxy_tester/rspec/helper.rb
278
324
  - lib/proxy_tester/rspec_runner.rb
279
325
  - lib/proxy_tester/template_file.rb
@@ -290,10 +336,11 @@ files:
290
336
  - script/test_web
291
337
  - script/unit_test
292
338
  - spec/actions/add_examples_to_test_cases_directory_spec.rb
293
- - spec/actions/clone_repository_spec.rb
339
+ - spec/actions/add_test_case_spec.rb
294
340
  - spec/actions/create_directory_spec.rb
295
341
  - spec/actions/create_file_spec.rb
296
342
  - spec/actions/create_output_spec.rb
343
+ - spec/actions/fetch_urls_spec.rb
297
344
  - spec/actions/handle_error_spec.rb
298
345
  - spec/actions/initialize_application_spec.rb
299
346
  - spec/actions/show_config_spec.rb
@@ -308,9 +355,12 @@ files:
308
355
  - spec/features/check_ssl_sites_spec.rb
309
356
  - spec/git_file_spec.rb
310
357
  - spec/git_repository_spec.rb
358
+ - spec/http_proxy_spec.rb
311
359
  - spec/main_spec.rb
312
360
  - spec/pac_result_spec.rb
313
361
  - spec/proxy_tester_spec_helper_spec.rb
362
+ - spec/remote_repository_spec.rb
363
+ - spec/reporters/fetch_urls_spec.rb
314
364
  - spec/rspec_runner_spec.rb
315
365
  - spec/spec_helper.rb
316
366
  - spec/support/capybara.rb
@@ -355,11 +405,19 @@ signing_key:
355
405
  specification_version: 3
356
406
  summary: Test proxies
357
407
  test_files:
408
+ - features/.keep
409
+ - features/add_test_case.feature
410
+ - features/step_definitions.rb
411
+ - features/support/debugging.rb
412
+ - features/support/env.rb
413
+ - features/support/environment.rb
414
+ - features/support/filesystem.rb
358
415
  - spec/actions/add_examples_to_test_cases_directory_spec.rb
359
- - spec/actions/clone_repository_spec.rb
416
+ - spec/actions/add_test_case_spec.rb
360
417
  - spec/actions/create_directory_spec.rb
361
418
  - spec/actions/create_file_spec.rb
362
419
  - spec/actions/create_output_spec.rb
420
+ - spec/actions/fetch_urls_spec.rb
363
421
  - spec/actions/handle_error_spec.rb
364
422
  - spec/actions/initialize_application_spec.rb
365
423
  - spec/actions/show_config_spec.rb
@@ -374,9 +432,12 @@ test_files:
374
432
  - spec/features/check_ssl_sites_spec.rb
375
433
  - spec/git_file_spec.rb
376
434
  - spec/git_repository_spec.rb
435
+ - spec/http_proxy_spec.rb
377
436
  - spec/main_spec.rb
378
437
  - spec/pac_result_spec.rb
379
438
  - spec/proxy_tester_spec_helper_spec.rb
439
+ - spec/remote_repository_spec.rb
440
+ - spec/reporters/fetch_urls_spec.rb
380
441
  - spec/rspec_runner_spec.rb
381
442
  - spec/spec_helper.rb
382
443
  - spec/support/capybara.rb
@@ -1,39 +0,0 @@
1
- # encoding: utf-8
2
- module ProxyTester
3
- module Actions
4
- class CloneRepository
5
- private
6
-
7
- attr_reader :source, :destination, :options
8
-
9
- public
10
-
11
- def initialize(source, destination, options = {})
12
- @source = ::File.expand_path(source)
13
- @destination = ::File.expand_path(destination)
14
- @options = options
15
- end
16
-
17
- def run
18
- if need_to_run? || options[:force] == true
19
- ProxyTester.ui_logger.warn "Cloning repository from \"#{source}\" to \"#{destination}\"."
20
-
21
- if !need_to_run? && options[:force] == true
22
- ProxyTester.ui_logger.warn "This action does not support \":force\"-flag. Please move away the destination repository yourself."
23
- return
24
- end
25
-
26
- GitRepository.clone(source, destination, bare: options.fetch(:bare, false))
27
- else
28
- ProxyTester.ui_logger.warn "Destination \"#{destination}\" already exists. Do not create it again!"
29
- end
30
- end
31
-
32
- private
33
-
34
- def need_to_run?
35
- !::File.exists? destination
36
- end
37
- end
38
- end
39
- end
@@ -1,83 +0,0 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
-
4
- describe Actions::CloneRepository do
5
- let(:source_git_repo) { File.join(working_directory, 'git_repo.git') }
6
- let(:destination_git_repo) { File.join(working_directory, 'git_clone_repo') }
7
-
8
- context '#initialize' do
9
- it 'requires a source and a destination' do
10
- repo = GitRepository.create(source_git_repo)
11
- repo.add_content('file.txt', 'asdf1')
12
-
13
- expect {
14
- Actions::CloneRepository.new(source_git_repo, destination_git_repo)
15
- }.not_to raise_error
16
- end
17
- end
18
-
19
- context '#run' do
20
- it 'runs the action' do
21
- repo = GitRepository.create(source_git_repo)
22
- repo.add_content('file.txt', 'asdf1')
23
-
24
- action = Actions::CloneRepository.new(source_git_repo, destination_git_repo)
25
- silence(:stderr) do
26
- action.run
27
- end
28
-
29
- expect(path_exists?('git_clone_repo')).to be_true
30
- end
31
-
32
- it 'respects existing path' do
33
- repo = GitRepository.create(source_git_repo)
34
- repo.add_content('file.txt', 'asdf1')
35
-
36
- create_directory('git_clone_repo')
37
-
38
- action = Actions::CloneRepository.new(source_git_repo, destination_git_repo)
39
-
40
- result = capture(:stderr) do
41
- ProxyTester.ui_logger.level = :info
42
- action.run
43
- end
44
-
45
- expect(result).to include('already')
46
- end
47
-
48
- it 'does !!!not!!! remove existing path if forced to' do
49
- repo = GitRepository.create(source_git_repo)
50
- repo.add_content('file.txt', 'asdf1')
51
-
52
- create_directory('git_clone_repo')
53
-
54
- action = Actions::CloneRepository.new(source_git_repo, destination_git_repo, force: true)
55
-
56
- result = capture(:stderr) do
57
- ProxyTester.ui_logger.level = :info
58
- action.run
59
- end
60
-
61
- expect(result).to include('yourself')
62
- end
63
-
64
- it 'resolves ~' do
65
- source_git_repo = '~/source_repo.git'
66
- destination_git_repo = '~/destination_repo'
67
-
68
-
69
- action = with_environment 'HOME' => working_directory do
70
- repo = GitRepository.create(source_git_repo)
71
- repo.add_content('file.txt', 'asdf1')
72
-
73
- Actions::CloneRepository.new(source_git_repo, destination_git_repo)
74
- end
75
-
76
- silence(:stderr) do
77
- action.run
78
- end
79
-
80
- expect(path_exists?('destination_repo/file.txt')).to be_true
81
- end
82
- end
83
- end