clavem 1.3.0 → 1.3.1
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/Rakefile +18 -0
- data/clavem.gemspec +1 -1
- data/doc/Clavem/Authorizer.html +1 -1
- data/doc/Clavem/Exceptions/AuthorizationDenied.html +1 -1
- data/doc/Clavem/Exceptions/Failure.html +1 -1
- data/doc/Clavem/Exceptions/Timeout.html +1 -1
- data/doc/Clavem/Exceptions.html +1 -1
- data/doc/Clavem/Version.html +2 -2
- data/doc/Clavem.html +1 -1
- data/doc/_index.html +1 -1
- data/doc/file.README.html +1 -1
- data/doc/index.html +1 -1
- data/doc/top-level-namespace.html +1 -1
- data/lib/clavem/version.rb +1 -1
- data/spec/clavem/authorizer_spec.rb +90 -90
- metadata +5 -5
data/Rakefile
CHANGED
@@ -9,3 +9,21 @@ require "rspec/core/rake_task"
|
|
9
9
|
|
10
10
|
RSpec::Core::RakeTask.new("spec")
|
11
11
|
RSpec::Core::RakeTask.new("spec:coverage") { |t| t.ruby_opts = "-r./spec/coverage_helper" }
|
12
|
+
|
13
|
+
desc "Generate the documentation"
|
14
|
+
task :docs do
|
15
|
+
system("yardoc") || raise("Failed Execution of: yardoc")
|
16
|
+
end
|
17
|
+
|
18
|
+
desc "Get the current release version"
|
19
|
+
task :version, :with_name do |_, args|
|
20
|
+
gem = Bundler::GemHelper.instance.gemspec
|
21
|
+
puts [args[:with_name] == "true" ? gem.name : nil, gem.version].compact.join("-")
|
22
|
+
end
|
23
|
+
|
24
|
+
desc "Prepare the release"
|
25
|
+
task :prerelease => ["spec:coverage", "docs"] do
|
26
|
+
["git add -A", "git commit -am \"Version #{Bundler::GemHelper.instance.gemspec.version}\""].each do |cmd|
|
27
|
+
system(cmd) || raise("Failed Execution of: #{cmd}")
|
28
|
+
end
|
29
|
+
end
|
data/clavem.gemspec
CHANGED
data/doc/Clavem/Authorizer.html
CHANGED
@@ -5876,7 +5876,7 @@
|
|
5876
5876
|
</div>
|
5877
5877
|
|
5878
5878
|
<div id="footer">
|
5879
|
-
Generated on
|
5879
|
+
Generated on Sat Jul 20 12:09:47 2013 by
|
5880
5880
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
5881
5881
|
0.8.6.2 (ruby-1.9.3).
|
5882
5882
|
</div>
|
@@ -124,7 +124,7 @@
|
|
124
124
|
</div>
|
125
125
|
|
126
126
|
<div id="footer">
|
127
|
-
Generated on
|
127
|
+
Generated on Sat Jul 20 12:09:46 2013 by
|
128
128
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
129
129
|
0.8.6.2 (ruby-1.9.3).
|
130
130
|
</div>
|
@@ -124,7 +124,7 @@
|
|
124
124
|
</div>
|
125
125
|
|
126
126
|
<div id="footer">
|
127
|
-
Generated on
|
127
|
+
Generated on Sat Jul 20 12:09:46 2013 by
|
128
128
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
129
129
|
0.8.6.2 (ruby-1.9.3).
|
130
130
|
</div>
|
@@ -124,7 +124,7 @@
|
|
124
124
|
</div>
|
125
125
|
|
126
126
|
<div id="footer">
|
127
|
-
Generated on
|
127
|
+
Generated on Sat Jul 20 12:09:46 2013 by
|
128
128
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
129
129
|
0.8.6.2 (ruby-1.9.3).
|
130
130
|
</div>
|
data/doc/Clavem/Exceptions.html
CHANGED
@@ -116,7 +116,7 @@
|
|
116
116
|
</div>
|
117
117
|
|
118
118
|
<div id="footer">
|
119
|
-
Generated on
|
119
|
+
Generated on Sat Jul 20 12:09:46 2013 by
|
120
120
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
121
121
|
0.8.6.2 (ruby-1.9.3).
|
122
122
|
</div>
|
data/doc/Clavem/Version.html
CHANGED
@@ -149,7 +149,7 @@
|
|
149
149
|
|
150
150
|
</div>
|
151
151
|
</dt>
|
152
|
-
<dd><pre class="code"><span class='int'>
|
152
|
+
<dd><pre class="code"><span class='int'>1</span></pre></dd>
|
153
153
|
|
154
154
|
<dt id="STRING-constant" class="">STRING =
|
155
155
|
<div class="docstring">
|
@@ -180,7 +180,7 @@
|
|
180
180
|
</div>
|
181
181
|
|
182
182
|
<div id="footer">
|
183
|
-
Generated on
|
183
|
+
Generated on Sat Jul 20 12:09:46 2013 by
|
184
184
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
185
185
|
0.8.6.2 (ruby-1.9.3).
|
186
186
|
</div>
|
data/doc/Clavem.html
CHANGED
@@ -120,7 +120,7 @@
|
|
120
120
|
</div>
|
121
121
|
|
122
122
|
<div id="footer">
|
123
|
-
Generated on
|
123
|
+
Generated on Sat Jul 20 12:09:46 2013 by
|
124
124
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
125
125
|
0.8.6.2 (ruby-1.9.3).
|
126
126
|
</div>
|
data/doc/_index.html
CHANGED
@@ -183,7 +183,7 @@
|
|
183
183
|
</div>
|
184
184
|
|
185
185
|
<div id="footer">
|
186
|
-
Generated on
|
186
|
+
Generated on Sat Jul 20 12:09:46 2013 by
|
187
187
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
188
188
|
0.8.6.2 (ruby-1.9.3).
|
189
189
|
</div>
|
data/doc/file.README.html
CHANGED
@@ -126,7 +126,7 @@ end
|
|
126
126
|
</div></div>
|
127
127
|
|
128
128
|
<div id="footer">
|
129
|
-
Generated on
|
129
|
+
Generated on Sat Jul 20 12:09:46 2013 by
|
130
130
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
131
131
|
0.8.6.2 (ruby-1.9.3).
|
132
132
|
</div>
|
data/doc/index.html
CHANGED
@@ -126,7 +126,7 @@ end
|
|
126
126
|
</div></div>
|
127
127
|
|
128
128
|
<div id="footer">
|
129
|
-
Generated on
|
129
|
+
Generated on Sat Jul 20 12:09:46 2013 by
|
130
130
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
131
131
|
0.8.6.2 (ruby-1.9.3).
|
132
132
|
</div>
|
@@ -103,7 +103,7 @@
|
|
103
103
|
</div>
|
104
104
|
|
105
105
|
<div id="footer">
|
106
|
-
Generated on
|
106
|
+
Generated on Sat Jul 20 12:09:46 2013 by
|
107
107
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
108
108
|
0.8.6.2 (ruby-1.9.3).
|
109
109
|
</div>
|
data/lib/clavem/version.rb
CHANGED
@@ -6,59 +6,59 @@
|
|
6
6
|
|
7
7
|
require "spec_helper"
|
8
8
|
|
9
|
-
|
10
|
-
|
9
|
+
describe Clavem::Authorizer do
|
10
|
+
class ClavemDummyServer
|
11
|
+
attr_accessor :started
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
13
|
+
def start
|
14
|
+
self.started = true
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
def shutdown
|
18
|
+
self.started = false
|
19
|
+
end
|
19
20
|
|
20
|
-
|
21
|
+
def mount_proc(path, &handler)
|
21
22
|
|
23
|
+
end
|
22
24
|
end
|
23
|
-
end
|
24
25
|
|
25
|
-
class ClavemDummyRequest
|
26
|
-
|
26
|
+
class ClavemDummyRequest
|
27
|
+
attr_reader :query
|
27
28
|
|
28
|
-
|
29
|
-
|
29
|
+
def initialize(token = nil)
|
30
|
+
@query = {"oauth_token" => token}
|
31
|
+
end
|
30
32
|
end
|
31
|
-
end
|
32
33
|
|
33
|
-
class ClavemDummyResponse
|
34
|
-
|
35
|
-
|
36
|
-
end
|
34
|
+
class ClavemDummyResponse
|
35
|
+
attr_accessor :status
|
36
|
+
attr_accessor :body
|
37
|
+
end
|
37
38
|
|
38
|
-
describe Clavem::Authorizer do
|
39
39
|
let(:instance){::Clavem::Authorizer.new}
|
40
40
|
|
41
41
|
describe ".instance" do
|
42
|
-
it
|
43
|
-
::Clavem::Authorizer.
|
42
|
+
it "should call .new with the passed arguments" do
|
43
|
+
expect(::Clavem::Authorizer).to receive(:new).with("HOST", "PORT", "COMMAND", "TITLE", "TEMPLATE", "TIMEOUT")
|
44
44
|
::Clavem::Authorizer.instance("HOST", "PORT", "COMMAND", "TITLE", "TEMPLATE", "TIMEOUT")
|
45
45
|
end
|
46
46
|
|
47
|
-
it
|
48
|
-
::Clavem::Authorizer.
|
47
|
+
it "should return the same instance" do
|
48
|
+
allow(::Clavem::Authorizer).to receive(:new) { Time.now }
|
49
49
|
authorizer = ::Clavem::Authorizer.instance("FIRST")
|
50
50
|
expect(::Clavem::Authorizer.instance("SECOND")).to be(authorizer)
|
51
51
|
end
|
52
52
|
|
53
|
-
it
|
54
|
-
::Clavem::Authorizer.
|
53
|
+
it "should return a new instance if requested to" do
|
54
|
+
allow(::Clavem::Authorizer).to receive(:new) { Time.now }
|
55
55
|
authorizer = ::Clavem::Authorizer.instance("FIRST")
|
56
56
|
expect(::Clavem::Authorizer.instance("HOST", "PORT", "COMMAND", "TITLE", "TEMPLATE", "TIMEOUT", true)).not_to be(authorizer)
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
60
|
describe "#initialize" do
|
61
|
-
it
|
61
|
+
it "should handle default arguments" do
|
62
62
|
authorizer = ::Clavem::Authorizer.new
|
63
63
|
expect(authorizer.host).to eq("localhost")
|
64
64
|
expect(authorizer.port).to eq(2501)
|
@@ -69,7 +69,7 @@ describe Clavem::Authorizer do
|
|
69
69
|
expect(authorizer.response_handler).to be_nil
|
70
70
|
end
|
71
71
|
|
72
|
-
it
|
72
|
+
it "should assign arguments" do
|
73
73
|
authorizer = ::Clavem::Authorizer.new("HOST", 2511, "COMMAND", "TITLE", "TEMPLATE", 2) do end
|
74
74
|
expect(authorizer.host).to eq("HOST")
|
75
75
|
expect(authorizer.port).to eq(2511)
|
@@ -80,62 +80,62 @@ describe Clavem::Authorizer do
|
|
80
80
|
expect(authorizer.response_handler).to be_a(Proc)
|
81
81
|
end
|
82
82
|
|
83
|
-
it
|
83
|
+
it "should correct wrong arguments" do
|
84
84
|
authorizer = ::Clavem::Authorizer.new("IP", -10, nil, nil, "", -1)
|
85
85
|
expect(authorizer.port).to eq(2501)
|
86
86
|
expect(authorizer.timeout).to eq(0)
|
87
87
|
end
|
88
88
|
|
89
|
-
it
|
89
|
+
it "should setup internal status" do
|
90
90
|
authorizer = ::Clavem::Authorizer.new
|
91
91
|
expect(authorizer.token).to be_nil
|
92
92
|
expect(authorizer.status).to eq(:waiting)
|
93
93
|
end
|
94
94
|
|
95
|
-
it
|
95
|
+
it "should return self" do
|
96
96
|
expect(::Clavem::Authorizer.new).to be_a(::Clavem::Authorizer)
|
97
97
|
end
|
98
98
|
end
|
99
99
|
|
100
100
|
describe "#authorize" do
|
101
|
-
it
|
101
|
+
it "should call the correct authorize sequence and then return self" do
|
102
102
|
sequence = []
|
103
103
|
instance = ::Clavem::Authorizer.new
|
104
104
|
server = ::ClavemDummyServer.new
|
105
105
|
|
106
106
|
# Setup stuff
|
107
|
-
instance.
|
107
|
+
allow(instance).to receive(:setup_webserver) do sequence << 1 end
|
108
108
|
|
109
109
|
instance.instance_variable_set(:@server, server)
|
110
|
-
instance.
|
111
|
-
instance.
|
112
|
-
instance.
|
110
|
+
allow(instance).to receive(:setup_interruptions_handling) do sequence << 2 end
|
111
|
+
allow(instance).to receive(:setup_timeout_handling) do sequence << 3 end
|
112
|
+
allow(instance).to receive(:open_endpoint) do sequence << 4 end
|
113
113
|
|
114
|
-
server.
|
114
|
+
expect(server).to receive(:start)
|
115
115
|
expect(instance.authorize("URL")).to be(instance)
|
116
116
|
expect(sequence).to eq([1, 2, 3, 4])
|
117
117
|
end
|
118
118
|
|
119
|
-
it
|
119
|
+
it "should raise an exception in case of timeout" do
|
120
120
|
instance = ::Clavem::Authorizer.new
|
121
|
-
instance.
|
121
|
+
allow(instance).to receive(:setup_webserver).and_raise(::Clavem::Exceptions::Timeout)
|
122
122
|
expect { instance.authorize("URL") }.to raise_error(::Clavem::Exceptions::Timeout)
|
123
123
|
expect(instance.status).to eq(:failure)
|
124
124
|
end
|
125
125
|
|
126
|
-
it
|
126
|
+
it "should raise an exception in case of errors" do
|
127
127
|
instance = ::Clavem::Authorizer.new
|
128
|
-
instance.
|
128
|
+
allow(instance).to receive(:setup_webserver).and_raise(ArgumentError)
|
129
129
|
expect { instance.authorize("URL") }.to raise_error(::Clavem::Exceptions::Failure)
|
130
130
|
expect(instance.status).to eq(:failure)
|
131
131
|
end
|
132
132
|
|
133
|
-
it
|
133
|
+
it "should always run #cleanup" do
|
134
134
|
cleaned = false
|
135
135
|
instance = ::Clavem::Authorizer.new
|
136
|
-
instance.
|
137
|
-
instance.
|
138
|
-
instance.
|
136
|
+
allow(instance).to receive(:cleanup) do cleaned = true end
|
137
|
+
allow(instance).to receive(:open_endpoint) do end
|
138
|
+
allow(instance).to receive(:setup_webserver) do
|
139
139
|
instance.instance_variable_set(:@server, ::ClavemDummyServer.new)
|
140
140
|
end
|
141
141
|
|
@@ -144,31 +144,31 @@ describe Clavem::Authorizer do
|
|
144
144
|
expect(cleaned).to be_true
|
145
145
|
|
146
146
|
cleaned = false
|
147
|
-
instance.
|
147
|
+
allow(instance).to receive(:setup_webserver).and_raise(ArgumentError)
|
148
148
|
expect { instance.authorize("URL") }.to raise_error(::Clavem::Exceptions::Failure)
|
149
149
|
expect(cleaned).to be_true
|
150
150
|
|
151
151
|
cleaned = false
|
152
|
-
instance.
|
152
|
+
allow(instance).to receive(:setup_webserver).and_raise(::Clavem::Exceptions::Timeout)
|
153
153
|
expect { instance.authorize("URL") }.to raise_error(::Clavem::Exceptions::Timeout)
|
154
154
|
expect(cleaned).to be_true
|
155
155
|
end
|
156
156
|
end
|
157
157
|
|
158
158
|
describe "#callback_url" do
|
159
|
-
it
|
159
|
+
it "should return the correct callback" do
|
160
160
|
expect(::Clavem::Authorizer.new.callback_url).to eq("http://localhost:2501/")
|
161
161
|
expect(::Clavem::Authorizer.new("10.0.0.1", "80").callback_url).to eq("http://10.0.0.1:80/")
|
162
162
|
end
|
163
163
|
end
|
164
164
|
|
165
165
|
describe "#default_response_handler" do
|
166
|
-
it
|
166
|
+
it "should return the token" do
|
167
167
|
instance = ::Clavem::Authorizer.new
|
168
168
|
expect(instance.default_response_handler(instance, ::ClavemDummyRequest.new("TOKEN"), nil)).to eq("TOKEN")
|
169
169
|
end
|
170
170
|
|
171
|
-
it
|
171
|
+
it "should return an empty string by default" do
|
172
172
|
instance = ::Clavem::Authorizer.new
|
173
173
|
expect(instance.default_response_handler(instance, ::ClavemDummyRequest.new(nil), nil)).to eq("")
|
174
174
|
end
|
@@ -182,63 +182,63 @@ describe Clavem::Authorizer do
|
|
182
182
|
|
183
183
|
it "should set using English if called without arguments" do
|
184
184
|
authorizer = ::Clavem::Authorizer.new
|
185
|
-
R18n::I18n.
|
185
|
+
expect(R18n::I18n).to receive(:new).with([:en, ENV["LANG"], R18n::I18n.system_locale].compact, File.absolute_path(::Pathname.new(File.dirname(__FILE__)).to_s + "/../../locales/")).and_call_original
|
186
186
|
authorizer.localize
|
187
187
|
end
|
188
188
|
|
189
189
|
it "should set the requested locale" do
|
190
190
|
authorizer = ::Clavem::Authorizer.new
|
191
|
-
R18n::I18n.
|
191
|
+
expect(R18n::I18n).to receive(:new).with([:it, ENV["LANG"], R18n::I18n.system_locale].compact, File.absolute_path(::Pathname.new(File.dirname(__FILE__)).to_s + "/../../locales/")).and_call_original
|
192
192
|
authorizer.localize(:it)
|
193
193
|
end
|
194
194
|
end
|
195
195
|
|
196
196
|
# PRIVATE
|
197
197
|
describe "#open_endpoint" do
|
198
|
-
it
|
199
|
-
Kernel.
|
198
|
+
it "should call system with the right command" do
|
199
|
+
expect(Kernel).to receive(:system).with("open \"URL\"")
|
200
200
|
instance.instance_variable_set(:@url, "URL")
|
201
201
|
instance.send(:open_endpoint)
|
202
202
|
|
203
|
-
Kernel.
|
203
|
+
expect(Kernel).to receive(:system).with("COMMAND")
|
204
204
|
::Clavem::Authorizer.new("HOST", "PORT", "COMMAND").send(:open_endpoint)
|
205
205
|
end
|
206
206
|
|
207
|
-
it
|
208
|
-
Kernel.
|
207
|
+
it "should raise exception in case of failures" do
|
208
|
+
allow(Kernel).to receive(:system).and_raise(RuntimeError)
|
209
209
|
expect { instance.send(:open_endpoint) }.to raise_error(::Clavem::Exceptions::Failure)
|
210
210
|
end
|
211
211
|
end
|
212
212
|
|
213
213
|
describe "#setup_interruptions_handling" do
|
214
|
-
it
|
215
|
-
Kernel.
|
216
|
-
Kernel.
|
217
|
-
Kernel.
|
218
|
-
Kernel.
|
214
|
+
it "should add handler for SIGINT, SIGTERM, SIGKILL" do
|
215
|
+
expect(Kernel).to receive(:trap).with("USR2")
|
216
|
+
expect(Kernel).to receive(:trap).with("INT")
|
217
|
+
expect(Kernel).to receive(:trap).with("TERM")
|
218
|
+
expect(Kernel).to receive(:trap).with("KILL")
|
219
219
|
instance.send(:setup_interruptions_handling)
|
220
220
|
end
|
221
221
|
end
|
222
222
|
|
223
223
|
describe "#setup_timeout_handling" do
|
224
|
-
it
|
224
|
+
it "should not set a timeout handler by default" do
|
225
225
|
authorizer = ::Clavem::Authorizer.new
|
226
|
-
authorizer.
|
227
|
-
authorizer.
|
226
|
+
allow(authorizer).to receive(:open_endpoint)
|
227
|
+
allow(authorizer).to receive(:setup_webserver) do authorizer.instance_variable_set(:@server, ::ClavemDummyServer.new) end
|
228
228
|
authorizer.authorize("URL")
|
229
229
|
expect(authorizer.instance_variable_get(:@timeout_handler)).to be_nil
|
230
230
|
end
|
231
231
|
|
232
|
-
it
|
233
|
-
Process.
|
234
|
-
Kernel.
|
232
|
+
it "should set and execute a timeout handler" do
|
233
|
+
expect(Process).to receive(:kill).with("USR2", 0)
|
234
|
+
expect(Kernel).to receive(:sleep).with(0.5)
|
235
235
|
|
236
236
|
server = ::ClavemDummyServer.new
|
237
|
-
server.
|
237
|
+
allow(server).to receive(:start) do sleep(1) end
|
238
238
|
|
239
239
|
authorizer = ::Clavem::Authorizer.new("HOST", "PORT", "COMMAND", "TITLE", "TEMPLATE", 500)
|
240
|
-
authorizer.
|
241
|
-
authorizer.
|
240
|
+
allow(authorizer).to receive(:open_endpoint) do end
|
241
|
+
allow(authorizer).to receive(:setup_webserver) do authorizer.instance_variable_set(:@server, server) end
|
242
242
|
expect { authorizer.authorize("URL") }.to raise_error(::Clavem::Exceptions::Timeout)
|
243
243
|
|
244
244
|
thread = authorizer.instance_variable_get(:@timeout_thread)
|
@@ -250,18 +250,18 @@ describe Clavem::Authorizer do
|
|
250
250
|
describe "#setup_webserver" do
|
251
251
|
it "should initialize a web server with correct arguments" do
|
252
252
|
logger = WEBrick::Log.new("/dev/null")
|
253
|
-
WEBrick::Log.
|
253
|
+
allow(WEBrick::Log).to receive(:new).and_return(logger)
|
254
254
|
|
255
|
-
::WEBrick::HTTPServer.
|
255
|
+
expect(::WEBrick::HTTPServer).to receive(:new).with(BindAddress: "10.0.0.1", Port: 80, Logger: logger, AccessLog: [nil, nil]).and_return(::ClavemDummyServer.new)
|
256
256
|
authorizer = ::Clavem::Authorizer.new("10.0.0.1", 80)
|
257
257
|
authorizer.send(:setup_webserver)
|
258
258
|
end
|
259
259
|
|
260
260
|
it "should setup a single request handler on /" do
|
261
261
|
server = ::ClavemDummyServer.new
|
262
|
-
::WEBrick::HTTPServer.
|
262
|
+
allow(::WEBrick::HTTPServer).to receive(:new).and_return(server)
|
263
263
|
authorizer = ::Clavem::Authorizer.new("HOST", "PORT")
|
264
|
-
server.
|
264
|
+
expect(server).to receive(:mount_proc).with("/")
|
265
265
|
authorizer.send(:setup_webserver)
|
266
266
|
end
|
267
267
|
end
|
@@ -273,12 +273,12 @@ describe Clavem::Authorizer do
|
|
273
273
|
|
274
274
|
it "should call the correct handler" do
|
275
275
|
instance.instance_variable_set(:@server, ::ClavemDummyServer.new)
|
276
|
-
instance.
|
276
|
+
expect(instance).to receive(:default_response_handler).with(instance, request, response)
|
277
277
|
instance.send(:dispatch_request, request, response)
|
278
278
|
|
279
279
|
authorizer = ::Clavem::Authorizer.new do end
|
280
280
|
authorizer.instance_variable_set(:@server, ::ClavemDummyServer.new)
|
281
|
-
authorizer.response_handler.
|
281
|
+
expect(authorizer.response_handler).to receive(:call).with(authorizer, request, response)
|
282
282
|
authorizer.send(:dispatch_request, request, response)
|
283
283
|
end
|
284
284
|
|
@@ -286,13 +286,13 @@ describe Clavem::Authorizer do
|
|
286
286
|
authorizer = ::Clavem::Authorizer.new
|
287
287
|
authorizer.instance_variable_set(:@server, server)
|
288
288
|
authorizer.status = :waiting
|
289
|
-
server.
|
289
|
+
expect(server).to receive(:shutdown)
|
290
290
|
authorizer.send(:dispatch_request, request, response)
|
291
291
|
|
292
292
|
authorizer = ::Clavem::Authorizer.new
|
293
293
|
authorizer.instance_variable_set(:@server, server)
|
294
294
|
authorizer.status = :success
|
295
|
-
server.
|
295
|
+
expect(server).not_to receive(:shutdown)
|
296
296
|
authorizer.send(:dispatch_request, request, response)
|
297
297
|
end
|
298
298
|
|
@@ -313,7 +313,7 @@ describe Clavem::Authorizer do
|
|
313
313
|
it "should render the body of the response" do
|
314
314
|
authorizer = ::Clavem::Authorizer.new
|
315
315
|
authorizer.instance_variable_set(:@server, server)
|
316
|
-
authorizer.instance_variable_get(:@compiled_template).
|
316
|
+
expect(authorizer.instance_variable_get(:@compiled_template)).to receive(:result).and_return("TEMPLATE")
|
317
317
|
authorizer.send(:dispatch_request, request, response)
|
318
318
|
expect(response.body).to eq("TEMPLATE")
|
319
319
|
end
|
@@ -322,30 +322,30 @@ describe Clavem::Authorizer do
|
|
322
322
|
describe "#cleanup" do
|
323
323
|
it "should shutdown the server and cleanup signal handling" do
|
324
324
|
server = ::ClavemDummyServer.new
|
325
|
-
server.
|
325
|
+
allow(server).to receive(:start) do sleep(1) end
|
326
326
|
|
327
327
|
authorizer = ::Clavem::Authorizer.new("HOST", "PORT", "COMMAND", "TITLE", "TEMPLATE")
|
328
|
-
authorizer.
|
329
|
-
authorizer.
|
328
|
+
allow(authorizer).to receive(:open_endpoint) do end
|
329
|
+
allow(authorizer).to receive(:setup_webserver) do authorizer.instance_variable_set(:@server, server) end
|
330
330
|
authorizer.authorize("URL")
|
331
331
|
|
332
|
-
Kernel.
|
333
|
-
Kernel.
|
334
|
-
Kernel.
|
335
|
-
Kernel.
|
336
|
-
server.
|
332
|
+
expect(Kernel).to receive(:trap).with("USR2", "DEFAULT")
|
333
|
+
expect(Kernel).to receive(:trap).with("INT", "DEFAULT")
|
334
|
+
expect(Kernel).to receive(:trap).with("TERM", "DEFAULT")
|
335
|
+
expect(Kernel).to receive(:trap).with("KILL", "DEFAULT")
|
336
|
+
expect(server).to receive(:shutdown)
|
337
337
|
authorizer.send(:cleanup)
|
338
338
|
end
|
339
339
|
|
340
340
|
it "should exit timeout handling thread if active" do
|
341
341
|
thread = nil
|
342
342
|
server = ::ClavemDummyServer.new
|
343
|
-
server.
|
343
|
+
allow(server).to receive(:start) do sleep(1) end
|
344
344
|
|
345
345
|
authorizer = ::Clavem::Authorizer.new("HOST", "PORT", "COMMAND", "TITLE", "TEMPLATE", 5000)
|
346
346
|
authorizer.send(:setup_timeout_handling)
|
347
347
|
thread = authorizer.instance_variable_get(:@timeout_thread)
|
348
|
-
thread.
|
348
|
+
expect(thread).to receive(:exit)
|
349
349
|
authorizer.send(:cleanup)
|
350
350
|
end
|
351
351
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clavem
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.1
|
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: 2013-07-
|
12
|
+
date: 2013-07-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: mamertes
|
@@ -18,7 +18,7 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 2.2.
|
21
|
+
version: 2.2.1
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 2.2.
|
29
|
+
version: 2.2.1
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: webrick
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -112,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
112
112
|
version: '0'
|
113
113
|
segments:
|
114
114
|
- 0
|
115
|
-
hash:
|
115
|
+
hash: -4417363914143300704
|
116
116
|
requirements: []
|
117
117
|
rubyforge_project: clavem
|
118
118
|
rubygems_version: 1.8.25
|