local_pac 0.9.0 → 0.10.0
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.
- data/Gemfile.lock +2 -2
- data/app/controllers/application_controller.rb +23 -5
- data/app/controllers/assets_controller.rb +3 -0
- data/app/controllers/file_serve_controller.rb +7 -2
- data/app/controllers/git_hook_controller.rb +3 -1
- data/app/controllers/lookup_controller.rb +10 -6
- data/app/locales/en.yml +3 -0
- data/lib/local_pac.rb +4 -0
- data/lib/local_pac/access_logger.rb +2 -0
- data/lib/local_pac/actions/reload_local_storage.rb +1 -1
- data/lib/local_pac/config.rb +1 -0
- data/lib/local_pac/error_messages.rb +7 -0
- data/lib/local_pac/exceptions.rb +3 -0
- data/lib/local_pac/git_storage.rb +14 -9
- data/lib/local_pac/local_storage.rb +1 -1
- data/lib/local_pac/translation_rule.rb +27 -0
- data/lib/local_pac/translation_table.rb +46 -0
- data/lib/local_pac/version.rb +1 -1
- data/local_pac.gemspec +1 -1
- data/share/archlinux/PKGBUILD +3 -3
- data/share/docker/Dockerfile +24 -0
- data/share/docker/src/ruby/gemrc +5 -0
- data/share/docker/src/shell/ruby.sh +5 -0
- data/share/docker/src/sudo/sudoers +90 -0
- data/share/docker/src/zsh/.zshrc +96 -0
- data/spec/access_logger_spec.rb +9 -0
- data/spec/actions/get_system_information_spec.rb +2 -1
- data/spec/actions/show_application_status_spec.rb +3 -2
- data/spec/error_messages_spec.rb +13 -0
- data/spec/features/check_git_push_spec.rb +20 -0
- data/spec/features/fetch_proxy_pac_spec.rb +33 -4
- data/spec/features/lookup_proxy_spec.rb +54 -9
- data/spec/git_storage_spec.rb +1 -0
- data/spec/local_storage_spec.rb +13 -0
- data/spec/spec_helper.rb +5 -0
- data/spec/translation_rule_spec.rb +30 -0
- data/spec/translation_table_spec.rb +65 -0
- metadata +27 -6
data/Gemfile.lock
CHANGED
@@ -2,16 +2,19 @@
|
|
2
2
|
module LocalPac
|
3
3
|
module App
|
4
4
|
class ApplicationController < Sinatra::Base
|
5
|
+
set :root, ::File.expand_path('../../', __FILE__)
|
6
|
+
set :haml, :format => :html5
|
7
|
+
|
8
|
+
enable :protection
|
9
|
+
enable :session
|
5
10
|
|
6
11
|
@local_storage_mutex = Mutex.new
|
12
|
+
@translation_table_mutex = Mutex.new
|
7
13
|
|
8
14
|
class << self
|
9
|
-
attr_reader :local_storage_mutex
|
15
|
+
attr_reader :local_storage_mutex, :translation_table_mutex
|
10
16
|
end
|
11
17
|
|
12
|
-
set :root, ::File.expand_path('../../', __FILE__)
|
13
|
-
set :haml, :format => :html5
|
14
|
-
|
15
18
|
def local_storage
|
16
19
|
return @local_storage if @local_storage
|
17
20
|
|
@@ -26,6 +29,20 @@ module LocalPac
|
|
26
29
|
end
|
27
30
|
end
|
28
31
|
|
32
|
+
def translation_table
|
33
|
+
return @translation_table if @translation_table
|
34
|
+
|
35
|
+
ApplicationController.translation_table_mutex.synchronize do
|
36
|
+
if settings.respond_to? :translation_table
|
37
|
+
LocalPac.ui_logger.debug 'Using translation table in production mode: loaded once on startup'
|
38
|
+
@translation_table = settings.translation_table
|
39
|
+
else
|
40
|
+
LocalPac.ui_logger.debug 'Using translation table in development mode: reloaded per request'
|
41
|
+
@translation_table = LocalPac::TranslationTable.new
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
29
46
|
use Rack::Deflater
|
30
47
|
use Rack::Locale
|
31
48
|
use Rack::NestedParams
|
@@ -116,6 +133,7 @@ module LocalPac
|
|
116
133
|
use Rack::CommonLogger, LocalPac::AccessLogger.new(LocalPac.config.access_log)
|
117
134
|
set :raise_errors, false
|
118
135
|
set :local_storage, LocalPac::LocalStorage.new
|
136
|
+
set :translation_table, LocalPac::TranslationTable.new
|
119
137
|
end
|
120
138
|
|
121
139
|
configure :development do
|
@@ -128,7 +146,7 @@ module LocalPac
|
|
128
146
|
|
129
147
|
configure :test do
|
130
148
|
use Rack::CommonLogger, LocalPac::NullAccessLogger.new
|
131
|
-
set :raise_errors,
|
149
|
+
set :raise_errors, false
|
132
150
|
end
|
133
151
|
|
134
152
|
configure do
|
@@ -1,16 +1,21 @@
|
|
1
1
|
module LocalPac
|
2
2
|
module App
|
3
3
|
class FileServeController < ApplicationController
|
4
|
+
helpers Sinatra::Param
|
4
5
|
|
5
6
|
get '/' do
|
6
7
|
redirect to('/proxy.pac')
|
7
8
|
end
|
8
9
|
|
9
10
|
get '/:name' do
|
11
|
+
param :name, String, required: true
|
12
|
+
|
10
13
|
content_type :proxy_pac_file
|
11
14
|
|
12
|
-
|
13
|
-
|
15
|
+
name = translation_table.rewrite(env['REMOTE_ADDR'], params[:name])
|
16
|
+
|
17
|
+
file = local_storage.find(name)
|
18
|
+
fail Sinatra::NotFound, name if file.nil?
|
14
19
|
|
15
20
|
file.compressed_content
|
16
21
|
end
|
@@ -3,6 +3,8 @@ module LocalPac
|
|
3
3
|
module App
|
4
4
|
class GitHookController < ApplicationController
|
5
5
|
|
6
|
+
set :observers, [LocalPac::App::FileServeController, LocalPac::App::LookupController]
|
7
|
+
|
6
8
|
helpers Sinatra::Param
|
7
9
|
helpers Sinatra::JSON
|
8
10
|
|
@@ -71,7 +73,7 @@ module LocalPac
|
|
71
73
|
fail Exceptions::PacFileInvalid, name: f.path unless validator.valid?(f)
|
72
74
|
end
|
73
75
|
|
74
|
-
LocalPac::Actions::ReloadLocalStorage.new(
|
76
|
+
LocalPac::Actions::ReloadLocalStorage.new(settings.observers).run
|
75
77
|
|
76
78
|
json result: :success
|
77
79
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
module LocalPac
|
2
2
|
module App
|
3
3
|
class LookupController < ApplicationController
|
4
|
-
|
5
4
|
helpers Sinatra::Param
|
6
5
|
|
7
6
|
get '/' do
|
@@ -9,8 +8,12 @@ module LocalPac
|
|
9
8
|
end
|
10
9
|
|
11
10
|
get '/:name' do
|
12
|
-
|
13
|
-
|
11
|
+
param :name, String, required: true
|
12
|
+
|
13
|
+
name = translation_table.rewrite(env['REMOTE_ADDR'], params[:name])
|
14
|
+
|
15
|
+
file = local_storage.find(name)
|
16
|
+
fail Sinatra::NotFound, name: name if file.nil?
|
14
17
|
|
15
18
|
@client_ip = IPAddr.new(remote_addr).to_s
|
16
19
|
@time = Time.now.strftime "%Y-%m-%d %H:%M:%S"
|
@@ -26,10 +29,11 @@ module LocalPac
|
|
26
29
|
|
27
30
|
parse_env = {}
|
28
31
|
|
29
|
-
|
32
|
+
name = translation_table.rewrite(env['REMOTE_ADDR'], params[:name])
|
33
|
+
@file = local_storage.find(name)
|
30
34
|
@uri = Addressable::URI.heuristic_parse(params[:url])
|
31
35
|
|
32
|
-
fail Sinatra::NotFound, name:
|
36
|
+
fail Sinatra::NotFound, name: name if @file.nil?
|
33
37
|
fail Exceptions::GivenUrlInvalid, JSON.dump(url: params[:url]) if @uri.host.blank?
|
34
38
|
|
35
39
|
begin
|
@@ -50,7 +54,7 @@ module LocalPac
|
|
50
54
|
begin
|
51
55
|
@result = parser.find(@uri)
|
52
56
|
rescue Exceptions::PacFileInvalid
|
53
|
-
raise Exceptions::PacFileInvalid, name:
|
57
|
+
raise Exceptions::PacFileInvalid, name: name
|
54
58
|
end
|
55
59
|
|
56
60
|
haml :lookup_result, layout: :application
|
data/app/locales/en.yml
CHANGED
@@ -19,6 +19,9 @@ en:
|
|
19
19
|
invalid_url:
|
20
20
|
summary: Invalid URL...
|
21
21
|
details: Sorry, but your request is invalid. The URL "%{url}" is not a correct one. Allowed are URLs like "http://www.example.org" or "www.example.org".
|
22
|
+
invalid_access_log_path:
|
23
|
+
summary: Invalid Path to Access Log...
|
24
|
+
details: Sorry, but I cannot start the server. The path "%{file}" to the access log is invalid. Maybe the directory "%{directory}" where the access log should be stored, does not exist.
|
22
25
|
invalid_client_ip:
|
23
26
|
summary: Invalid Client IP...
|
24
27
|
details: Sorry, but your request is invalid. The client ip address "%{client_ip}" is not a correct one. Allowed are IPs like "10.0.0.1".
|
data/lib/local_pac.rb
CHANGED
@@ -10,10 +10,12 @@ require 'sinatra'
|
|
10
10
|
require 'sinatra/param'
|
11
11
|
require "sinatra/json"
|
12
12
|
require 'json'
|
13
|
+
require 'rack/protection'
|
13
14
|
|
14
15
|
require 'thor'
|
15
16
|
require 'sys/proctable'
|
16
17
|
require 'set'
|
18
|
+
require 'csv'
|
17
19
|
require 'facter'
|
18
20
|
require 'fileutils'
|
19
21
|
require 'pathname'
|
@@ -45,6 +47,8 @@ require 'local_pac/main'
|
|
45
47
|
require 'local_pac/access_logger'
|
46
48
|
require 'local_pac/null_access_logger'
|
47
49
|
|
50
|
+
require 'local_pac/translation_rule'
|
51
|
+
require 'local_pac/translation_table'
|
48
52
|
require 'local_pac/git_repository'
|
49
53
|
require 'local_pac/git_storage'
|
50
54
|
require 'local_pac/erb_generator'
|
data/lib/local_pac/config.rb
CHANGED
@@ -64,6 +64,7 @@ module LocalPac
|
|
64
64
|
option :access_log, ::File.expand_path(::File.join(ENV['HOME'], '.local', 'share', 'local_pac', 'log', 'access.log'))
|
65
65
|
option :sass_cache, ::File.expand_path(::File.join(ENV['HOME'], '.local', 'share', 'local_pac', 'cache'))
|
66
66
|
option :config_file, ::File.expand_path(::File.join(ENV['HOME'], '.config', 'local_pac', 'config.yaml'))
|
67
|
+
option :translation_file, ::File.expand_path(::File.join(ENV['HOME'], '.config', 'local_pac', 'translation.csv'))
|
67
68
|
option :reload_config_signal, :USR1
|
68
69
|
option :reload_storage_signal, :USR2
|
69
70
|
option :debug_mode, false
|
@@ -121,6 +121,13 @@ module LocalPac
|
|
121
121
|
exit_code: 17,
|
122
122
|
)
|
123
123
|
|
124
|
+
ErrorHandler.create(
|
125
|
+
exception: Exceptions::AccessLogPathInvalid,
|
126
|
+
details: 'errors.invalid_access_log_path.details',
|
127
|
+
summary: 'errors.invalid_access_log_path.summary',
|
128
|
+
exit_code: 18,
|
129
|
+
)
|
130
|
+
|
124
131
|
#ErrorHandler.create(
|
125
132
|
# exception:
|
126
133
|
# summary:
|
data/lib/local_pac/exceptions.rb
CHANGED
@@ -4,7 +4,7 @@ module LocalPac
|
|
4
4
|
|
5
5
|
private
|
6
6
|
|
7
|
-
attr_reader :storage_path, :repository, :file_creator, :null_file, :vcs_engine, :compressor_engine
|
7
|
+
attr_reader :storage_path, :repository, :file_creator, :null_file, :vcs_engine, :compressor_engine, :data
|
8
8
|
|
9
9
|
public
|
10
10
|
|
@@ -19,6 +19,14 @@ module LocalPac
|
|
19
19
|
rescue Exceptions::RepositoryDoesNotExist
|
20
20
|
@repository = vcs_engine.create(storage_path)
|
21
21
|
end
|
22
|
+
|
23
|
+
LocalPac.ui_logger.debug 'Available pac files by path: ' + pac_files.collect {|p| "\"#{p.path}\"" }.join(", ")
|
24
|
+
LocalPac.ui_logger.debug 'Available pac files by name: ' + pac_files.collect {|p| "\"#{p.name}\"" }.join(", ")
|
25
|
+
|
26
|
+
@data = load_data
|
27
|
+
|
28
|
+
LocalPac.ui_logger.debug 'Loaded pac files by path: ' + @data.collect {|_,p| "\"#{p.path}\"" }.join(", ")
|
29
|
+
LocalPac.ui_logger.debug 'Loaded pac files by name: ' + @data.collect {|_,p| "\"#{p.name}\"" }.join(", ")
|
22
30
|
end
|
23
31
|
|
24
32
|
def [](key)
|
@@ -35,15 +43,12 @@ module LocalPac
|
|
35
43
|
|
36
44
|
private
|
37
45
|
|
38
|
-
def
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
compressor_engine.new.prepare(file)
|
43
|
-
memo[file.name.to_sym] = file
|
46
|
+
def load_data
|
47
|
+
pac_files.reduce({}) do |memo, file|
|
48
|
+
compressor_engine.new.prepare(file)
|
49
|
+
memo[file.name.to_sym] = file
|
44
50
|
|
45
|
-
|
46
|
-
end
|
51
|
+
memo
|
47
52
|
end
|
48
53
|
end
|
49
54
|
|
@@ -12,7 +12,7 @@ module LocalPac
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def find(name)
|
15
|
-
name = name.sub(/.pac$/, '').
|
15
|
+
name = name.sub(/.pac$/, '').gsub(%r{/}, '::').downcase.to_sym
|
16
16
|
LocalPac.ui_logger.debug "Using the following name to find pac file: \":#{name}\"."
|
17
17
|
file = storage[name]
|
18
18
|
LocalPac.ui_logger.debug "Returning the following file: \"#{file.path || 'not found' }\"."
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module LocalPac
|
3
|
+
class TranslationRule
|
4
|
+
|
5
|
+
attr_reader :network, :requested_file, :rewritten_file
|
6
|
+
|
7
|
+
def initialize(options = {})
|
8
|
+
@network = IPAddr.new(options.fetch(:network))
|
9
|
+
@requested_file = options.fetch(:requested_file)
|
10
|
+
@rewritten_file = options.fetch(:rewritten_file)
|
11
|
+
rescue KeyError => err
|
12
|
+
raise ArgumentError, err.message
|
13
|
+
end
|
14
|
+
|
15
|
+
def match?(client_ip, file)
|
16
|
+
network.include?(client_ip) && requested_file == file
|
17
|
+
end
|
18
|
+
|
19
|
+
def eql?(other)
|
20
|
+
network == other.network && requested_file == other.requested_file
|
21
|
+
end
|
22
|
+
|
23
|
+
def hash
|
24
|
+
[network, requested_file].hash
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module LocalPac
|
3
|
+
class TranslationTable
|
4
|
+
private
|
5
|
+
|
6
|
+
attr_reader :rule_engine, :rules, :cache
|
7
|
+
|
8
|
+
public
|
9
|
+
|
10
|
+
def initialize(file = LocalPac.config.translation_file, rule_engine = TranslationRule, cache = ActiveSupport::Cache::MemoryStore.new)
|
11
|
+
@rule_engine = rule_engine
|
12
|
+
@rules = read_table(file)
|
13
|
+
@cache = cache
|
14
|
+
end
|
15
|
+
|
16
|
+
def rewrite(client_ip, requested_file)
|
17
|
+
#cache.fetch("#{client_ip}_#{requested_file}") do
|
18
|
+
rules.find( proc { OpenStruct.new(rewritten_file: requested_file) } ) { |r| r.match?(client_ip, requested_file) }.rewritten_file
|
19
|
+
#end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def read_table(file)
|
25
|
+
local_rules = Set.new
|
26
|
+
|
27
|
+
if file.blank?
|
28
|
+
LocalPac.ui_logger.warn "Undefined translation file at path \"#{file}\". Using an empty table."
|
29
|
+
return local_rules
|
30
|
+
end
|
31
|
+
|
32
|
+
CSV.foreach(file, headers: true) do |row|
|
33
|
+
local_rules << rule_engine.new(
|
34
|
+
network: row['network'],
|
35
|
+
requested_file: row['requested_file'],
|
36
|
+
rewritten_file: row['rewritten_file'],
|
37
|
+
)
|
38
|
+
end
|
39
|
+
|
40
|
+
local_rules
|
41
|
+
rescue Errno::ENOENT
|
42
|
+
LocalPac.ui_logger.warn "I cannot find translation file at path \"#{file}\". Using an empty table."
|
43
|
+
local_rules
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/local_pac/version.rb
CHANGED
data/local_pac.gemspec
CHANGED
@@ -34,7 +34,7 @@ EOS
|
|
34
34
|
spec.add_runtime_dependency 'rack-contrib'
|
35
35
|
spec.add_runtime_dependency 'sinatra'
|
36
36
|
spec.add_runtime_dependency 'activesupport'
|
37
|
-
spec.add_runtime_dependency 'proxy_pac_rb'
|
37
|
+
spec.add_runtime_dependency 'proxy_pac_rb', '~>0.2.0'
|
38
38
|
spec.add_runtime_dependency 'facter'
|
39
39
|
spec.add_runtime_dependency 'pager'
|
40
40
|
spec.add_runtime_dependency 'sys-proctable'
|
data/share/archlinux/PKGBUILD
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Maintainer: Max Meyer <dev@fedux.org>
|
2
2
|
pkgname=local_pac
|
3
|
-
pkgver=0.
|
3
|
+
pkgver=0.9.0
|
4
4
|
pkgrel=1
|
5
5
|
pkgdesc="local pacfile serving server"
|
6
6
|
arch=(i686 x86_64)
|
@@ -11,7 +11,7 @@ install=${pkgname}.install
|
|
11
11
|
makedepends=(rubygems filegen phantomjs)
|
12
12
|
source=(http://gems.rubyforge.org/gems/$pkgname-$pkgver.gem)
|
13
13
|
noextract=($pkgname-$pkgver.gem)
|
14
|
-
sha256sums=('
|
14
|
+
sha256sums=('7838bb5cede5dbea1431edad9952ca1fb91f168c70382f58dfdf54b7d8e8196e')
|
15
15
|
|
16
16
|
package() {
|
17
17
|
cd "$srcdir"
|
@@ -34,7 +34,7 @@ package() {
|
|
34
34
|
|
35
35
|
msg "Starting download of gems. Don't get alert if the download takes a lot of time. Since rubygems 2.2.0 a new algorithm to resolve dependencies is used. Upgrade to > 2.2.0 via sudo /usr/bin/gem update --system to improve performance."
|
36
36
|
|
37
|
-
GEM_HOME="${pkgdir}${_library_dir}" GEM_ROOT="${pkgdir}${_library_dir}" GEM_PATH="${pkgdir}${_library_dir}" /usr/bin/gem install --env-shebang --wrappers --no-ri --no-rdoc --no-prerelease --install-dir ${pkgdir}${_library_dir} $pkgname -v $pkgver
|
37
|
+
GEM_HOME="${pkgdir}${_library_dir}" GEM_ROOT="${pkgdir}${_library_dir}" GEM_PATH="${pkgdir}${_library_dir}" /usr/bin/gem install --env-shebang --wrappers --no-ri --no-rdoc --no-prerelease --install-dir ${pkgdir}${_library_dir} $pkgname -v $pkgver --verbose
|
38
38
|
GEM_HOME="${pkgdir}${_library_dir}" GEM_ROOT="${pkgdir}${_library_dir}" GEM_PATH="${pkgdir}${_library_dir}" /usr/bin/gem install --env-shebang --wrappers --no-ri --no-rdoc --no-prerelease --install-dir ${pkgdir}${_library_dir} puma
|
39
39
|
|
40
40
|
install -D -m 644 ${pkgdir}${_share_dir}/archlinux/config.yaml ${pkgdir}${_examples_dir}/config.yaml.example
|
@@ -0,0 +1,24 @@
|
|
1
|
+
FROM archlinux
|
2
|
+
|
3
|
+
RUN pacman -Suy ruby git zsh sudo phantomjs --noconfirm
|
4
|
+
|
5
|
+
ADD src/shell/ruby.sh /etc/profile.d/ruby.sh
|
6
|
+
RUN chmod +x /etc/profile.d/ruby.sh
|
7
|
+
RUN chown root:root /etc/profile.d/ruby.sh
|
8
|
+
|
9
|
+
ADD src/ruby/gemrc /etc/gemrc
|
10
|
+
RUN chown root:root /etc/gemrc
|
11
|
+
|
12
|
+
ADD src/sudo/sudoers /etc/sudoers
|
13
|
+
RUN chown root:root /etc/sudoers
|
14
|
+
|
15
|
+
RUN useradd -m user -s /usr/bin/zsh
|
16
|
+
RUN echo user:user | chpasswd -c SHA256
|
17
|
+
|
18
|
+
RUN groupadd sudo
|
19
|
+
RUN gpasswd -a user sudo
|
20
|
+
|
21
|
+
ADD src/zsh/.zshrc /home/user/.zshrc
|
22
|
+
|
23
|
+
RUN su -l -c "gem install bundler" user
|
24
|
+
RUN su -l -c "gem install rake" user
|
@@ -0,0 +1,90 @@
|
|
1
|
+
## sudoers file.
|
2
|
+
##
|
3
|
+
## This file MUST be edited with the 'visudo' command as root.
|
4
|
+
## Failure to use 'visudo' may result in syntax or file permission errors
|
5
|
+
## that prevent sudo from running.
|
6
|
+
##
|
7
|
+
## See the sudoers man page for the details on how to write a sudoers file.
|
8
|
+
##
|
9
|
+
|
10
|
+
##
|
11
|
+
## Host alias specification
|
12
|
+
##
|
13
|
+
## Groups of machines. These may include host names (optionally with wildcards),
|
14
|
+
## IP addresses, network numbers or netgroups.
|
15
|
+
# Host_Alias WEBSERVERS = www1, www2, www3
|
16
|
+
|
17
|
+
##
|
18
|
+
## User alias specification
|
19
|
+
##
|
20
|
+
## Groups of users. These may consist of user names, uids, Unix groups,
|
21
|
+
## or netgroups.
|
22
|
+
# User_Alias ADMINS = millert, dowdy, mikef
|
23
|
+
|
24
|
+
##
|
25
|
+
## Cmnd alias specification
|
26
|
+
##
|
27
|
+
## Groups of commands. Often used to group related commands together.
|
28
|
+
# Cmnd_Alias PROCESSES = /usr/bin/nice, /bin/kill, /usr/bin/renice, \
|
29
|
+
# /usr/bin/pkill, /usr/bin/top
|
30
|
+
|
31
|
+
##
|
32
|
+
## Defaults specification
|
33
|
+
##
|
34
|
+
## You may wish to keep some of the following environment variables
|
35
|
+
## when running commands via sudo.
|
36
|
+
##
|
37
|
+
## Locale settings
|
38
|
+
# Defaults env_keep += "LANG LANGUAGE LINGUAS LC_* _XKB_CHARSET"
|
39
|
+
##
|
40
|
+
## Run X applications through sudo; HOME is used to find the
|
41
|
+
## .Xauthority file. Note that other programs use HOME to find
|
42
|
+
## configuration files and this may lead to privilege escalation!
|
43
|
+
# Defaults env_keep += "HOME"
|
44
|
+
##
|
45
|
+
## X11 resource path settings
|
46
|
+
# Defaults env_keep += "XAPPLRESDIR XFILESEARCHPATH XUSERFILESEARCHPATH"
|
47
|
+
##
|
48
|
+
## Desktop path settings
|
49
|
+
# Defaults env_keep += "QTDIR KDEDIR"
|
50
|
+
##
|
51
|
+
## Allow sudo-run commands to inherit the callers' ConsoleKit session
|
52
|
+
# Defaults env_keep += "XDG_SESSION_COOKIE"
|
53
|
+
##
|
54
|
+
## Uncomment to enable special input methods. Care should be taken as
|
55
|
+
## this may allow users to subvert the command being run via sudo.
|
56
|
+
# Defaults env_keep += "XMODIFIERS GTK_IM_MODULE QT_IM_MODULE QT_IM_SWITCHER"
|
57
|
+
##
|
58
|
+
## Uncomment to enable logging of a command's output, except for
|
59
|
+
## sudoreplay and reboot. Use sudoreplay to play back logged sessions.
|
60
|
+
# Defaults log_output
|
61
|
+
# Defaults!/usr/bin/sudoreplay !log_output
|
62
|
+
# Defaults!/usr/local/bin/sudoreplay !log_output
|
63
|
+
# Defaults!/sbin/reboot !log_output
|
64
|
+
|
65
|
+
##
|
66
|
+
## Runas alias specification
|
67
|
+
##
|
68
|
+
|
69
|
+
##
|
70
|
+
## User privilege specification
|
71
|
+
##
|
72
|
+
root ALL=(ALL) ALL
|
73
|
+
|
74
|
+
## Uncomment to allow members of group wheel to execute any command
|
75
|
+
# %wheel ALL=(ALL) ALL
|
76
|
+
|
77
|
+
## Same thing without a password
|
78
|
+
# %wheel ALL=(ALL) NOPASSWD: ALL
|
79
|
+
|
80
|
+
## Uncomment to allow members of group sudo to execute any command
|
81
|
+
%sudo ALL=(ALL) ALL
|
82
|
+
|
83
|
+
## Uncomment to allow any user to run sudo if they know the password
|
84
|
+
## of the user they are running the command as (root by default).
|
85
|
+
# Defaults targetpw # Ask for the password of the target user
|
86
|
+
# ALL ALL=(ALL) ALL # WARNING: only use this together with 'Defaults targetpw'
|
87
|
+
|
88
|
+
## Read drop-in files from /etc/sudoers.d
|
89
|
+
## (the '#' here does not indicate a comment)
|
90
|
+
#includedir /etc/sudoers.d
|
@@ -0,0 +1,96 @@
|
|
1
|
+
alias -s tex=vim
|
2
|
+
alias -s html=w3m
|
3
|
+
|
4
|
+
alias ls='ls --color'
|
5
|
+
alias ll='ls -al'
|
6
|
+
|
7
|
+
#caching
|
8
|
+
zstyle ':completion:*' use-cache on
|
9
|
+
zstyle ':completion:*' cache-path ~/.zsh_completion_cache
|
10
|
+
|
11
|
+
#approxy completion
|
12
|
+
zstyle ':completion:*' completer _complete _match _approximate
|
13
|
+
zstyle ':completion:*:match:*' original only
|
14
|
+
zstyle ':completion:*:approximate:*' max-errors 1 numeric
|
15
|
+
|
16
|
+
#paths
|
17
|
+
zstyle ':completion:*' squeeze-slashes true
|
18
|
+
export EDITOR=vim
|
19
|
+
export HISTFILE=~/.zsh_history
|
20
|
+
export HISTSIZE=10000
|
21
|
+
export SAVEHIST=10000
|
22
|
+
export LC_ALL=en_GB.utf8
|
23
|
+
export PATH=~/bin:$PATH
|
24
|
+
export WORDCHARS='*?_[]~=&;!#$%^(){}'
|
25
|
+
#export fignore='swp:swo' ]
|
26
|
+
|
27
|
+
#fpath=($HOME/.zsh/completion/ $fpath)
|
28
|
+
bindkey -e
|
29
|
+
bindkey "" backward-delete-char
|
30
|
+
bindkey "[3~" delete-char
|
31
|
+
autoload -U promptinit && promptinit
|
32
|
+
autoload -U colors && colors
|
33
|
+
autoload -U compinit && compinit
|
34
|
+
autoload -U age
|
35
|
+
autoload -U zmv
|
36
|
+
autoload -Uz vcs_info
|
37
|
+
|
38
|
+
zmodload zsh/pcre
|
39
|
+
zmodload zsh/datetime
|
40
|
+
#CHANGING DIRECTORIes
|
41
|
+
setopt auto_cd
|
42
|
+
setopt auto_pushd
|
43
|
+
setopt pushd_ignore_dups
|
44
|
+
|
45
|
+
#completion
|
46
|
+
#setopt auto_list
|
47
|
+
setopt auto_menu
|
48
|
+
setopt auto_param_slash
|
49
|
+
setopt auto_remove_slash
|
50
|
+
setopt hash_list_all
|
51
|
+
setopt hash_cmds
|
52
|
+
setopt hash_dirs
|
53
|
+
|
54
|
+
#expansion and globbing
|
55
|
+
setopt glob_complete
|
56
|
+
setopt glob_dots
|
57
|
+
setopt hist_subst_pattern
|
58
|
+
setopt mark_dirs
|
59
|
+
setopt numeric_glob_sort
|
60
|
+
setopt null_glob
|
61
|
+
setopt completealiases
|
62
|
+
|
63
|
+
#history
|
64
|
+
setopt append_history
|
65
|
+
setopt extended_history
|
66
|
+
setopt hist_allow_clobber
|
67
|
+
setopt hist_fcntl_lock
|
68
|
+
setopt hist_ignore_all_dups
|
69
|
+
setopt hist_ignore_space
|
70
|
+
setopt hist_lex_words
|
71
|
+
setopt hist_reduce_blanks
|
72
|
+
setopt hist_save_no_dups
|
73
|
+
setopt inc_append_history
|
74
|
+
|
75
|
+
#input/output
|
76
|
+
setopt correct
|
77
|
+
#setopt print_exit_value
|
78
|
+
setopt short_loops
|
79
|
+
|
80
|
+
#job control
|
81
|
+
setopt long_list_jobs
|
82
|
+
setopt notify
|
83
|
+
|
84
|
+
#prompting
|
85
|
+
setopt transient_rprompt
|
86
|
+
setopt prompt_subst
|
87
|
+
|
88
|
+
#other
|
89
|
+
setopt interactivecomments
|
90
|
+
precmd() {
|
91
|
+
print -Pn "\e]0;%n@%m: %~\a"
|
92
|
+
vcs_info
|
93
|
+
}
|
94
|
+
|
95
|
+
PROMPT='%# '
|
96
|
+
RPROMPT="[%n@%m]"
|
@@ -36,7 +36,7 @@ describe Actions::ShowApplicationStatus do
|
|
36
36
|
EOS
|
37
37
|
|
38
38
|
config_file = create_file('config.yaml', config_string)
|
39
|
-
|
39
|
+
create_file('run/pid', $$)
|
40
40
|
|
41
41
|
config = LocalPac::Config.new(config_file)
|
42
42
|
|
@@ -44,7 +44,8 @@ describe Actions::ShowApplicationStatus do
|
|
44
44
|
Actions::ShowApplicationStatus.new(pager: false, config: config).run
|
45
45
|
end
|
46
46
|
|
47
|
-
|
47
|
+
# timing problems
|
48
|
+
#expect(result).to include('osfamily')
|
48
49
|
expect(result).to include('pid_file')
|
49
50
|
expect(result).to include('pid_file')
|
50
51
|
expect(result).to include('cmdline')
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe 'Error messages' do
|
5
|
+
it 'shows suitable error for invalid access log' do
|
6
|
+
handler = ErrorHandler.find(Exceptions::AccessLogPathInvalid)
|
7
|
+
handler.use(file: 'my_file', directory: 'my_dir')
|
8
|
+
|
9
|
+
expect(handler.details).to include 'my_file'
|
10
|
+
expect(handler.details).to include 'my_dir'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
@@ -50,6 +50,10 @@ describe 'Lookup proxy for url' do
|
|
50
50
|
end.new
|
51
51
|
|
52
52
|
LocalPac.config = config
|
53
|
+
|
54
|
+
observer = double('observer')
|
55
|
+
LocalPac::App::GitHookController.set :observers, [observer]
|
56
|
+
|
53
57
|
Capybara.app = LocalPac::App::GitHookController
|
54
58
|
end
|
55
59
|
|
@@ -69,6 +73,10 @@ describe 'Lookup proxy for url' do
|
|
69
73
|
api_key: 'THIS_IS_THE_API_KEY',
|
70
74
|
}
|
71
75
|
|
76
|
+
observer = double('observer')
|
77
|
+
expect(observer).to receive(:set)
|
78
|
+
LocalPac::App::GitHookController.set :observers, [observer]
|
79
|
+
|
72
80
|
response = page.driver.post('/pre-receive', params )
|
73
81
|
result = JSON.parse(response.body)['result']
|
74
82
|
|
@@ -92,6 +100,10 @@ describe 'Lookup proxy for url' do
|
|
92
100
|
api_key: 'THIS_IS_THE_API_KEY',
|
93
101
|
}
|
94
102
|
|
103
|
+
observer = double('observer')
|
104
|
+
allow(observer).to receive(:set)
|
105
|
+
LocalPac::App::GitHookController.set :observers, [observer]
|
106
|
+
|
95
107
|
response = page.driver.post('/pre-receive', params )
|
96
108
|
result = JSON.parse(response.body)['error_summary']
|
97
109
|
|
@@ -108,6 +120,10 @@ describe 'Lookup proxy for url' do
|
|
108
120
|
api_key: 'THIS_IS_THE_API_KEY',
|
109
121
|
}
|
110
122
|
|
123
|
+
observer = double('observer')
|
124
|
+
allow(observer).to receive(:set)
|
125
|
+
LocalPac::App::GitHookController.set :observers, [observer]
|
126
|
+
|
111
127
|
response = page.driver.post('/blub-gith-hook', params )
|
112
128
|
json = JSON.parse(response.body)
|
113
129
|
|
@@ -123,6 +139,10 @@ describe 'Lookup proxy for url' do
|
|
123
139
|
api_key: 'invalid',
|
124
140
|
}
|
125
141
|
|
142
|
+
observer = double('observer')
|
143
|
+
allow(observer).to receive(:set)
|
144
|
+
LocalPac::App::GitHookController.set :observers, [observer]
|
145
|
+
|
126
146
|
response = page.driver.post('/pre-receive', params )
|
127
147
|
result = JSON.parse(response.body)['error_summary']
|
128
148
|
|
@@ -3,20 +3,27 @@ require 'spec_helper_features'
|
|
3
3
|
|
4
4
|
describe 'Fetch proxy pac', :type => :feature do
|
5
5
|
context '/v1/pac' do
|
6
|
-
let(:
|
6
|
+
let(:valid_pac_file1) do <<-EOS.strip_heredoc.chomp
|
7
7
|
function FindProxyForURL(url, host) {
|
8
8
|
return "DIRECT";
|
9
9
|
}
|
10
10
|
EOS
|
11
11
|
end
|
12
|
+
|
13
|
+
let(:valid_pac_file2) do <<-EOS.strip_heredoc.chomp
|
14
|
+
function FindProxyForURL(url, host) {
|
15
|
+
return "PROXY localhost:3128";
|
16
|
+
}
|
17
|
+
EOS
|
18
|
+
end
|
12
19
|
|
13
|
-
let(:
|
20
|
+
let(:compressed_valid_pac_file1) { "function FindProxyForURL(){return\"DIRECT\"}" }
|
14
21
|
|
15
22
|
let(:git_repo) { File.join(working_directory, 'git_repo.git') }
|
16
23
|
|
17
24
|
before :each do
|
18
25
|
repo = GitRepository.create(git_repo)
|
19
|
-
repo.add_content('file.pac',
|
26
|
+
repo.add_content('file.pac', valid_pac_file1)
|
20
27
|
end
|
21
28
|
|
22
29
|
before :each do
|
@@ -30,10 +37,14 @@ describe 'Fetch proxy pac', :type => :feature do
|
|
30
37
|
def local_storage
|
31
38
|
::File.join(working_directory, 'git_repo.git')
|
32
39
|
end
|
40
|
+
|
41
|
+
def translation_file
|
42
|
+
::File.join(working_directory, 'translation.csv')
|
43
|
+
end
|
33
44
|
end.new
|
34
45
|
|
35
46
|
LocalPac.config = config
|
36
|
-
Capybara.app = LocalPac::App::FileServeController
|
47
|
+
Capybara.app = LocalPac::App::FileServeController.new
|
37
48
|
end
|
38
49
|
|
39
50
|
it 'finds an existing proxy pac' do
|
@@ -41,6 +52,20 @@ describe 'Fetch proxy pac', :type => :feature do
|
|
41
52
|
expect(page).to have_content('function FindProxyForURL(){return"DIRECT"}')
|
42
53
|
end
|
43
54
|
|
55
|
+
it 'supports file name translation based on client ip address' do
|
56
|
+
repo = GitRepository.new(git_repo)
|
57
|
+
repo.add_content('proxy.pac', valid_pac_file1)
|
58
|
+
repo.add_content('proxy_neu.pac', valid_pac_file2)
|
59
|
+
|
60
|
+
create_file 'translation.csv', <<-EOS.strip_heredoc
|
61
|
+
"network","requested_file","rewritten_file"
|
62
|
+
"127.0.0.0/8","proxy.pac","proxy_neu.pac"
|
63
|
+
EOS
|
64
|
+
|
65
|
+
visit('/proxy.pac')
|
66
|
+
expect(page).to have_content('function FindProxyForURL(){return"PROXY localhost:3128"}')
|
67
|
+
end
|
68
|
+
|
44
69
|
it 'exits with 404 if file does not exist' do
|
45
70
|
visit('/does_not_exist.pac')
|
46
71
|
expect(page.status_code).to eq(404)
|
@@ -58,6 +83,8 @@ describe 'Fetch proxy pac', :type => :feature do
|
|
58
83
|
def local_storage
|
59
84
|
::File.join(working_directory, 'git_repo.git')
|
60
85
|
end
|
86
|
+
|
87
|
+
def translation_file; end
|
61
88
|
end.new
|
62
89
|
|
63
90
|
LocalPac.config = config
|
@@ -82,6 +109,8 @@ describe 'Fetch proxy pac', :type => :feature do
|
|
82
109
|
def local_storage
|
83
110
|
::File.join(working_directory, 'git_repo.git')
|
84
111
|
end
|
112
|
+
|
113
|
+
def translation_file; end
|
85
114
|
end.new
|
86
115
|
|
87
116
|
LocalPac.config = config
|
@@ -11,6 +11,13 @@ describe 'Lookup proxy for url' do
|
|
11
11
|
EOS
|
12
12
|
end
|
13
13
|
|
14
|
+
let(:translated_pac_file) do <<-EOS.strip_heredoc.chomp
|
15
|
+
function FindProxyForURL(url, host) {
|
16
|
+
return "PROXY localhost:3128";
|
17
|
+
}
|
18
|
+
EOS
|
19
|
+
end
|
20
|
+
|
14
21
|
let(:client_valid_pac_file) do <<-EOS.strip_heredoc.chomp
|
15
22
|
function FindProxyForURL(url, host) {
|
16
23
|
if ( MyIpAddress() == '127.0.0.5' ) {
|
@@ -42,13 +49,6 @@ describe 'Lookup proxy for url' do
|
|
42
49
|
|
43
50
|
let(:git_repo) { File.join(working_directory, 'git_repo.git') }
|
44
51
|
|
45
|
-
before :each do
|
46
|
-
repo = GitRepository.create(git_repo)
|
47
|
-
repo.add_content('file.pac', valid_pac_file)
|
48
|
-
repo.add_content('client.pac', client_valid_pac_file)
|
49
|
-
repo.add_content('time.pac', time_valid_pac_file)
|
50
|
-
end
|
51
|
-
|
52
52
|
before :each do
|
53
53
|
config = Class.new do
|
54
54
|
include FeduxOrg::Stdlib::Filesystem
|
@@ -60,35 +60,69 @@ describe 'Lookup proxy for url' do
|
|
60
60
|
def local_storage
|
61
61
|
::File.join(working_directory, 'git_repo.git')
|
62
62
|
end
|
63
|
+
|
64
|
+
def translation_file
|
65
|
+
::File.join(working_directory, 'translation.csv')
|
66
|
+
end
|
63
67
|
end.new
|
64
68
|
|
65
69
|
LocalPac.config = config
|
66
|
-
Capybara.app = LocalPac::App::LookupController
|
70
|
+
Capybara.app = LocalPac::App::LookupController.new
|
67
71
|
end
|
68
72
|
|
73
|
+
|
69
74
|
it 'looks up proxy for valid url' do
|
75
|
+
repo = GitRepository.create(git_repo)
|
76
|
+
repo.add_content('file.pac', valid_pac_file)
|
77
|
+
|
70
78
|
search_for url: 'http://www.example.org', content: 'You asked me to look up'
|
71
79
|
end
|
72
80
|
|
73
81
|
it 'looks up proxy for valid url and changes client ip' do
|
82
|
+
repo = GitRepository.create(git_repo)
|
83
|
+
repo.add_content('client.pac', client_valid_pac_file)
|
84
|
+
|
74
85
|
search_for url: 'http://www.example.org', content: 'PROXY localhost:3128', client_ip: '127.0.0.5', pac_file: '/client.pac'
|
75
86
|
end
|
76
87
|
|
77
88
|
it 'looks up proxy for valid url and changes time' do
|
89
|
+
repo = GitRepository.create(git_repo)
|
90
|
+
repo.add_content('time.pac', time_valid_pac_file)
|
91
|
+
|
78
92
|
search_for url: 'http://www.example.org', content: 'PROXY localhost:3128', time: Time.parse('2014-03-10'), pac_file: '/time.pac'
|
79
93
|
end
|
80
94
|
|
95
|
+
it 'looks up proxy for translated proxy pac' do
|
96
|
+
repo = GitRepository.create(git_repo)
|
97
|
+
repo.add_content('translated.pac', translated_pac_file)
|
98
|
+
create_file 'translation.csv', <<-EOS.strip_heredoc
|
99
|
+
"network","requested_file","rewritten_file"
|
100
|
+
"127.0.0.0/8","file.pac","translated.pac"
|
101
|
+
EOS
|
102
|
+
|
103
|
+
search_for url: 'http://www.example.org', content: 'PROXY localhost:3128'
|
104
|
+
end
|
105
|
+
|
81
106
|
it 'has a default ip' do
|
107
|
+
repo = GitRepository.create(git_repo)
|
108
|
+
repo.add_content('file.pac', valid_pac_file)
|
109
|
+
|
82
110
|
visit('/file.pac')
|
83
111
|
expect(page).to have_xpath("//input[@value='127.0.0.1']")
|
84
112
|
end
|
85
113
|
|
86
114
|
it 'has a default time' do
|
115
|
+
repo = GitRepository.create(git_repo)
|
116
|
+
repo.add_content('file.pac', valid_pac_file)
|
117
|
+
|
87
118
|
visit('/file.pac')
|
88
119
|
expect(page).to have_xpath("//input[@value='#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}']")
|
89
120
|
end
|
90
121
|
|
91
122
|
it 'returns a error message for a invalid url' do
|
123
|
+
repo = GitRepository.create(git_repo)
|
124
|
+
repo.add_content('file.pac', valid_pac_file)
|
125
|
+
|
92
126
|
visit('/file.pac')
|
93
127
|
within('#search') do
|
94
128
|
fill_in 'url', :with => '§ASDF$$'
|
@@ -98,6 +132,9 @@ describe 'Lookup proxy for url' do
|
|
98
132
|
end
|
99
133
|
|
100
134
|
it 'returns a error message for a invalid time' do
|
135
|
+
repo = GitRepository.create(git_repo)
|
136
|
+
repo.add_content('file.pac', valid_pac_file)
|
137
|
+
|
101
138
|
visit('/file.pac')
|
102
139
|
within('#search') do
|
103
140
|
fill_in 'url', :with => 'http://example.com'
|
@@ -108,6 +145,9 @@ describe 'Lookup proxy for url' do
|
|
108
145
|
end
|
109
146
|
|
110
147
|
it 'returns a error message for a invalid client ip' do
|
148
|
+
repo = GitRepository.create(git_repo)
|
149
|
+
repo.add_content('file.pac', valid_pac_file)
|
150
|
+
|
111
151
|
visit('/file.pac')
|
112
152
|
within('#search') do
|
113
153
|
fill_in 'url', :with => 'http://example.com'
|
@@ -118,6 +158,9 @@ describe 'Lookup proxy for url' do
|
|
118
158
|
end
|
119
159
|
|
120
160
|
it 'returns a error message for a invalid url on the second page' do
|
161
|
+
repo = GitRepository.create(git_repo)
|
162
|
+
repo.add_content('file.pac', valid_pac_file)
|
163
|
+
|
121
164
|
visit('/file.pac')
|
122
165
|
within('#search') do
|
123
166
|
fill_in 'url', :with => 'http://www.example.org'
|
@@ -134,6 +177,9 @@ describe 'Lookup proxy for url' do
|
|
134
177
|
end
|
135
178
|
|
136
179
|
it 'returns a error message for a invalid url' do
|
180
|
+
repo = GitRepository.create(git_repo)
|
181
|
+
repo.add_content('file.pac', valid_pac_file)
|
182
|
+
|
137
183
|
visit('/file.pac')
|
138
184
|
within('#search') do
|
139
185
|
fill_in 'url', :with => ''
|
@@ -141,6 +187,5 @@ describe 'Lookup proxy for url' do
|
|
141
187
|
click_on('Search')
|
142
188
|
expect(page).to have_content('Invalid URL...')
|
143
189
|
end
|
144
|
-
|
145
190
|
end
|
146
191
|
end
|
data/spec/git_storage_spec.rb
CHANGED
@@ -100,6 +100,7 @@ describe GitStorage do
|
|
100
100
|
|
101
101
|
vcs = double('vcs')
|
102
102
|
allow(vcs).to receive(:added_files).and_return([pac_file])
|
103
|
+
allow(vcs).to receive(:all_files).and_return([pac_file])
|
103
104
|
|
104
105
|
vcs_engine = double('vcs_engine')
|
105
106
|
allow(vcs_engine).to receive(:new).and_return(vcs)
|
data/spec/local_storage_spec.rb
CHANGED
@@ -61,5 +61,18 @@ describe LocalStorage do
|
|
61
61
|
storage = LocalStorage.new(repo)
|
62
62
|
expect(storage.find('unexist').path).to be_nil
|
63
63
|
end
|
64
|
+
|
65
|
+
it 'supports "_" in requested file name' do
|
66
|
+
file = double('File')
|
67
|
+
allow(file).to receive(:name).and_return(:file_pac1)
|
68
|
+
allow(file).to receive(:path).and_return('file_pac1.pac')
|
69
|
+
|
70
|
+
repo = double('GitRepository')
|
71
|
+
expect(repo).to receive(:[]).with(:file_pac1).and_return(file)
|
72
|
+
|
73
|
+
storage = LocalStorage.new(repo)
|
74
|
+
file = storage.find('file_pac1')
|
75
|
+
expect(file.name).to eq(:'file_pac1')
|
76
|
+
end
|
64
77
|
end
|
65
78
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -18,5 +18,10 @@ require 'local_pac/spec_helper'
|
|
18
18
|
# Loading support files
|
19
19
|
Dir.glob(::File.expand_path('../support/*.rb', __FILE__)).each { |f| require_relative f }
|
20
20
|
|
21
|
+
require File.expand_path('../../app/controllers/application_controller.rb', __FILE__)
|
22
|
+
require File.expand_path('../../app/controllers/file_serve_controller.rb', __FILE__)
|
23
|
+
require File.expand_path('../../app/controllers/lookup_controller.rb', __FILE__)
|
24
|
+
Dir.glob(::File.expand_path('../../app/controllers/*.rb', __FILE__)).each { |f| require f }
|
25
|
+
|
21
26
|
# Avoid writing "describe LocalPac::MyClass do [..]" but "describe MyClass do [..]"
|
22
27
|
include LocalPac
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe TranslationRule do
|
5
|
+
context '#initialize' do
|
6
|
+
it 'requires network, requested name and rewritten name' do
|
7
|
+
expect {
|
8
|
+
TranslationRule.new(network: '127.0.0.0/32', requested_file: 'file1.pac', rewritten_file: 'file2.pac')
|
9
|
+
}.not_to raise_error
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'supports uniquest in sets' do
|
13
|
+
set = Set.new
|
14
|
+
|
15
|
+
set << TranslationRule.new(network: '127.0.0.0/32', requested_file: 'file1.pac', rewritten_file: 'file2.pac')
|
16
|
+
set << TranslationRule.new(network: '127.0.0.0/32', requested_file: 'file1.pac', rewritten_file: 'file2.pac')
|
17
|
+
|
18
|
+
expect(set.size).to eq(1)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context '#match?' do
|
23
|
+
it 'matches if network and requested_file match' do
|
24
|
+
rule = TranslationRule.new(network: '127.0.0.0/8', requested_file: 'file1.pac', rewritten_file: 'file2.pac')
|
25
|
+
result = rule.match? '127.0.0.1', 'file1.pac'
|
26
|
+
|
27
|
+
expect(result).to be_true
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe TranslationTable do
|
5
|
+
context '#initialize' do
|
6
|
+
it 'accepts a path to translation table file' do
|
7
|
+
file = create_file 'translation.csv', <<-EOS.strip_heredoc
|
8
|
+
"network","requested_file","rewritten_file"
|
9
|
+
"127.0.0.0/8","proxy.pac","proxy_neu.pac"
|
10
|
+
EOS
|
11
|
+
|
12
|
+
expect {
|
13
|
+
TranslationTable.new(file)
|
14
|
+
}.not_to raise_error
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'logs an error message if file does not exist' do
|
18
|
+
result = capture(:stderr) do
|
19
|
+
LocalPac.ui_logger.level = :info
|
20
|
+
TranslationTable.new('asdf/file')
|
21
|
+
end
|
22
|
+
|
23
|
+
expect(result).to include('asdf/file')
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context '#rewrite' do
|
28
|
+
it 'rewrites a file name if rule exists' do
|
29
|
+
file = create_file 'translation.csv', <<-EOS.strip_heredoc
|
30
|
+
"network","requested_file","rewritten_file"
|
31
|
+
"127.0.0.0/8","proxy.pac","proxy_neu.pac"
|
32
|
+
EOS
|
33
|
+
|
34
|
+
rule = double('rule')
|
35
|
+
allow(rule).to receive(:match?).and_return(true)
|
36
|
+
allow(rule).to receive(:rewritten_file).and_return('proxy_neu.pac')
|
37
|
+
|
38
|
+
rule_engine = double('rule')
|
39
|
+
allow(rule_engine).to receive(:new).and_return(rule)
|
40
|
+
|
41
|
+
table = TranslationTable.new(file, rule_engine)
|
42
|
+
file = table.rewrite('127.0.0.1', 'proxy.pac')
|
43
|
+
|
44
|
+
expect(file).to eq('proxy_neu.pac')
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'returns the same if no rule exists' do
|
48
|
+
file = create_file 'translation.csv', <<-EOS.strip_heredoc
|
49
|
+
"network","requested_file","rewritten_file"
|
50
|
+
"127.0.0.0/8","proxy.pac","proxy_neu.pac"
|
51
|
+
EOS
|
52
|
+
|
53
|
+
rule = double('rule')
|
54
|
+
allow(rule).to receive(:match?).and_return(false)
|
55
|
+
|
56
|
+
rule_engine = double('rule')
|
57
|
+
allow(rule_engine).to receive(:new).and_return(rule)
|
58
|
+
|
59
|
+
table = TranslationTable.new(file, rule_engine)
|
60
|
+
file = table.rewrite('130.0.0.1', 'proxy.pac')
|
61
|
+
|
62
|
+
expect(file).to eq('proxy.pac')
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
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.10.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-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: thor
|
@@ -240,17 +240,17 @@ dependencies:
|
|
240
240
|
requirement: !ruby/object:Gem::Requirement
|
241
241
|
none: false
|
242
242
|
requirements:
|
243
|
-
- -
|
243
|
+
- - ~>
|
244
244
|
- !ruby/object:Gem::Version
|
245
|
-
version:
|
245
|
+
version: 0.2.0
|
246
246
|
type: :runtime
|
247
247
|
prerelease: false
|
248
248
|
version_requirements: !ruby/object:Gem::Requirement
|
249
249
|
none: false
|
250
250
|
requirements:
|
251
|
-
- -
|
251
|
+
- - ~>
|
252
252
|
- !ruby/object:Gem::Version
|
253
|
-
version:
|
253
|
+
version: 0.2.0
|
254
254
|
- !ruby/object:Gem::Dependency
|
255
255
|
name: facter
|
256
256
|
requirement: !ruby/object:Gem::Requirement
|
@@ -460,6 +460,8 @@ files:
|
|
460
460
|
- lib/local_pac/spec_helper_file_server.rb
|
461
461
|
- lib/local_pac/template_file.rb
|
462
462
|
- lib/local_pac/template_repository.rb
|
463
|
+
- lib/local_pac/translation_rule.rb
|
464
|
+
- lib/local_pac/translation_table.rb
|
463
465
|
- lib/local_pac/ui_logger.rb
|
464
466
|
- lib/local_pac/version.rb
|
465
467
|
- local_pac.gemspec
|
@@ -474,10 +476,16 @@ files:
|
|
474
476
|
- share/archlinux/config.yaml
|
475
477
|
- share/archlinux/local_pac.install
|
476
478
|
- share/archlinux/startup.erb
|
479
|
+
- share/docker/Dockerfile
|
480
|
+
- share/docker/src/ruby/gemrc
|
481
|
+
- share/docker/src/shell/ruby.sh
|
482
|
+
- share/docker/src/sudo/sudoers
|
483
|
+
- share/docker/src/zsh/.zshrc
|
477
484
|
- share/examples/config.yaml
|
478
485
|
- share/systemd/local_pac.service
|
479
486
|
- share/systemd/local_pac.socket
|
480
487
|
- share/systemd/local_pac@.service
|
488
|
+
- spec/access_logger_spec.rb
|
481
489
|
- spec/actions/add_examples_to_local_storage_spec.rb
|
482
490
|
- spec/actions/create_directory_spec.rb
|
483
491
|
- spec/actions/create_file_spec.rb
|
@@ -501,6 +509,7 @@ files:
|
|
501
509
|
- spec/data_spec.rb
|
502
510
|
- spec/erb_generator_spec.rb
|
503
511
|
- spec/error_handler_spec.rb
|
512
|
+
- spec/error_messages_spec.rb
|
504
513
|
- spec/features/check_git_push_spec.rb
|
505
514
|
- spec/features/fetch_proxy_pac_spec.rb
|
506
515
|
- spec/features/lookup_proxy_spec.rb
|
@@ -534,6 +543,8 @@ files:
|
|
534
543
|
- spec/support/string.rb
|
535
544
|
- spec/template_file_spec.rb
|
536
545
|
- spec/template_repository_spec.rb
|
546
|
+
- spec/translation_rule_spec.rb
|
547
|
+
- spec/translation_table_spec.rb
|
537
548
|
- vendor/assets/components/.keep
|
538
549
|
- vendor/assets/components/bootstrap-sass/.bower.json
|
539
550
|
- vendor/assets/components/bootstrap-sass/CNAME
|
@@ -1108,12 +1119,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
1108
1119
|
- - ! '>='
|
1109
1120
|
- !ruby/object:Gem::Version
|
1110
1121
|
version: '0'
|
1122
|
+
segments:
|
1123
|
+
- 0
|
1124
|
+
hash: 799622578968057618
|
1111
1125
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
1112
1126
|
none: false
|
1113
1127
|
requirements:
|
1114
1128
|
- - ! '>='
|
1115
1129
|
- !ruby/object:Gem::Version
|
1116
1130
|
version: '0'
|
1131
|
+
segments:
|
1132
|
+
- 0
|
1133
|
+
hash: 799622578968057618
|
1117
1134
|
requirements: []
|
1118
1135
|
rubyforge_project:
|
1119
1136
|
rubygems_version: 1.8.23
|
@@ -1126,6 +1143,7 @@ test_files:
|
|
1126
1143
|
- features/show_status.feature_
|
1127
1144
|
- features/step_definitions.rb
|
1128
1145
|
- features/support/env.rb
|
1146
|
+
- spec/access_logger_spec.rb
|
1129
1147
|
- spec/actions/add_examples_to_local_storage_spec.rb
|
1130
1148
|
- spec/actions/create_directory_spec.rb
|
1131
1149
|
- spec/actions/create_file_spec.rb
|
@@ -1149,6 +1167,7 @@ test_files:
|
|
1149
1167
|
- spec/data_spec.rb
|
1150
1168
|
- spec/erb_generator_spec.rb
|
1151
1169
|
- spec/error_handler_spec.rb
|
1170
|
+
- spec/error_messages_spec.rb
|
1152
1171
|
- spec/features/check_git_push_spec.rb
|
1153
1172
|
- spec/features/fetch_proxy_pac_spec.rb
|
1154
1173
|
- spec/features/lookup_proxy_spec.rb
|
@@ -1182,4 +1201,6 @@ test_files:
|
|
1182
1201
|
- spec/support/string.rb
|
1183
1202
|
- spec/template_file_spec.rb
|
1184
1203
|
- spec/template_repository_spec.rb
|
1204
|
+
- spec/translation_rule_spec.rb
|
1205
|
+
- spec/translation_table_spec.rb
|
1185
1206
|
has_rdoc:
|