zimbra_intercepting_proxy 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.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +38 -0
- data/Rakefile +9 -0
- data/bin/zimbra_intercepting_proxy +52 -0
- data/lib/zimbra_intercepting_proxy.rb +33 -0
- data/lib/zimbra_intercepting_proxy/backend.rb +10 -0
- data/lib/zimbra_intercepting_proxy/config.rb +74 -0
- data/lib/zimbra_intercepting_proxy/connection.rb +15 -0
- data/lib/zimbra_intercepting_proxy/debug.rb +15 -0
- data/lib/zimbra_intercepting_proxy/request.rb +46 -0
- data/lib/zimbra_intercepting_proxy/server.rb +68 -0
- data/lib/zimbra_intercepting_proxy/user.rb +60 -0
- data/lib/zimbra_intercepting_proxy/version.rb +3 -0
- data/test/fixtures/auth_80.txt +14 -0
- data/test/fixtures/route_7072.txt +9 -0
- data/test/fixtures/users.yml +6 -0
- data/test/test_backend.rb +32 -0
- data/test/test_helper.rb +11 -0
- data/test/test_request.rb +20 -0
- data/test/test_user.rb +55 -0
- data/zimbra_intercepting_proxy.gemspec +31 -0
- metadata +188 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5b8fc64cce8ebee058df8af6636304827251ff52
|
4
|
+
data.tar.gz: ac0562ae52e4aba1d0b4d33fe6cb4711ec26c8b4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9d2ef644be75708386f0fcad9e741f59500fa6887343aaeae862a8c3fb7c9acfe852ce10543187be1f8a3fe4a4315677b064009a569e02e5aa4fb30674920c0d
|
7
|
+
data.tar.gz: 02f4cba8f32ad848ed7557edbb5784f51e67f13d935bcea69e00e163766fb1114703ef89ce960d28600eee224b921283f9043f2ce142a8b411b74c242c783311
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Patricio Bruna
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# ZimbraInterceptingProxy
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
|
6
|
+
## TODO:
|
7
|
+
|
8
|
+
1. Logger
|
9
|
+
2. Iniciar con parametros
|
10
|
+
3. Iniciar el segundo plano
|
11
|
+
4. Paquetizar
|
12
|
+
|
13
|
+
|
14
|
+
## Installation
|
15
|
+
|
16
|
+
Add this line to your application's Gemfile:
|
17
|
+
|
18
|
+
gem 'zimbra_proxy_spy'
|
19
|
+
|
20
|
+
And then execute:
|
21
|
+
|
22
|
+
$ bundle
|
23
|
+
|
24
|
+
Or install it yourself as:
|
25
|
+
|
26
|
+
$ gem install zimbra_proxy_spy
|
27
|
+
|
28
|
+
## Usage
|
29
|
+
|
30
|
+
TODO: Write usage instructions here
|
31
|
+
|
32
|
+
## Contributing
|
33
|
+
|
34
|
+
1. Fork it ( https://github.com/[my-github-username]/zimbra_proxy_spy/fork )
|
35
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
36
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
37
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
38
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'zimbra_intercepting_proxy'
|
5
|
+
require 'optparse'
|
6
|
+
|
7
|
+
# host, port
|
8
|
+
ARGV << '-h' if ARGV.empty?
|
9
|
+
|
10
|
+
options = {}
|
11
|
+
|
12
|
+
optparse = OptionParser.new do |opts|
|
13
|
+
|
14
|
+
opts.banner = "Usage: zimbra_intercepting_proxy [options]"
|
15
|
+
|
16
|
+
opts.on("-dDOMAIN", "--domain=DOMAIN", "Email domain of the mailboxes") do |o|
|
17
|
+
options[:domain] = o
|
18
|
+
end
|
19
|
+
|
20
|
+
opts.on("-fFILE", "--usersfile=FILE", "YAML file with the list of migrated users") do |o|
|
21
|
+
options[:migrated_users_file] = o
|
22
|
+
end
|
23
|
+
|
24
|
+
opts.on("-omSERVER", "--oldmailbox=SERVER", "Hostname or IP of the mailbox from where we are migrating") do |o|
|
25
|
+
options[:old_backend] = o
|
26
|
+
end
|
27
|
+
|
28
|
+
opts.on("-nmSERVER", "--newmailbox=SERVER", "Hostname or IP of the mailbox to where we are migrating") do |o|
|
29
|
+
options[:new_backend] = o
|
30
|
+
end
|
31
|
+
|
32
|
+
opts.on("-baADDRESS", "--bindaddress=ADDRESS", "The IP Address to bind to. Default 0.0.0.0") do |o|
|
33
|
+
options[:bind_address] = o
|
34
|
+
end
|
35
|
+
|
36
|
+
opts.on("-bpPORT", "--bindport=PORT", "The Port to bind to. Default 0.0.0.0") do |o|
|
37
|
+
options[:bind_port] = o
|
38
|
+
end
|
39
|
+
|
40
|
+
opts.on("-v", "--verbose", "Save logs information to /var/log/zimbra_intercepting_proxy.log") do |o|
|
41
|
+
options[:debug] = true
|
42
|
+
end
|
43
|
+
|
44
|
+
opts.on("-h", "--help", "Prints this help") do
|
45
|
+
puts opts
|
46
|
+
exit
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
optparse.parse!
|
52
|
+
ZimbraInterceptingProxy.start options
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "yaml"
|
2
|
+
require "uuid"
|
3
|
+
require 'em-proxy'
|
4
|
+
require 'http/parser'
|
5
|
+
require "addressable/uri"
|
6
|
+
require 'logger'
|
7
|
+
require "zimbra_intercepting_proxy/version"
|
8
|
+
require "zimbra_intercepting_proxy/user"
|
9
|
+
require "zimbra_intercepting_proxy/config"
|
10
|
+
require "zimbra_intercepting_proxy/backend"
|
11
|
+
require "zimbra_intercepting_proxy/request"
|
12
|
+
require "zimbra_intercepting_proxy/server"
|
13
|
+
require "zimbra_intercepting_proxy/debug"
|
14
|
+
require "zimbra_intercepting_proxy/connection"
|
15
|
+
|
16
|
+
module ZimbraInterceptingProxy
|
17
|
+
|
18
|
+
def self.start(options)
|
19
|
+
config!(options)
|
20
|
+
ZimbraInterceptingProxy::Server.run
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.config!(options)
|
24
|
+
ZimbraInterceptingProxy::Config.domain = options[:domain]
|
25
|
+
ZimbraInterceptingProxy::Config.migrated_users_file = options[:migrated_users_file]
|
26
|
+
ZimbraInterceptingProxy::Config.old_backend = options[:old_backend]
|
27
|
+
ZimbraInterceptingProxy::Config.new_backend = options[:new_backend]
|
28
|
+
ZimbraInterceptingProxy::Config.bind_address = options[:bind_address] || "0.0.0.0"
|
29
|
+
ZimbraInterceptingProxy::Config.bind_port = options[:bind_port]
|
30
|
+
ZimbraInterceptingProxy::Config.debug = options[:debug]
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module ZimbraInterceptingProxy
|
2
|
+
module Config
|
3
|
+
attr_accessor :new_backend, :old_backend
|
4
|
+
|
5
|
+
ROUTE_URL = "/service/extension/nginx-lookup"
|
6
|
+
ROUTE_REQUEST_PORT = 7072
|
7
|
+
AUTH_REQUEST_PORT = 80
|
8
|
+
|
9
|
+
def self.domain=(domain)
|
10
|
+
@domain = domain
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.domain
|
14
|
+
@domain
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.migrated_users_file=(file)
|
18
|
+
@migrated_users_file = file
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.migrated_users_file
|
22
|
+
@migrated_users_file
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.backend_port=(port)
|
26
|
+
@backend_port
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.backend_port
|
30
|
+
@backend_port
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.old_backend=(old_backend)
|
34
|
+
@old_backend = old_backend
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.new_backend=(new_backend)
|
38
|
+
@new_backend = new_backend
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.old_backend
|
42
|
+
@old_backend
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.new_backend
|
46
|
+
@new_backend
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.bind_port=(bind_port)
|
50
|
+
@bind_port = bind_port
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.bind_port
|
54
|
+
@bind_port
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.bind_address=(bind_address)
|
58
|
+
@bind_address = bind_address
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.bind_address
|
62
|
+
@bind_address
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.debug=(debug)
|
66
|
+
@debug = debug
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.debug
|
70
|
+
@debug
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module ZimbraInterceptingProxy
|
2
|
+
class Request
|
3
|
+
require 'pp'
|
4
|
+
|
5
|
+
attr_accessor :body, :headers, :parser
|
6
|
+
|
7
|
+
def initialize(connection, parser)
|
8
|
+
@body = connection.body
|
9
|
+
@headers = connection.headers
|
10
|
+
@parser = parser
|
11
|
+
end
|
12
|
+
|
13
|
+
def auth_request?
|
14
|
+
@parser.http_method == "POST" && @parser.request_url == "/zimbra/" && @headers["Cookie"] = "ZM_TEST=true" && auth_request_params?
|
15
|
+
end
|
16
|
+
|
17
|
+
def auth_request_params?
|
18
|
+
uri = Addressable::URI.parse("http://localhost/?#{@body}")
|
19
|
+
uri.query_values["loginOp"] == "login"
|
20
|
+
end
|
21
|
+
|
22
|
+
def route_request?
|
23
|
+
@parser.request_url == ZimbraInterceptingProxy::Config::ROUTE_URL
|
24
|
+
end
|
25
|
+
|
26
|
+
def port
|
27
|
+
return ZimbraInterceptingProxy::Config::ROUTE_REQUEST_PORT if route_request?
|
28
|
+
return ZimbraInterceptingProxy::Config::AUTH_REQUEST_PORT if auth_request?
|
29
|
+
end
|
30
|
+
|
31
|
+
def user_token
|
32
|
+
return auth_username if auth_request?
|
33
|
+
return auth_zimbraId if route_request?
|
34
|
+
end
|
35
|
+
|
36
|
+
def auth_zimbraId
|
37
|
+
headers["Auth-User"]
|
38
|
+
end
|
39
|
+
|
40
|
+
def auth_username
|
41
|
+
uri = Addressable::URI.parse("http://localhost/?#{@body}")
|
42
|
+
uri.query_values["username"]
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module ZimbraInterceptingProxy
|
2
|
+
|
3
|
+
module Server
|
4
|
+
require 'pp'
|
5
|
+
|
6
|
+
def run
|
7
|
+
debug = ZimbraInterceptingProxy::Debug
|
8
|
+
host = ZimbraInterceptingProxy::Config.bind_address
|
9
|
+
port = ZimbraInterceptingProxy::Config.bind_port
|
10
|
+
|
11
|
+
Proxy.start(:host => host, :port => port) do |conn|
|
12
|
+
|
13
|
+
debug.logger "Starting server on #{host}:#{port}"
|
14
|
+
|
15
|
+
@backend = {host: ZimbraInterceptingProxy::Config.old_backend, port: 80}
|
16
|
+
connection = ZimbraInterceptingProxy::Connection.new
|
17
|
+
|
18
|
+
@parser = Http::Parser.new
|
19
|
+
@parser.on_message_begin = proc{ connection.started = true }
|
20
|
+
@parser.on_headers_complete = proc { |e| connection.headers = e }
|
21
|
+
@parser.on_body = proc { |chunk| connection.body << chunk }
|
22
|
+
@parser.on_message_complete = proc do |p|
|
23
|
+
|
24
|
+
request = ZimbraInterceptingProxy::Request.new(connection, @parser)
|
25
|
+
|
26
|
+
if request.auth_request? || request.route_request?
|
27
|
+
user = User.new(request.user_token)
|
28
|
+
@backend[:host] = user.backend if user.migrated?
|
29
|
+
@backend[:port] = request.port
|
30
|
+
end
|
31
|
+
|
32
|
+
conn.server @backend[:host], :host => @backend[:host], :port => @backend[:port]
|
33
|
+
conn.relay_to_servers connection.buffer
|
34
|
+
|
35
|
+
connection.buffer.clear
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
conn.on_connect do |data,b|
|
40
|
+
debug.logger [:on_connect, data, b]
|
41
|
+
end
|
42
|
+
|
43
|
+
conn.on_data do |data|
|
44
|
+
debug.logger [:on_data, data]
|
45
|
+
connection.buffer << data
|
46
|
+
@parser << data
|
47
|
+
|
48
|
+
data
|
49
|
+
end
|
50
|
+
|
51
|
+
conn.on_response do |backend, resp|
|
52
|
+
new_resp = resp.gsub(/Auth-Server: .*/, "Auth-Server: #{ZimbraInterceptingProxy::Config.new_backend}")
|
53
|
+
debug.logger [:on_response, backend, new_resp]
|
54
|
+
new_resp
|
55
|
+
end
|
56
|
+
|
57
|
+
conn.on_finish do |backend, name|
|
58
|
+
debug.logger [:on_finish, name].inspect
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
module_function :run
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module ZimbraInterceptingProxy
|
2
|
+
|
3
|
+
class User
|
4
|
+
attr_accessor :email, :zimbraId
|
5
|
+
|
6
|
+
# user_identifier can be an email address, zimbraId UUID or just the
|
7
|
+
# local part of an email address, like user in user@example.com
|
8
|
+
def initialize(user_identifier)
|
9
|
+
@zimbraId = set_zimbraId user_identifier
|
10
|
+
@email = set_email user_identifier
|
11
|
+
User.load_migrated_users
|
12
|
+
end
|
13
|
+
|
14
|
+
# If user has email (unless email.nil?)
|
15
|
+
def migrated?
|
16
|
+
!find_in_db.nil?
|
17
|
+
end
|
18
|
+
|
19
|
+
def backend
|
20
|
+
return ZimbraInterceptingProxy::Config.new_backend if migrated?
|
21
|
+
ZimbraInterceptingProxy::Config.old_backend
|
22
|
+
end
|
23
|
+
|
24
|
+
def find_in_db
|
25
|
+
return User.DB[email] if has_email?
|
26
|
+
return User.DB.invert[zimbraId] if has_zimbraId?
|
27
|
+
end
|
28
|
+
|
29
|
+
def has_email?
|
30
|
+
!email.nil?
|
31
|
+
end
|
32
|
+
|
33
|
+
def has_zimbraId?
|
34
|
+
!zimbraId.nil?
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.load_migrated_users
|
38
|
+
YAML.load_file ZimbraInterceptingProxy::Config.migrated_users_file
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.DB
|
42
|
+
load_migrated_users
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
def set_zimbraId user_identifier
|
47
|
+
return user_identifier if UUID.validate user_identifier
|
48
|
+
nil
|
49
|
+
end
|
50
|
+
|
51
|
+
def set_email user_identifier
|
52
|
+
return user_identifier if user_identifier.match(/@/)
|
53
|
+
return "#{user_identifier}@#{ZimbraInterceptingProxy::Config.domain}" unless UUID.validate user_identifier
|
54
|
+
nil
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
POST /zimbra/ HTTP/1.0
|
2
|
+
X-Forwarded-For: 186.67.32.114
|
3
|
+
Host: 200.91.20.185
|
4
|
+
Connection: close
|
5
|
+
Content-Type: application/x-www-form-urlencoded
|
6
|
+
Origin: http://190.196.208.85
|
7
|
+
Cookie: ZM_TEST=true; ZM_TEST=true
|
8
|
+
Content-Length: 66
|
9
|
+
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
|
10
|
+
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/600.5.17 (KHTML, like Gecko) Version/8.0.5 Safari/600.5.17
|
11
|
+
Accept-Language: es-es
|
12
|
+
Accept-Encoding: gzip, deflate
|
13
|
+
|
14
|
+
loginOp=login&username=pbruna&password=5693537374&client=preferred
|
@@ -0,0 +1,6 @@
|
|
1
|
+
pato@example.com: "7b562ae0-be97-0132-9a66-482a1423458f"
|
2
|
+
max@example.com: "7b562c60-be97-0132-9a66-482a1423458f"
|
3
|
+
moliery@example.com: "7b562ce0-be97-0132-9a66-482a1423458f"
|
4
|
+
watson@example.com: "251b1902-2250-4477-bdd1-8a101f7e7e4e"
|
5
|
+
sherlock@example.com: "7b562dd0-be97-0132-9a66-482a1423458f"
|
6
|
+
pbruna@itlinux.cl: "cfd6e914-4f00-440c-9a57-e1a9327128b9"
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class Backend < Minitest::Test
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@user_migrated_email = ZimbraInterceptingProxy::User.new("watson@example.com")
|
7
|
+
@user_migrated_zimbraId = ZimbraInterceptingProxy::User.new("251b1902-2250-4477-bdd1-8a101f7e7e4e")
|
8
|
+
@user_not_migrated_email = ZimbraInterceptingProxy::User.new("jackbower@example.com")
|
9
|
+
@user_not_migrated_zimbraId = ZimbraInterceptingProxy::User.new("251b1902-2250-4477-bdd1-8a101f7e7333")
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_should_return_old_backend_if_user_email_is_not_migrated
|
13
|
+
backend = ZimbraInterceptingProxy::Backend.for_user @user_not_migrated_email
|
14
|
+
assert_equal(ZimbraInterceptingProxy::Config.old_backend, backend)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_should_return_old_backend_if_user_zimbraID_is_not_migrated
|
18
|
+
backend = ZimbraInterceptingProxy::Backend.for_user @user_not_migrated_zimbraId
|
19
|
+
assert_equal(ZimbraInterceptingProxy::Config.old_backend, backend)
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_should_return_new_backend_if_user_email_was_migrated
|
23
|
+
backend = ZimbraInterceptingProxy::Backend.for_user @user_migrated_email
|
24
|
+
assert_equal(ZimbraInterceptingProxy::Config.new_backend, backend)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_should_return_new_backend_if_user_zimbraID_was_migrated
|
28
|
+
backend = ZimbraInterceptingProxy::Backend.for_user @user_migrated_zimbraId
|
29
|
+
assert_equal(ZimbraInterceptingProxy::Config.new_backend, backend)
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require "zimbra_intercepting_proxy"
|
2
|
+
|
3
|
+
require 'minitest/autorun'
|
4
|
+
require 'minitest/reporters' # requires the gem
|
5
|
+
|
6
|
+
Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new # spec-like progress
|
7
|
+
|
8
|
+
ZimbraInterceptingProxy::Config.domain="example.com"
|
9
|
+
ZimbraInterceptingProxy::Config.migrated_users_file="./test/fixtures/users.yml"
|
10
|
+
ZimbraInterceptingProxy::Config.old_backend = "old-mailbox.example.com"
|
11
|
+
ZimbraInterceptingProxy::Config.new_backend = "new-mailbox.zboxapp.com"
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class Request < Minitest::Test
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@auth_request = IO.read("./test/fixtures/auth_80.txt")
|
7
|
+
@route_request = IO.read("./test/fixtures/route_7072.txt")
|
8
|
+
end
|
9
|
+
|
10
|
+
# def test_should_return_user_token_from_auth_request
|
11
|
+
# request = ZimbraInterceptingProxy::Request.new @auth_request
|
12
|
+
# assert_equal("pbruna", request.user_token)
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
# def test_should_return_user_token_from_route_request
|
16
|
+
# request = ZimbraInterceptingProxy::Request.new @route_request
|
17
|
+
# assert_equal("251b1902-2250-4477-bdd1-8a101f7e7e4e", request.user_token)
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
end
|
data/test/test_user.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class User < Minitest::Test
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@user = {email: "watson@example.com", zimbraId: "251b1902-2250-4477-bdd1-8a101f7e7e4e"}
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_only_set_zimbraId_when_passed_a_zimbraId
|
10
|
+
u = ZimbraInterceptingProxy::User.new(@user[:zimbraId])
|
11
|
+
assert_equal(u.zimbraId, @user[:zimbraId])
|
12
|
+
assert_nil(u.email)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_only_set_email_when_passed_an_email
|
16
|
+
u = ZimbraInterceptingProxy::User.new(@user[:email])
|
17
|
+
assert_equal(u.email, @user[:email])
|
18
|
+
assert_nil(u.zimbraId)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_return_email_when_passed_just_an_username
|
22
|
+
u = ZimbraInterceptingProxy::User.new("watson")
|
23
|
+
assert_equal(u.email, @user[:email])
|
24
|
+
assert_nil(u.zimbraId)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_should_load_db_user_file_to_global_hash
|
28
|
+
assert_equal(ZimbraInterceptingProxy::User.DB.class, Hash)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_db_should_have_emails_when_email_is_passed
|
32
|
+
assert(ZimbraInterceptingProxy::User.DB["watson@example.com"])
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_return_true_if_migrated_user_with_zimbraId
|
36
|
+
u = ZimbraInterceptingProxy::User.new("7b562ce0-be97-0132-9a66-482a1423458f")
|
37
|
+
assert(u.migrated?, "Failure message.")
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_return_false_if_not_migrated_user_with_zimbraId
|
41
|
+
u = ZimbraInterceptingProxy::User.new("7b562ce0-be97-0132-9a66-482a14234333")
|
42
|
+
assert(!u.migrated?, "Failure message.")
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_return_true_if_migrated_user_with_email
|
46
|
+
u = ZimbraInterceptingProxy::User.new(@user[:email])
|
47
|
+
assert(u.migrated?, "Failure message.")
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_return_false_if_no_migrated_user_with_email
|
51
|
+
u = ZimbraInterceptingProxy::User.new("pbruna")
|
52
|
+
assert(!u.migrated?, "Failure message.")
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'zimbra_intercepting_proxy/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "zimbra_intercepting_proxy"
|
8
|
+
spec.version = ZimbraInterceptingProxy::VERSION
|
9
|
+
spec.authors = ["Patricio Bruna"]
|
10
|
+
spec.email = ["pbruna@itlinux.cl"]
|
11
|
+
spec.summary = "A HTTP intercepting Proxy for the Zimbra Proxy"
|
12
|
+
spec.description = spec.summary
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency 'em-proxy'
|
22
|
+
spec.add_dependency 'thor'
|
23
|
+
spec.add_dependency 'uuid'
|
24
|
+
spec.add_dependency 'http_parser.rb'
|
25
|
+
spec.add_dependency 'addressable'
|
26
|
+
|
27
|
+
|
28
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
29
|
+
spec.add_development_dependency "rake"
|
30
|
+
spec.add_development_dependency "minitest-reporters"
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,188 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: zimbra_intercepting_proxy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Patricio Bruna
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: em-proxy
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: thor
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: uuid
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: http_parser.rb
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: addressable
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: bundler
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.6'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.6'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rake
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: minitest-reporters
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
description: A HTTP intercepting Proxy for the Zimbra Proxy
|
126
|
+
email:
|
127
|
+
- pbruna@itlinux.cl
|
128
|
+
executables:
|
129
|
+
- zimbra_intercepting_proxy
|
130
|
+
extensions: []
|
131
|
+
extra_rdoc_files: []
|
132
|
+
files:
|
133
|
+
- ".gitignore"
|
134
|
+
- Gemfile
|
135
|
+
- LICENSE.txt
|
136
|
+
- README.md
|
137
|
+
- Rakefile
|
138
|
+
- bin/zimbra_intercepting_proxy
|
139
|
+
- lib/zimbra_intercepting_proxy.rb
|
140
|
+
- lib/zimbra_intercepting_proxy/backend.rb
|
141
|
+
- lib/zimbra_intercepting_proxy/config.rb
|
142
|
+
- lib/zimbra_intercepting_proxy/connection.rb
|
143
|
+
- lib/zimbra_intercepting_proxy/debug.rb
|
144
|
+
- lib/zimbra_intercepting_proxy/request.rb
|
145
|
+
- lib/zimbra_intercepting_proxy/server.rb
|
146
|
+
- lib/zimbra_intercepting_proxy/user.rb
|
147
|
+
- lib/zimbra_intercepting_proxy/version.rb
|
148
|
+
- test/fixtures/auth_80.txt
|
149
|
+
- test/fixtures/route_7072.txt
|
150
|
+
- test/fixtures/users.yml
|
151
|
+
- test/test_backend.rb
|
152
|
+
- test/test_helper.rb
|
153
|
+
- test/test_request.rb
|
154
|
+
- test/test_user.rb
|
155
|
+
- zimbra_intercepting_proxy.gemspec
|
156
|
+
homepage: ''
|
157
|
+
licenses:
|
158
|
+
- MIT
|
159
|
+
metadata: {}
|
160
|
+
post_install_message:
|
161
|
+
rdoc_options: []
|
162
|
+
require_paths:
|
163
|
+
- lib
|
164
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
165
|
+
requirements:
|
166
|
+
- - ">="
|
167
|
+
- !ruby/object:Gem::Version
|
168
|
+
version: '0'
|
169
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
requirements: []
|
175
|
+
rubyforge_project:
|
176
|
+
rubygems_version: 2.2.2
|
177
|
+
signing_key:
|
178
|
+
specification_version: 4
|
179
|
+
summary: A HTTP intercepting Proxy for the Zimbra Proxy
|
180
|
+
test_files:
|
181
|
+
- test/fixtures/auth_80.txt
|
182
|
+
- test/fixtures/route_7072.txt
|
183
|
+
- test/fixtures/users.yml
|
184
|
+
- test/test_backend.rb
|
185
|
+
- test/test_helper.rb
|
186
|
+
- test/test_request.rb
|
187
|
+
- test/test_user.rb
|
188
|
+
has_rdoc:
|