badcarl-integrity-jabber 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.
- data/.gitignore +1 -0
- data/LICENSE +20 -0
- data/README.rdoc +7 -0
- data/Rakefile +34 -0
- data/VERSION +1 -0
- data/integrity-jabber.gemspec +55 -0
- data/lib/integrity/notifier/config.haml +21 -0
- data/lib/integrity/notifier/jabber.rb +42 -0
- data/test/remote/integrity-jabber-test-config.yml.sample +10 -0
- data/test/remote/integrity_jabber_remote_test.rb +98 -0
- data/test/test_helper.rb +20 -0
- data/test/unit/integrity_jabber_test.rb +79 -0
- metadata +86 -0
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
.DS_Store
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Carl Porth
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "integrity-jabber"
|
8
|
+
gem.summary = %Q{A jabber notifier for integrity}
|
9
|
+
gem.email = "badcarl@gmail.com"
|
10
|
+
gem.homepage = "http://github.com/badcarl/integrity-jabber"
|
11
|
+
gem.authors = ["Carl Porth"]
|
12
|
+
gem.add_dependency 'integrity'
|
13
|
+
gem.add_dependency 'xmpp4r'
|
14
|
+
end
|
15
|
+
|
16
|
+
rescue LoadError
|
17
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
18
|
+
end
|
19
|
+
|
20
|
+
require 'rake/testtask'
|
21
|
+
Rake::TestTask.new('test:unit') do |test|
|
22
|
+
test.libs << 'lib' << 'test'
|
23
|
+
test.pattern = 'test/unit/**/*_test.rb'
|
24
|
+
test.verbose = true
|
25
|
+
end
|
26
|
+
|
27
|
+
Rake::TestTask.new('test:remote') do |test|
|
28
|
+
test.libs << 'lib' << 'test'
|
29
|
+
test.pattern = 'test/remote/**/*_test.rb'
|
30
|
+
test.verbose = true
|
31
|
+
end
|
32
|
+
|
33
|
+
task :test => 'test:unit'
|
34
|
+
task :default => :test
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.2
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{integrity-jabber}
|
5
|
+
s.version = "0.0.2"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Carl Porth"]
|
9
|
+
s.date = %q{2009-07-03}
|
10
|
+
s.email = %q{badcarl@gmail.com}
|
11
|
+
s.extra_rdoc_files = [
|
12
|
+
"LICENSE",
|
13
|
+
"README.rdoc"
|
14
|
+
]
|
15
|
+
s.files = [
|
16
|
+
".gitignore",
|
17
|
+
"LICENSE",
|
18
|
+
"README.rdoc",
|
19
|
+
"Rakefile",
|
20
|
+
"VERSION",
|
21
|
+
"integrity-jabber.gemspec",
|
22
|
+
"lib/integrity/notifier/config.haml",
|
23
|
+
"lib/integrity/notifier/jabber.rb",
|
24
|
+
"test/remote/integrity-jabber-test-config.yml.sample",
|
25
|
+
"test/remote/integrity_jabber_remote_test.rb",
|
26
|
+
"test/test_helper.rb",
|
27
|
+
"test/unit/integrity_jabber_test.rb"
|
28
|
+
]
|
29
|
+
s.homepage = %q{http://github.com/badcarl/integrity-jabber}
|
30
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
31
|
+
s.require_paths = ["lib"]
|
32
|
+
s.rubygems_version = %q{1.3.3}
|
33
|
+
s.summary = %q{A jabber notifier for integrity}
|
34
|
+
s.test_files = [
|
35
|
+
"test/remote/integrity_jabber_remote_test.rb",
|
36
|
+
"test/test_helper.rb",
|
37
|
+
"test/unit/integrity_jabber_test.rb"
|
38
|
+
]
|
39
|
+
|
40
|
+
if s.respond_to? :specification_version then
|
41
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
42
|
+
s.specification_version = 3
|
43
|
+
|
44
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
45
|
+
s.add_runtime_dependency(%q<integrity>, [">= 0"])
|
46
|
+
s.add_runtime_dependency(%q<xmpp4r>, [">= 0"])
|
47
|
+
else
|
48
|
+
s.add_dependency(%q<integrity>, [">= 0"])
|
49
|
+
s.add_dependency(%q<xmpp4r>, [">= 0"])
|
50
|
+
end
|
51
|
+
else
|
52
|
+
s.add_dependency(%q<integrity>, [">= 0"])
|
53
|
+
s.add_dependency(%q<xmpp4r>, [">= 0"])
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
%h3 Jabber Server Configuration
|
2
|
+
|
3
|
+
%p.normal
|
4
|
+
%label{ :for => "jabber_notifier_jid" } Jabber ID
|
5
|
+
%input.text#jabber_notifier_jid{ :name => "notifiers[Jabber][jid]", :value => config["jid"], :type => "text" }
|
6
|
+
|
7
|
+
%p.normal
|
8
|
+
%label{ :for => "jabber_notifier_password" } Password
|
9
|
+
%input.text#jabber_notifier_password{ :name => "notifiers[Jabber][password]", :value => config["password"], :type => "text" }
|
10
|
+
|
11
|
+
%p.normal
|
12
|
+
%label{ :for => "jabber_notifier_to" } To
|
13
|
+
%input.text#jabber_notifier_to{ :name => "notifiers[Jabber][to]", :value => config["to"], :type => "text" }
|
14
|
+
|
15
|
+
%p.normal
|
16
|
+
%label{ :for => "jabber_notifier_server" } Server
|
17
|
+
%input.text#jabber_notifier_server{ :name => "notifiers[Jabber][server]", :value => config["server"], :type => "text" }
|
18
|
+
|
19
|
+
%p.normal
|
20
|
+
%label{ :for => "jabber_notifier_port" } Port
|
21
|
+
%input.text#jabber_notifier_port{ :name => "notifiers[Jabber][port]", :value => config["port"], :type => "text" }
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require "integrity"
|
2
|
+
require "xmpp4r"
|
3
|
+
|
4
|
+
module Integrity
|
5
|
+
class Notifier
|
6
|
+
class Jabber < Notifier::Base
|
7
|
+
|
8
|
+
def self.to_haml
|
9
|
+
File.read(File.dirname(__FILE__) + "/config.haml")
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize(commit, config={})
|
13
|
+
super(commit, config)
|
14
|
+
|
15
|
+
@client = ::Jabber::Client.new(config.delete('jid'))
|
16
|
+
@password = config.delete('password')
|
17
|
+
@port = config.delete('port')
|
18
|
+
@server = config.delete('server')
|
19
|
+
@to = config.delete('to').split(/\s+/)
|
20
|
+
|
21
|
+
@server = nil if @server.blank?
|
22
|
+
@port = 5222 if @port.blank?
|
23
|
+
end
|
24
|
+
|
25
|
+
def deliver!
|
26
|
+
@client.connect(@server, @port.to_i)
|
27
|
+
@client.auth(@password)
|
28
|
+
|
29
|
+
@to.each do |to|
|
30
|
+
message = ::Jabber::Message.new(to, full_message)
|
31
|
+
message.type = :chat
|
32
|
+
@client.send(message)
|
33
|
+
end
|
34
|
+
|
35
|
+
@client.close
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
register Jabber
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class IntegrityJabberRemoteTest < Test::Unit::TestCase
|
4
|
+
include Integrity::Notifier::Test
|
5
|
+
|
6
|
+
CONFIG_FILE = ENV['JABBER_CONFIG'] || '~/.integrity-jabber-test-config.yml'
|
7
|
+
|
8
|
+
def notifier
|
9
|
+
"Jabber"
|
10
|
+
end
|
11
|
+
|
12
|
+
def setup
|
13
|
+
begin
|
14
|
+
@test_config = File.open(File.expand_path(CONFIG_FILE)) do |io|
|
15
|
+
YAML::load(io)
|
16
|
+
end
|
17
|
+
raise unless @test_config
|
18
|
+
rescue => e
|
19
|
+
puts "Place a yaml file at #{CONFIG_FILE} with jabber test config, for example:"
|
20
|
+
puts File.read(File.dirname(__FILE__) + '/integrity-jabber-test-config.yml.sample')
|
21
|
+
raise e
|
22
|
+
end
|
23
|
+
|
24
|
+
%w[ notifier receiver ].each do |client|
|
25
|
+
@test_config[client] or raise "Need to configure #{client}: in #{CONFIG_FILE}"
|
26
|
+
%w[ jid password server port ].each do |key|
|
27
|
+
@test_config[client][key] or raise "Need to configure #{client}: #{key}: in #{CONFIG_FILE}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
setup_database
|
32
|
+
|
33
|
+
@notifier_config = {
|
34
|
+
'jid' => @test_config['notifier']['jid'],
|
35
|
+
'password' => @test_config['notifier']['password'],
|
36
|
+
'server' => @test_config['notifier']['server'],
|
37
|
+
'port' => @test_config['notifier']['port'],
|
38
|
+
|
39
|
+
'to' => @test_config['receiver']['jid']
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_it_sends_successful_jabber_notification
|
44
|
+
successful = Integrity::Commit.gen(:successful)
|
45
|
+
|
46
|
+
message = deliver(successful)
|
47
|
+
|
48
|
+
assert_not_nil message
|
49
|
+
|
50
|
+
assert_equal @test_config['receiver']['jid'], message.to.to_s
|
51
|
+
assert_equal @test_config['notifier']['jid'], message.from.to_s
|
52
|
+
|
53
|
+
assert message.body.include?("successful")
|
54
|
+
assert message.body.include?(successful.committed_at.to_s)
|
55
|
+
assert message.body.include?(successful.author.name)
|
56
|
+
assert message.body.include?(successful.output)
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_it_sends_failed_jabber_notification
|
60
|
+
failed = Integrity::Commit.gen(:failed)
|
61
|
+
|
62
|
+
message = deliver(failed)
|
63
|
+
|
64
|
+
assert_not_nil message
|
65
|
+
|
66
|
+
assert_equal @test_config['receiver']['jid'], message.to.to_s
|
67
|
+
assert_equal @test_config['notifier']['jid'], message.from.to_s
|
68
|
+
|
69
|
+
assert message.body.include?("failed")
|
70
|
+
assert message.body.include?(failed.committed_at.to_s)
|
71
|
+
assert message.body.include?(failed.author.name)
|
72
|
+
assert message.body.include?(failed.output)
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
def deliver(commit)
|
78
|
+
receiver = ::Jabber::Client.new(@test_config['receiver']['jid'])
|
79
|
+
receiver.add_message_callback do |message|
|
80
|
+
Thread.main[:message] = message
|
81
|
+
Thread.main.wakeup
|
82
|
+
end
|
83
|
+
|
84
|
+
Timeout::timeout(15) do
|
85
|
+
receiver.connect(@test_config['receiver']['server'], @test_config['receiver']['port'])
|
86
|
+
receiver.auth(@test_config['receiver']['password'])
|
87
|
+
receiver.send(::Jabber::Presence.new(nil, nil, 127))
|
88
|
+
|
89
|
+
Integrity::Notifier::Jabber.new(commit, @notifier_config.dup).deliver!
|
90
|
+
Thread.stop # wait to be woken up by callback
|
91
|
+
end
|
92
|
+
|
93
|
+
Thread.current[:message]
|
94
|
+
ensure
|
95
|
+
receiver.close
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
$:.unshift File.dirname(__FILE__) + "/../lib", File.dirname(__FILE__)
|
2
|
+
|
3
|
+
require "rubygems"
|
4
|
+
|
5
|
+
if dm_version = ENV['DM_VERSION']
|
6
|
+
gem 'dm-core', dm_version
|
7
|
+
gem 'dm-sweatshop', dm_version
|
8
|
+
gem 'dm-validations', dm_version
|
9
|
+
gem 'dm-types', dm_version
|
10
|
+
gem 'dm-timestamps', dm_version
|
11
|
+
gem 'dm-aggregates', dm_version
|
12
|
+
end
|
13
|
+
|
14
|
+
require "integrity"
|
15
|
+
require "integrity/notifier/test"
|
16
|
+
require "integrity/notifier/jabber"
|
17
|
+
|
18
|
+
require "test/unit"
|
19
|
+
require "xmpp4r"
|
20
|
+
require "mocha"
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class IntegrityJabberTest < Test::Unit::TestCase
|
4
|
+
include Integrity::Notifier::Test
|
5
|
+
|
6
|
+
def notifier
|
7
|
+
"Jabber"
|
8
|
+
end
|
9
|
+
|
10
|
+
def setup
|
11
|
+
setup_database
|
12
|
+
|
13
|
+
@config = {
|
14
|
+
'jid' => 'notifier@localhost',
|
15
|
+
'password' => 'secret',
|
16
|
+
'to' => 'receiver@localhost'
|
17
|
+
}
|
18
|
+
|
19
|
+
@commit = Integrity::Commit.gen(:successful)
|
20
|
+
|
21
|
+
@client = stub_everything('jabber_client', :send => nil)
|
22
|
+
::Jabber::Client.stubs(:new).returns(@client)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_configuration_form
|
26
|
+
assert form_have_tag?("h3", :content => "Jabber Server Configuration")
|
27
|
+
|
28
|
+
assert provides_option?("jid", "foo@example.org")
|
29
|
+
assert provides_option?("password", "secret")
|
30
|
+
assert provides_option?("server", "example.org")
|
31
|
+
assert provides_option?("port", "5222")
|
32
|
+
assert provides_option?("to", "bar@example.org")
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_configuration_with_server
|
36
|
+
@client.expects(:connect).with('example.com', anything)
|
37
|
+
|
38
|
+
Integrity::Notifier::Jabber.new(@commit, @config.merge('server' => 'example.com')).deliver!
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_configuration_without_server
|
42
|
+
@client.expects(:connect).with(nil, anything)
|
43
|
+
|
44
|
+
Integrity::Notifier::Jabber.new(@commit, @config.merge('server' => '')).deliver!
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_configuration_with_port
|
48
|
+
@client.expects(:connect).with(anything, 5223)
|
49
|
+
|
50
|
+
Integrity::Notifier::Jabber.new(@commit, @config.merge('port' => '5223')).deliver!
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_configuration_without_port
|
54
|
+
@client.expects(:connect).with(anything, 5222)
|
55
|
+
|
56
|
+
Integrity::Notifier::Jabber.new(@commit, @config.merge('port' => '')).deliver!
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_sends_messages
|
60
|
+
@client.expects(:send).with { |message| message.to.to_s == 'client@localhost' }
|
61
|
+
|
62
|
+
Integrity::Notifier::Jabber.new(@commit, @config.merge('to' => 'client@localhost')).deliver!
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_sends_multiple_messages
|
66
|
+
@client.expects(:send).with { |message| message.to.to_s == 'client1@localhost' }
|
67
|
+
@client.expects(:send).with { |message| message.to.to_s == 'client2@localhost/test' }
|
68
|
+
@client.expects(:send).with { |message| message.to.to_s == 'client3@localhost/resource' }
|
69
|
+
|
70
|
+
Integrity::Notifier::Jabber.new(@commit, @config.merge('to' => 'client1@localhost client2@localhost/test client3@localhost/resource')).deliver!
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_closes_connection
|
74
|
+
@client.expects(:close)
|
75
|
+
|
76
|
+
Integrity::Notifier::Jabber.new(@commit, @config).deliver!
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: badcarl-integrity-jabber
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Carl Porth
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-07-03 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: integrity
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: xmpp4r
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
version:
|
35
|
+
description:
|
36
|
+
email: badcarl@gmail.com
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- LICENSE
|
43
|
+
- README.rdoc
|
44
|
+
files:
|
45
|
+
- .gitignore
|
46
|
+
- LICENSE
|
47
|
+
- README.rdoc
|
48
|
+
- Rakefile
|
49
|
+
- VERSION
|
50
|
+
- integrity-jabber.gemspec
|
51
|
+
- lib/integrity/notifier/config.haml
|
52
|
+
- lib/integrity/notifier/jabber.rb
|
53
|
+
- test/remote/integrity-jabber-test-config.yml.sample
|
54
|
+
- test/remote/integrity_jabber_remote_test.rb
|
55
|
+
- test/test_helper.rb
|
56
|
+
- test/unit/integrity_jabber_test.rb
|
57
|
+
has_rdoc: false
|
58
|
+
homepage: http://github.com/badcarl/integrity-jabber
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options:
|
61
|
+
- --charset=UTF-8
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: "0"
|
69
|
+
version:
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: "0"
|
75
|
+
version:
|
76
|
+
requirements: []
|
77
|
+
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 1.2.0
|
80
|
+
signing_key:
|
81
|
+
specification_version: 3
|
82
|
+
summary: A jabber notifier for integrity
|
83
|
+
test_files:
|
84
|
+
- test/remote/integrity_jabber_remote_test.rb
|
85
|
+
- test/test_helper.rb
|
86
|
+
- test/unit/integrity_jabber_test.rb
|