local_pac 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -13,6 +13,7 @@ describe LocalStorage do
13
13
  it 'initializes storage' do
14
14
  file = double('File')
15
15
  allow(file).to receive(:name).and_return(:file1)
16
+ allow(file).to receive(:path).and_return('file1.pac')
16
17
 
17
18
  repo = double('GitRepository')
18
19
  expect(repo).to receive(:[]).and_return(file)
@@ -21,39 +22,44 @@ describe LocalStorage do
21
22
  file = storage.find('file1')
22
23
  expect(file.name).to eq(:file1)
23
24
  end
25
+ end
24
26
 
25
- context '#find' do
26
- it 'returns file if exists' do
27
- file = double('GitFile')
28
- allow(file).to receive(:name).and_return(:file1)
27
+ context '#find' do
28
+ it 'returns file if exists' do
29
+ file = double('File')
30
+ allow(file).to receive(:name).and_return(:file1)
31
+ allow(file).to receive(:path).and_return('file1.pac')
29
32
 
30
- repo = double('GitRepository')
31
- expect(repo).to receive(:[]).and_return(file)
33
+ repo = double('GitRepository')
34
+ expect(repo).to receive(:[]).and_return(file)
32
35
 
33
- storage = LocalStorage.new(repo)
34
- file = storage.find('file1')
35
- expect(file.name).to eq(:file1)
36
- end
36
+ storage = LocalStorage.new(repo)
37
+ file = storage.find('file1')
38
+ expect(file.name).to eq(:file1)
39
+ end
37
40
 
38
- it 'returns file for pac in subdir' do
39
- file = double('GitFile')
40
- allow(file).to receive(:name).and_return(:'dir::file1')
41
+ it 'returns file for pac in subdir' do
42
+ file = double('File')
43
+ allow(file).to receive(:name).and_return(:'dir::file1')
44
+ allow(file).to receive(:path).and_return('dir/file1.pac')
41
45
 
42
- repo = double('GitRepository')
43
- expect(repo).to receive(:[]).and_return(file)
46
+ repo = double('GitRepository')
47
+ expect(repo).to receive(:[]).and_return(file)
44
48
 
45
- storage = LocalStorage.new(repo)
46
- file = storage.find('dir/file1')
47
- expect(file.name).to eq(:'dir::file1')
48
- end
49
+ storage = LocalStorage.new(repo)
50
+ file = storage.find('dir/file1')
51
+ expect(file.name).to eq(:'dir::file1')
52
+ end
49
53
 
50
- it 'returns null file if does not exist' do
51
- repo = double('GitRepository')
52
- expect(repo).to receive(:[]).and_return(nil)
54
+ it 'returns null file if does not exist' do
55
+ file = double('File')
56
+ allow(file).to receive(:path).and_return(nil)
53
57
 
54
- storage = LocalStorage.new(repo)
55
- expect(storage.find('unexist')).to be_nil
56
- end
58
+ repo = double('GitRepository')
59
+ expect(repo).to receive(:[]).and_return(file)
60
+
61
+ storage = LocalStorage.new(repo)
62
+ expect(storage.find('unexist').path).to be_nil
57
63
  end
58
64
  end
59
65
  end
@@ -9,11 +9,18 @@ describe PacFileValidator do
9
9
  EOS
10
10
  end
11
11
 
12
- let(:invalid_pac_file) do <<-EOS.strip_heredoc
12
+ let(:invalid_pac_file1) do <<-EOS.strip_heredoc
13
13
  function FindProxyForURL(url, host) {
14
14
  EOS
15
15
  end
16
16
 
17
+ let(:invalid_pac_file2) do <<-EOS.strip_heredoc
18
+ function FindProxyForURL(url, host) {
19
+ asdf();
20
+ }
21
+ EOS
22
+ end
23
+
17
24
  it 'returns true if file is valid' do
18
25
  file = double('PacFile')
19
26
  expect(file).to receive(:content).and_return(valid_pac_file)
@@ -21,9 +28,16 @@ describe PacFileValidator do
21
28
  expect(validator.valid?(file)).to be_true
22
29
  end
23
30
 
24
- it 'returns true if file is invalid' do
31
+ it 'returns false if file produces parsing error' do
32
+ file = double('PacFile')
33
+ expect(file).to receive(:content).and_return(invalid_pac_file1)
34
+ validator = PacFileValidator.new
35
+ expect(validator.valid?(file)).to be_false
36
+ end
37
+
38
+ it 'returns false if file uses invalid function' do
25
39
  file = double('PacFile')
26
- expect(file).to receive(:content).and_return(invalid_pac_file)
40
+ expect(file).to receive(:content).and_return(invalid_pac_file2)
27
41
  validator = PacFileValidator.new
28
42
  expect(validator.valid?(file)).to be_false
29
43
  end
@@ -26,7 +26,9 @@ describe ProxyPac::PACEngine do
26
26
  parser = ProxyPac::PACEngine.new(file: file)
27
27
 
28
28
  expect do
29
- parser.find(Addressable::URI.parse('http://example.org'))
29
+ silence(:stderr) do
30
+ parser.find(Addressable::URI.parse('http://example.org'))
31
+ end
30
32
  end.to raise_error Exceptions::PacFileInvalid
31
33
  end
32
34
  end
data/spec/server_spec.rb CHANGED
@@ -18,55 +18,56 @@ describe Server do
18
18
  end
19
19
  end
20
20
 
21
- context '#start' do
22
- it 'starts the server' do
23
- create_file 'app.rb', <<-EOS.strip_heredoc
24
- require 'sinatra'
21
+ #context '#start' do
22
+ # it 'starts the server' do
23
+ # create_file 'app.rb', <<-EOS.strip_heredoc
24
+ # require 'sinatra'
25
25
 
26
- trap 'USR1' do
27
- $stderr.puts "Exit"
28
- Kernel.exit!
29
- end
26
+ # trap 'USR1' do
27
+ # $stderr.puts "Exit"
28
+ # Kernel.exit!
29
+ # end
30
30
 
31
- class App < Sinatra::Base
32
- get '/' do
33
- 'Hello World'
34
- end
35
- end
36
- EOS
31
+ # class App < Sinatra::Base
32
+ # get '/' do
33
+ # 'Hello World'
34
+ # end
35
+ # end
36
+ # EOS
37
37
 
38
- config_file = create_file 'config.ru', <<-EOS.strip_heredoc
39
- $LOAD_PATH << File.expand_path('..', __FILE__)
38
+ # config_file = create_file 'config.ru', <<-EOS.strip_heredoc
39
+ # $LOAD_PATH << File.expand_path('..', __FILE__)
40
40
 
41
- #$stderr = StringIO.new
42
- #$stdout = StringIO.new
41
+ # $stderr = StringIO.new
42
+ # $stdout = StringIO.new
43
43
 
44
- require 'app'
45
- run App
46
- EOS
44
+ # require 'app'
45
+ # run App
46
+ # EOS
47
47
 
48
- command = double('Command')
49
- allow(command).to receive(:to_s).and_return("rackup -E development -o 127.0.0.1 -p 9999 #{config_file} 2>/dev/null >&1")
48
+ # command = double('Command')
49
+ # allow(command).to receive(:to_s).and_return("rackup -E development -o 127.0.0.1 -p 9999 #{config_file} 2>/dev/null >&1")
50
50
 
51
- server = Server.new(command)
51
+ # LocalPac.ui_logger.level = :unknown
52
+ # server = Server.new(command)
52
53
 
53
- unless child_pid = Kernel.fork
54
- server.start
55
- end
54
+ # unless child_pid = Kernel.fork
55
+ # server.start
56
+ # end
56
57
 
57
- begin
58
- tries ||= 3
58
+ # begin
59
+ # tries ||= 3
59
60
 
60
- response = with_environment({}, clear: true) do
61
- Excon.get('http://127.0.0.1:9999')
62
- end
63
- rescue Excon::Errors::SocketError
64
- sleep 1
65
- retry unless (tries -= 1).zero?
66
- end
61
+ # response = with_environment({}, clear: true) do
62
+ # Excon.get('http://127.0.0.1:9999')
63
+ # end
64
+ # rescue Excon::Errors::SocketError
65
+ # sleep 1
66
+ # retry unless (tries -= 1).zero?
67
+ # end
67
68
 
68
- Process.kill :USR1, child_pid
69
- expect(response.body).to eq('Hello World')
70
- end
71
- end
69
+ # expect(response.body).to eq('Hello World')
70
+ # Process.kill 'USR1', child_pid
71
+ # end
72
+ #end
72
73
  end
@@ -1 +1,3 @@
1
1
  require 'active_support/core_ext/kernel/reporting'
2
+
3
+ LocalPac.ui_logger.level = :unknown
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: local_pac
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
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-03 00:00:00.000000000 Z
12
+ date: 2014-03-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
@@ -331,6 +331,38 @@ dependencies:
331
331
  - - ! '>='
332
332
  - !ruby/object:Gem::Version
333
333
  version: '0'
334
+ - !ruby/object:Gem::Dependency
335
+ name: sinatra-param
336
+ requirement: !ruby/object:Gem::Requirement
337
+ none: false
338
+ requirements:
339
+ - - ! '>='
340
+ - !ruby/object:Gem::Version
341
+ version: '0'
342
+ type: :runtime
343
+ prerelease: false
344
+ version_requirements: !ruby/object:Gem::Requirement
345
+ none: false
346
+ requirements:
347
+ - - ! '>='
348
+ - !ruby/object:Gem::Version
349
+ version: '0'
350
+ - !ruby/object:Gem::Dependency
351
+ name: sinatra-contrib
352
+ requirement: !ruby/object:Gem::Requirement
353
+ none: false
354
+ requirements:
355
+ - - ! '>='
356
+ - !ruby/object:Gem::Version
357
+ version: '0'
358
+ type: :runtime
359
+ prerelease: false
360
+ version_requirements: !ruby/object:Gem::Requirement
361
+ none: false
362
+ requirements:
363
+ - - ! '>='
364
+ - !ruby/object:Gem::Version
365
+ version: '0'
334
366
  - !ruby/object:Gem::Dependency
335
367
  name: rugged
336
368
  requirement: !ruby/object:Gem::Requirement
@@ -418,6 +450,7 @@ files:
418
450
  - app/controllers/application_controller.rb
419
451
  - app/controllers/assets_controller.rb
420
452
  - app/controllers/file_serve_controller.rb
453
+ - app/controllers/git_hook_controller.rb
421
454
  - app/controllers/lookup_controller.rb
422
455
  - app/locales/de.yml
423
456
  - app/locales/en.yml
@@ -439,7 +472,7 @@ files:
439
472
  - files/examples/proxy-complex.pac.example
440
473
  - files/examples/proxy-function_demo.pac.example
441
474
  - files/examples/proxy.pac.example
442
- - files/git-hook.erb
475
+ - files/git-hook.rb.erb
443
476
  - files/proxy.pac
444
477
  - lib/local_pac.rb
445
478
  - lib/local_pac/access_logger.rb
@@ -521,6 +554,7 @@ files:
521
554
  - spec/config_spec.rb
522
555
  - spec/data_spec.rb
523
556
  - spec/erb_generator_spec.rb
557
+ - spec/features/check_git_push_spec.rb
524
558
  - spec/features/fetch_proxy_pac_spec.rb
525
559
  - spec/features/lookup_proxy_spec.rb
526
560
  - spec/file_spec.rb
@@ -603,6 +637,7 @@ test_files:
603
637
  - spec/config_spec.rb
604
638
  - spec/data_spec.rb
605
639
  - spec/erb_generator_spec.rb
640
+ - spec/features/check_git_push_spec.rb
606
641
  - spec/features/fetch_proxy_pac_spec.rb
607
642
  - spec/features/lookup_proxy_spec.rb
608
643
  - spec/file_spec.rb
data/files/git-hook.erb DELETED
@@ -1,26 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- <% Array(lookup('gem_path')).each do |p| -%>
4
- $LOAD_PATH.unshift '<%= p %>'
5
- <% end -%>
6
-
7
- require 'git_hook-pre_receive'
8
- require 'pac'
9
- require 'uri'
10
-
11
- class PacFileSyntaxChecker
12
- def check(files)
13
- files.each do |f|
14
- begin
15
- pac = PAC.source f.content
16
- pac.find('http://www.example.com')
17
- rescue => e
18
- $stderr.puts "Maybe I found a syntax error in file \"#{f.name}\". Please check files locally again, e.g with a pac file tester, fix the error and send update via git. The original error was: #{e.message}"
19
- exit 1
20
- end
21
- end
22
- end
23
- end
24
-
25
- parser = Git::PreReceiveHookParser.new($stdin.read)
26
- PacFileSyntaxChecker.new.check(parser.files)