camper_van 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,208 @@
1
+ require "spec_helper"
2
+
3
+ describe CamperVan::IRCD do
4
+ class TestConnection
5
+ attr_reader :sent
6
+
7
+ def initialize
8
+ @sent = []
9
+ end
10
+
11
+ def send_line(line)
12
+ @sent << line
13
+ end
14
+
15
+ def close_connection
16
+ end
17
+
18
+ def remote_ip
19
+ "127.0.0.1"
20
+ end
21
+ end
22
+
23
+ class TestIRCD < CamperVan::IRCD
24
+ attr_writer :campfire
25
+ end
26
+
27
+ before :each do
28
+ @connection = TestConnection.new
29
+ @server = TestIRCD.new(@connection)
30
+
31
+ @server.campfire = Class.new do
32
+ def user(*args)
33
+ yield OpenStruct.new(:name => "Nathan")
34
+ end
35
+ end.new
36
+ end
37
+
38
+ describe "#handle" do
39
+ it "saves the subdomain and API key from the PASS command" do
40
+ @server.handle :pass => ["test:asdf1234"]
41
+ @server.subdomain.must_equal "test"
42
+ @server.api_key.must_equal "asdf1234"
43
+ end
44
+
45
+ it "saves the nickname from the NICK command" do
46
+ @server.handle :nick => ["nathan"]
47
+ @server.nick.must_equal "nathan"
48
+ end
49
+
50
+ it "saves the user and host from the USER command" do
51
+ @server.handle :user => ["nathan", 0, 0, "Nathan"]
52
+ @server.user.must_equal "nathan"
53
+ @server.host.must_equal "127.0.0.1"
54
+ end
55
+
56
+ it "responds with an error when given a nick and user without a password" do
57
+ @server.handle :nick => ["nathan"]
58
+ @server.handle :user => ["nathan", 0, 0, "Nathan"]
59
+ @connection.sent.first.must_match /^:camper_van NOTICE AUTH :.*password/
60
+ end
61
+
62
+ it "responds with welcome messages after receiving a valid registration" do
63
+ @server.handle :pass => ["test:1234asdf"]
64
+ @server.handle :nick => ["nathan"]
65
+ @server.handle :user => ["nathan", 0, 0, "Nathan"]
66
+ @connection.sent.first.must_match /^:camper_van 001 nathan/
67
+ end
68
+
69
+ it "forces a nick change to match the campfire user if it doesn't match" do
70
+ @server.handle :pass => ["test:1234asdf"]
71
+ @server.handle :nick => ["bob"]
72
+ @server.handle :user => ["nathan", 0, 0, "Nathan"]
73
+ line = @connection.sent.detect { |c| c =~ /NICK/ }
74
+ line.must_match /NICK nathan/
75
+ end
76
+
77
+ it "returns an error and shuts down if campfire can't be contacted" do
78
+ @server.campfire = Class.new do
79
+ def user(*args)
80
+ raise Firering::Connection::HTTPError,
81
+ OpenStruct.new(:error => "could not connect")
82
+ end
83
+ end.new
84
+ @server.handle :pass => ["test:1234asdf"]
85
+ @server.handle :nick => ["bob"]
86
+ @server.handle :user => ["nathan", 0, 0, "Nathan"]
87
+ @connection.sent.last.must_match /NOTICE .*could not connect/
88
+ end
89
+
90
+ it "returns an error if the campfire api key is incorrect (user info is nil)" do
91
+ @server.campfire = Class.new do
92
+ def user(*args)
93
+ yield OpenStruct.new # nil everything
94
+ end
95
+ end.new
96
+ @server.handle :pass => ["test:1234asdf"]
97
+ @server.handle :nick => ["bob"]
98
+ @server.handle :user => ["nathan", 0, 0, "Nathan"]
99
+ @connection.sent.last.must_match /NOTICE .*invalid api key/i
100
+ end
101
+
102
+ context "when registered" do
103
+ before :each do
104
+ @server.handle :pass => ["test:1234asdf"]
105
+ @server.handle :nick => ["nathan"]
106
+ @server.handle :user => ["nathan", 0, 0, "Nathan"]
107
+ end
108
+
109
+ # it "connects to the campfire API" do
110
+ # skip "campfire api next!"
111
+ # end
112
+ end
113
+
114
+ context "with a MODE command" do
115
+
116
+ before :each do
117
+ @channel = MiniTest::Mock.new
118
+
119
+ # register
120
+ @server.handle :pass => ["test:1234asdf"]
121
+ @server.handle :nick => ["nathan"]
122
+ @server.handle :user => ["nathan", 0, 0, "Nathan"]
123
+
124
+ @server.channels["#test"] = @channel
125
+ end
126
+
127
+ after :each do
128
+ @channel.verify
129
+ end
130
+
131
+ it "asks the channel to send its mode" do
132
+ @channel.expect :current_mode, nil
133
+ @server.handle :mode => ["#test"]
134
+ end
135
+
136
+ it "with a +i sets the channel mode to +i" do
137
+ @channel.expect :set_mode, nil, ["+i"]
138
+ @server.handle :mode => ["#test", "+i"]
139
+ end
140
+
141
+ it "with a -i sets the channel mode to -i" do
142
+ @channel.expect :set_mode, nil, ["-i"]
143
+ @server.handle :mode => ["#test", "-i"]
144
+ end
145
+
146
+ context "with an unknown mode argument" do
147
+ it "responds with an error" do
148
+ @server.handle :mode => ["#test", "-t"]
149
+ @connection.sent.last.must_match /472 nathan t :Unknown mode t/
150
+ end
151
+ end
152
+
153
+ end
154
+
155
+ context "with a WHO command" do
156
+ before :each do
157
+ @channel = MiniTest::Mock.new
158
+
159
+ # register
160
+ @server.handle :pass => ["test:1234asdf"]
161
+ @server.handle :nick => ["nathan"]
162
+ @server.handle :user => ["nathan", 0, 0, "Nathan"]
163
+
164
+ @server.channels["#test"] = @channel
165
+ end
166
+
167
+ after :each do
168
+ @channel.verify
169
+ end
170
+
171
+ it "asks campfire for a list of users" do
172
+ @channel.expect(:list_users, nil)
173
+ @server.handle :who => ["#test"]
174
+ end
175
+
176
+ it "returns 'end of list' only when an invalid channel is specified" do
177
+ @server.handle :who => ["#invalid"]
178
+ @connection.sent.last.must_match /^:camper_van 315 nathan #invalid :End/
179
+ end
180
+ end
181
+
182
+ context "with a QUIT command" do
183
+ before :each do
184
+ @channel = MiniTest::Mock.new
185
+
186
+ # register
187
+ @server.handle :pass => ["test:1234asdf"]
188
+ @server.handle :nick => ["nathan"]
189
+ @server.handle :user => ["nathan", 0, 0, "Nathan"]
190
+
191
+ @server.channels["#test"] = @channel
192
+ end
193
+
194
+ after :each do
195
+ @channel.verify
196
+ end
197
+
198
+ it "calls #part on the connected channels" do
199
+ @channel.expect(:part, nil)
200
+ @server.handle :quit => ["leaving..."]
201
+ end
202
+
203
+ end
204
+
205
+ end
206
+
207
+ end
208
+
@@ -0,0 +1,66 @@
1
+ require "spec_helper"
2
+
3
+ describe CamperVan::ServerReply do
4
+ before :each do
5
+ @test_server = Class.new do
6
+ include CamperVan::ServerReply
7
+
8
+ attr_reader :sent, :nick, :user, :host
9
+ def initialize
10
+ @sent = []
11
+ @nick, @user, @host = %w(nathan nathan localhost)
12
+ end
13
+ def send_line(data)
14
+ @sent << data
15
+ end
16
+
17
+ end
18
+
19
+ @server = @test_server.new
20
+ end
21
+
22
+ describe "#numeric_reply" do
23
+ it "sends the coded command from the server" do
24
+ @server.numeric_reply(:rpl_welcome, ":welcome")
25
+ @server.sent.size.must_equal 1
26
+ @server.sent.first.must_equal ":camper_van 001 nathan :welcome"
27
+ end
28
+ end
29
+
30
+ describe "#command_reply" do
31
+ it "replies with the given command and arguments" do
32
+ @server.command_reply :notice, "nickname", "hello there"
33
+ @server.sent.size.must_equal 1
34
+ @server.sent.first.must_equal ":camper_van NOTICE nickname :hello there"
35
+ end
36
+
37
+ it "does not prefix strings with a : if they have one already" do
38
+ @server.command_reply :notice, "nickname", ":hello there"
39
+ @server.sent.size.must_equal 1
40
+ @server.sent.first.must_equal ":camper_van NOTICE nickname :hello there"
41
+ end
42
+ end
43
+
44
+ describe "#user_reply" do
45
+ it "replies with the given command directed to the user" do
46
+ @server.user_reply :join, "#chan"
47
+ @server.sent.size.must_equal 1
48
+ @server.sent.first.must_equal ":nathan!nathan@localhost JOIN #chan"
49
+ end
50
+
51
+ it "prefixes the final argument with : if it has spaces" do
52
+ @server.user_reply :privmsg, "#chan", "hello world"
53
+ @server.sent.size.must_equal 1
54
+ @server.sent.first.must_equal ":nathan!nathan@localhost PRIVMSG #chan :hello world"
55
+ end
56
+ end
57
+
58
+ describe "#campfire_reply" do
59
+ it "replies with a command from the given nickname" do
60
+ @server.campfire_reply :privmsg, "joe", "#chan", "hello world"
61
+ @server.sent.size.must_equal 1
62
+ @server.sent.first.must_equal ":joe!joe@campfire PRIVMSG #chan :hello world"
63
+ end
64
+ end
65
+
66
+ end
@@ -0,0 +1,43 @@
1
+ require "spec_helper"
2
+
3
+ describe CamperVan::Server do
4
+ it "has a run module method" do
5
+ CamperVan::Server.must_respond_to :run
6
+ end
7
+
8
+ class TestServer
9
+ include CamperVan::Server
10
+
11
+ attr_reader :sent
12
+ def initialize
13
+ @sent = []
14
+ end
15
+
16
+ def close_connection
17
+ end
18
+
19
+ def send_data(data)
20
+ @sent << data
21
+ end
22
+
23
+ def get_peername
24
+ "xx" + [6667, 127, 0, 0, 1].pack("nC4")
25
+ end
26
+ end
27
+
28
+ before :each do
29
+ @server = TestServer.new
30
+ @server.post_init
31
+ end
32
+
33
+ describe "#receive_line" do
34
+ it "allows for a failed attempt at registration" do
35
+ @server.receive_line "PASS invalid"
36
+ @server.receive_line "NICK nathan" # ignored
37
+ @server.receive_line "USER nathan 0 0 :Nathan" # ignored
38
+
39
+ @server.sent.first.must_match /must specify/
40
+ end
41
+ end
42
+
43
+ end
@@ -0,0 +1,40 @@
1
+ require "spec_helper"
2
+
3
+ describe CamperVan::User do
4
+ context "when initialized from a firering user" do
5
+ before :each do
6
+ # User = Struct.new(:connection, :id, :name, :email_address, :admin,
7
+ # :created_at, :type, :api_auth_token, :avatar_url)
8
+ @f_user = Firering::User.new(
9
+ nil, 12345, "Joe Q. Bob", "joe_bob@example.com", true, Time.now, "asdf", ""
10
+ )
11
+
12
+ @user = CamperVan::User.new(@f_user)
13
+ end
14
+
15
+ it "has a nick" do
16
+ @user.nick.must_equal "joe_q_bob"
17
+ end
18
+
19
+ it "has a name" do
20
+ @user.name.must_equal "Joe Q. Bob"
21
+ end
22
+
23
+ it "has an account" do
24
+ @user.account.must_equal "joe_bob"
25
+ end
26
+
27
+ it "has a server" do
28
+ @user.server.must_equal "example.com"
29
+ end
30
+
31
+ it "has an id" do
32
+ @user.id.must_equal 12345
33
+ end
34
+
35
+ it "can be an admin" do
36
+ @user.admin?.must_equal true
37
+ end
38
+
39
+ end
40
+ end
@@ -0,0 +1,13 @@
1
+ require "bundler"
2
+
3
+ Bundler.setup :default, :development
4
+
5
+ require "minitest/spec"
6
+ require "minitest/autorun"
7
+ require "minitest/mock"
8
+
9
+ require "ostruct"
10
+
11
+ require "camper_van"
12
+
13
+ alias :context :describe
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: camper_van
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Nathan Witmer
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-07-04 00:00:00.000000000 -06:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: eventmachine
17
+ requirement: &2152888420 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: 0.12.10
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *2152888420
26
+ - !ruby/object:Gem::Dependency
27
+ name: firering
28
+ requirement: &2152887920 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 1.1.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: *2152887920
37
+ - !ruby/object:Gem::Dependency
38
+ name: logging
39
+ requirement: &2152887460 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ version: 1.5.1
45
+ type: :runtime
46
+ prerelease: false
47
+ version_requirements: *2152887460
48
+ - !ruby/object:Gem::Dependency
49
+ name: trollop
50
+ requirement: &2152887000 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: 1.16.2
56
+ type: :runtime
57
+ prerelease: false
58
+ version_requirements: *2152887000
59
+ - !ruby/object:Gem::Dependency
60
+ name: minitest
61
+ requirement: &2152886540 !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ~>
65
+ - !ruby/object:Gem::Version
66
+ version: 2.2.2
67
+ type: :development
68
+ prerelease: false
69
+ version_requirements: *2152886540
70
+ description: An IRC to Campfire bridge for IRC-based access to campfire chatrooms
71
+ email:
72
+ - nwitmer@gmail.com
73
+ executables:
74
+ - camper_van
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - .gitignore
79
+ - .rvmrc
80
+ - Gemfile
81
+ - Gemfile.lock
82
+ - Guardfile
83
+ - LICENSE
84
+ - README.md
85
+ - Rakefile
86
+ - bin/camper_van
87
+ - camper_van.gemspec
88
+ - lib/camper_van.rb
89
+ - lib/camper_van/channel.rb
90
+ - lib/camper_van/command_definition.rb
91
+ - lib/camper_van/command_parser.rb
92
+ - lib/camper_van/debug_proxy.rb
93
+ - lib/camper_van/ircd.rb
94
+ - lib/camper_van/logger.rb
95
+ - lib/camper_van/server.rb
96
+ - lib/camper_van/server_reply.rb
97
+ - lib/camper_van/user.rb
98
+ - lib/camper_van/utils.rb
99
+ - lib/camper_van/version.rb
100
+ - spec/camper_van/channel_spec.rb
101
+ - spec/camper_van/command_definition_spec.rb
102
+ - spec/camper_van/command_parser_spec.rb
103
+ - spec/camper_van/ircd_spec.rb
104
+ - spec/camper_van/server_reply_spec.rb
105
+ - spec/camper_van/server_spec.rb
106
+ - spec/camper_van/user_spec.rb
107
+ - spec/spec_helper.rb
108
+ has_rdoc: true
109
+ homepage: ''
110
+ licenses: []
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ! '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ! '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubyforge_project: camper_van
129
+ rubygems_version: 1.6.2
130
+ signing_key:
131
+ specification_version: 3
132
+ summary: An IRC to Campfire bridge
133
+ test_files:
134
+ - spec/camper_van/channel_spec.rb
135
+ - spec/camper_van/command_definition_spec.rb
136
+ - spec/camper_van/command_parser_spec.rb
137
+ - spec/camper_van/ircd_spec.rb
138
+ - spec/camper_van/server_reply_spec.rb
139
+ - spec/camper_van/server_spec.rb
140
+ - spec/camper_van/user_spec.rb
141
+ - spec/spec_helper.rb