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.
- data/Gemfile.lock +15 -3
- data/app/controllers/application_controller.rb +40 -17
- data/app/controllers/git_hook_controller.rb +69 -0
- data/app/locales/en.yml +17 -4
- data/bin/local_pac +64 -14
- data/config.ru +10 -1
- data/files/example-config.erb +3 -5
- data/files/git-hook.rb.erb +121 -0
- data/lib/local_pac/cli/helper.rb +0 -22
- data/lib/local_pac/config.rb +20 -3
- data/lib/local_pac/exceptions.rb +12 -9
- data/lib/local_pac/git_repository.rb +22 -3
- data/lib/local_pac/git_storage.rb +1 -1
- data/lib/local_pac/initializer.rb +24 -12
- data/lib/local_pac/local_storage.rb +4 -1
- data/lib/local_pac/main.rb +9 -47
- data/lib/local_pac/pac_file_validator.rb +3 -2
- data/lib/local_pac/ui_logger.rb +19 -0
- data/lib/local_pac/version.rb +1 -1
- data/lib/local_pac.rb +16 -5
- data/local_pac.gemspec +3 -1
- data/spec/actions/add_examples_to_local_storage_spec.rb +1 -1
- data/spec/actions/create_directory_spec.rb +2 -2
- data/spec/actions/create_file_spec.rb +2 -2
- data/spec/actions/create_repository_spec.rb +2 -2
- data/spec/actions/send_signal_spec.rb +1 -1
- data/spec/features/check_git_push_spec.rb +105 -0
- data/spec/features/lookup_proxy_spec.rb +0 -7
- data/spec/git_repository_spec.rb +64 -0
- data/spec/initializer_spec.rb +26 -15
- data/spec/local_storage_spec.rb +31 -25
- data/spec/pac_file_validator_spec.rb +17 -3
- data/spec/proxy_pac/pac_engine_spec.rb +3 -1
- data/spec/server_spec.rb +41 -40
- data/spec/support/reporting.rb +2 -0
- metadata +38 -3
- data/files/git-hook.erb +0 -26
data/spec/local_storage_spec.rb
CHANGED
@@ -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
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
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
|
-
|
31
|
-
|
33
|
+
repo = double('GitRepository')
|
34
|
+
expect(repo).to receive(:[]).and_return(file)
|
32
35
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
36
|
+
storage = LocalStorage.new(repo)
|
37
|
+
file = storage.find('file1')
|
38
|
+
expect(file.name).to eq(:file1)
|
39
|
+
end
|
37
40
|
|
38
|
-
|
39
|
-
|
40
|
-
|
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
|
-
|
43
|
-
|
46
|
+
repo = double('GitRepository')
|
47
|
+
expect(repo).to receive(:[]).and_return(file)
|
44
48
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
+
storage = LocalStorage.new(repo)
|
50
|
+
file = storage.find('dir/file1')
|
51
|
+
expect(file.name).to eq(:'dir::file1')
|
52
|
+
end
|
49
53
|
|
50
|
-
|
51
|
-
|
52
|
-
|
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
|
-
|
55
|
-
|
56
|
-
|
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(:
|
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
|
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(
|
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
|
-
|
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
|
-
|
23
|
-
|
24
|
-
|
21
|
+
#context '#start' do
|
22
|
+
# it 'starts the server' do
|
23
|
+
# create_file 'app.rb', <<-EOS.strip_heredoc
|
24
|
+
# require 'sinatra'
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
# trap 'USR1' do
|
27
|
+
# $stderr.puts "Exit"
|
28
|
+
# Kernel.exit!
|
29
|
+
# end
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
31
|
+
# class App < Sinatra::Base
|
32
|
+
# get '/' do
|
33
|
+
# 'Hello World'
|
34
|
+
# end
|
35
|
+
# end
|
36
|
+
# EOS
|
37
37
|
|
38
|
-
|
39
|
-
|
38
|
+
# config_file = create_file 'config.ru', <<-EOS.strip_heredoc
|
39
|
+
# $LOAD_PATH << File.expand_path('..', __FILE__)
|
40
40
|
|
41
|
-
|
42
|
-
|
41
|
+
# $stderr = StringIO.new
|
42
|
+
# $stdout = StringIO.new
|
43
43
|
|
44
|
-
|
45
|
-
|
46
|
-
|
44
|
+
# require 'app'
|
45
|
+
# run App
|
46
|
+
# EOS
|
47
47
|
|
48
|
-
|
49
|
-
|
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
|
-
|
51
|
+
# LocalPac.ui_logger.level = :unknown
|
52
|
+
# server = Server.new(command)
|
52
53
|
|
53
|
-
|
54
|
-
|
55
|
-
|
54
|
+
# unless child_pid = Kernel.fork
|
55
|
+
# server.start
|
56
|
+
# end
|
56
57
|
|
57
|
-
|
58
|
-
|
58
|
+
# begin
|
59
|
+
# tries ||= 3
|
59
60
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
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
|
-
|
69
|
-
|
70
|
-
|
71
|
-
end
|
69
|
+
# expect(response.body).to eq('Hello World')
|
70
|
+
# Process.kill 'USR1', child_pid
|
71
|
+
# end
|
72
|
+
#end
|
72
73
|
end
|
data/spec/support/reporting.rb
CHANGED
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.
|
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-
|
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)
|