kronk 1.9.3 → 1.9.4
Sign up to get free protection for your applications and to get access to all the features.
- data/History.rdoc +10 -0
- data/README.rdoc +1 -1
- data/Rakefile +5 -4
- data/TODO.rdoc +2 -0
- data/lib/kronk.rb +6 -3
- data/lib/kronk/cmd.rb +17 -9
- data/lib/kronk/constants.rb +4 -1
- data/lib/kronk/request.rb +37 -12
- data/lib/kronk/response.rb +15 -35
- data/test/test_helper.rb +1 -1
- data/test/test_helper_methods.rb +5 -5
- data/test/test_kronk.rb +4 -4
- data/test/test_player.rb +3 -3
- data/test/test_request.rb +98 -2
- data/test/test_response.rb +4 -9
- metadata +149 -141
data/History.rdoc
CHANGED
data/README.rdoc
CHANGED
data/Rakefile
CHANGED
@@ -22,10 +22,11 @@ Hoe.spec 'kronk' do
|
|
22
22
|
self.history_file = "History.rdoc"
|
23
23
|
self.extra_rdoc_files = FileList['*.rdoc']
|
24
24
|
|
25
|
-
self.extra_deps << ['json',
|
26
|
-
self.extra_deps << ['cookiejar',
|
27
|
-
self.extra_deps << ['ruby-path',
|
28
|
-
self.extra_deps << ['mime-types',
|
25
|
+
self.extra_deps << ['json', '~>1.5']
|
26
|
+
self.extra_deps << ['cookiejar', '~>0.3.0']
|
27
|
+
self.extra_deps << ['ruby-path', '~>1.0.0']
|
28
|
+
self.extra_deps << ['mime-types', '~>1.18.0']
|
29
|
+
self.extra_deps << ['simple_oauth', '~>0.1.9']
|
29
30
|
|
30
31
|
self.extra_dev_deps << ['plist', '~>3.1.0']
|
31
32
|
self.extra_dev_deps << ['nokogiri', '~>1.4']
|
data/TODO.rdoc
CHANGED
data/lib/kronk.rb
CHANGED
@@ -4,17 +4,19 @@ require 'json'
|
|
4
4
|
require 'cookiejar'
|
5
5
|
require 'path'
|
6
6
|
require 'mime/types'
|
7
|
+
require 'simple_oauth'
|
7
8
|
|
8
9
|
require 'thread'
|
9
10
|
require 'stringio'
|
10
11
|
|
11
12
|
require 'net/http'
|
13
|
+
require 'base64'
|
12
14
|
require 'yaml'
|
13
15
|
|
14
16
|
class Kronk
|
15
17
|
|
16
18
|
# This gem's version.
|
17
|
-
VERSION = '1.9.
|
19
|
+
VERSION = '1.9.4'
|
18
20
|
|
19
21
|
require 'kronk/constants'
|
20
22
|
require 'kronk/queue_runner'
|
@@ -279,6 +281,7 @@ class Kronk
|
|
279
281
|
# :http_method:: Symbol - the http method to use; defaults to :get
|
280
282
|
# :user_agent:: String - user agent string or alias; defaults to 'kronk'
|
281
283
|
# :auth:: Hash - must contain :username and :password; defaults to nil
|
284
|
+
# :oauth:: Hash - :consumer_key, :token, :consumer_secret, :token_secret
|
282
285
|
# :proxy:: Hash/String - http proxy to use; defaults to nil
|
283
286
|
# :keep_indicies:: Boolean - indicies of modified arrays display as hashes
|
284
287
|
# :show_headers:: Boolean/String/Array - which headers to show in output
|
@@ -389,7 +392,7 @@ class Kronk
|
|
389
392
|
|
390
393
|
req = Request.new uri, opts
|
391
394
|
Cmd.verbose "Retrieving URL: #{req.uri}\n" if defined?(Cmd)
|
392
|
-
resp = req.
|
395
|
+
resp = req.stream opts
|
393
396
|
|
394
397
|
hist_uri = req.uri.to_s[0..-req.uri.request_uri.length]
|
395
398
|
hist_uri = hist_uri[(req.uri.scheme.length + 3)..-1]
|
@@ -429,7 +432,7 @@ class Kronk
|
|
429
432
|
out_opts[key] = val.merge out_opts[key], &DEEP_MERGE
|
430
433
|
|
431
434
|
# Hashes
|
432
|
-
when :headers, :auth
|
435
|
+
when :headers, :auth, :oauth
|
433
436
|
out_opts[key] = val.merge out_opts[key]
|
434
437
|
|
435
438
|
# Proxy hash or String
|
data/lib/kronk/cmd.rb
CHANGED
@@ -106,7 +106,6 @@ class Kronk
|
|
106
106
|
|
107
107
|
def self.parse_args argv
|
108
108
|
options = {
|
109
|
-
:auth => {},
|
110
109
|
:no_body => false,
|
111
110
|
:player => {},
|
112
111
|
:proxy => {},
|
@@ -450,6 +449,11 @@ Parse and run diffs against data from live and cached http responses.
|
|
450
449
|
end
|
451
450
|
|
452
451
|
|
452
|
+
opt.on('--oauth', String, 'Yaml file with Oauth credentials') do |file|
|
453
|
+
options[:oauth] = YAML.load_file file
|
454
|
+
end
|
455
|
+
|
456
|
+
|
453
457
|
opt.on('-x', '--proxy STR', String,
|
454
458
|
'Use HTTP proxy on given port: host[:port]') do |value|
|
455
459
|
options[:proxy][:host], options[:proxy][:port] = value.split ":", 2
|
@@ -498,6 +502,7 @@ Parse and run diffs against data from live and cached http responses.
|
|
498
502
|
|
499
503
|
opt.on('-u', '--user STR', String,
|
500
504
|
'Set server auth user and/or password: usr[:pass]') do |value|
|
505
|
+
options[:auth] ||= {}
|
501
506
|
options[:auth][:username], options[:auth][:password] =
|
502
507
|
value.split ":", 2
|
503
508
|
|
@@ -679,17 +684,20 @@ Parse and run diffs against data from live and cached http responses.
|
|
679
684
|
# to $stdout.
|
680
685
|
|
681
686
|
def self.render kronk, options={}
|
682
|
-
|
687
|
+
status =
|
688
|
+
if options[:irb]
|
689
|
+
irb kronk.response
|
683
690
|
|
684
|
-
|
685
|
-
|
691
|
+
elsif kronk.diff
|
692
|
+
render_diff kronk.diff
|
686
693
|
|
687
|
-
|
688
|
-
|
694
|
+
elsif kronk.response
|
695
|
+
render_response kronk.response, kronk.options
|
696
|
+
end
|
689
697
|
|
690
|
-
|
691
|
-
|
692
|
-
|
698
|
+
cache_response kronk.response
|
699
|
+
|
700
|
+
status
|
693
701
|
end
|
694
702
|
|
695
703
|
|
data/lib/kronk/constants.rb
CHANGED
@@ -49,9 +49,12 @@ class Kronk
|
|
49
49
|
Hash === v1 && Hash === v2 ? v1.merge(v2,&DEEP_MERGE) : v2
|
50
50
|
end
|
51
51
|
|
52
|
+
RUBY_ENGINE = 'ruby' unless defined?(RUBY_ENGINE)
|
53
|
+
|
52
54
|
# The default Kronk user agent.
|
53
55
|
DEFAULT_USER_AGENT =
|
54
|
-
"Kronk/#{VERSION} (http://
|
56
|
+
"Kronk/#{VERSION} (#{RUBY_PLATFORM}; U; en-US; http://kronk.me) \
|
57
|
+
#{RUBY_ENGINE}/#{RUBY_VERSION}p#{RUBY_PATCHLEVEL}"
|
55
58
|
|
56
59
|
# Aliases for various user-agents. Thanks Mechanize! :)
|
57
60
|
USER_AGENTS = {
|
data/lib/kronk/request.rb
CHANGED
@@ -225,6 +225,7 @@ class Kronk
|
|
225
225
|
# :query:: Hash/String - the data to append to the http request path
|
226
226
|
# :user_agent:: String - user agent string or alias; defaults to 'kronk'
|
227
227
|
# :auth:: Hash - must contain :username and :password; defaults to nil
|
228
|
+
# :oauth:: Hash - :consumer_key, :token, :consumer_secret, :token_secret
|
228
229
|
# :headers:: Hash - extra headers to pass to the request
|
229
230
|
# :http_method:: Symbol - the http method to use; defaults to :get
|
230
231
|
# :proxy:: Hash/String - http proxy to use; defaults to {}
|
@@ -234,7 +235,8 @@ class Kronk
|
|
234
235
|
# to using a post request.
|
235
236
|
|
236
237
|
def initialize uri, opts={}
|
237
|
-
@auth
|
238
|
+
@auth = opts[:auth]
|
239
|
+
@oauth = opts[:oauth]
|
238
240
|
|
239
241
|
@connection = nil
|
240
242
|
@response = nil
|
@@ -283,19 +285,37 @@ class Kronk
|
|
283
285
|
# Returns the basic auth credentials if available.
|
284
286
|
|
285
287
|
def auth
|
286
|
-
|
288
|
+
if (!@auth || !@auth[:username]) && @headers['Authorization'] &&
|
289
|
+
@headers['Authorization'] !~ /^OAuth\s/
|
287
290
|
|
288
|
-
if !@auth[:username] && @headers['Authorization']
|
289
|
-
require 'base64'
|
290
291
|
str = Base64.decode64 @headers['Authorization'].split[1]
|
291
292
|
username, password = str.split(":", 2)
|
292
|
-
@auth = {
|
293
|
+
@auth = {
|
294
|
+
:username => username,
|
295
|
+
:password => password
|
296
|
+
}.merge(@auth || {})
|
293
297
|
end
|
294
298
|
|
295
299
|
@auth
|
296
300
|
end
|
297
301
|
|
298
302
|
|
303
|
+
##
|
304
|
+
# Returns the oauth credentials if available.
|
305
|
+
|
306
|
+
def oauth
|
307
|
+
if (!@oauth || !@oauth[:token] || !@oauth[:consumer_key]) &&
|
308
|
+
@headers['Authorization'].to_s =~ /^OAuth\s/
|
309
|
+
|
310
|
+
@oauth =
|
311
|
+
SimpleOAuth::Header.parse(@headers['Authorization']).
|
312
|
+
merge(@oauth || {})
|
313
|
+
end
|
314
|
+
|
315
|
+
@oauth
|
316
|
+
end
|
317
|
+
|
318
|
+
|
299
319
|
##
|
300
320
|
# Assign request body. Supports String, Hash, and IO. Will attempt to
|
301
321
|
# correctly assing the Content-Type and Transfer-Encoding headers.
|
@@ -446,7 +466,7 @@ class Kronk
|
|
446
466
|
def retrieve opts={}, &block
|
447
467
|
start_time = Time.now
|
448
468
|
|
449
|
-
@response = stream opts
|
469
|
+
@response = stream opts, &block
|
450
470
|
|
451
471
|
@response.body # make sure to read the full body from io
|
452
472
|
@response.time = Time.now - start_time - @response.conn_time
|
@@ -466,6 +486,7 @@ class Kronk
|
|
466
486
|
|
467
487
|
def stream opts={}, &block
|
468
488
|
retried = false
|
489
|
+
opts = opts.merge(:request => self)
|
469
490
|
|
470
491
|
begin
|
471
492
|
start_time = Time.now
|
@@ -475,7 +496,6 @@ class Kronk
|
|
475
496
|
|
476
497
|
@response = conn.request http_request, nil, opts, &block
|
477
498
|
@response.conn_time = conn_time
|
478
|
-
@response.request = self
|
479
499
|
|
480
500
|
@response
|
481
501
|
|
@@ -501,8 +521,9 @@ class Kronk
|
|
501
521
|
:no_cookies => !self.use_cookies
|
502
522
|
}
|
503
523
|
|
504
|
-
hash[:auth] = @auth
|
505
|
-
hash[:
|
524
|
+
hash[:auth] = @auth if @auth
|
525
|
+
hash[:oauth] = @oauth if @oauth
|
526
|
+
hash[:data] = @body if @body
|
506
527
|
hash[:headers] = @headers unless @headers.empty?
|
507
528
|
hash[:proxy] = self.proxy unless self.proxy.empty?
|
508
529
|
|
@@ -517,7 +538,7 @@ class Kronk
|
|
517
538
|
|
518
539
|
def to_s
|
519
540
|
out = "#{@http_method} #{@uri.request_uri} HTTP/1.1\r\n"
|
520
|
-
out << "
|
541
|
+
out << "Host: #{@uri.host}:#{@uri.port}\r\n"
|
521
542
|
|
522
543
|
http_request.each do |name, value|
|
523
544
|
out << "#{name}: #{value}\r\n" unless name =~ /host/i
|
@@ -549,8 +570,12 @@ class Kronk
|
|
549
570
|
def http_request
|
550
571
|
req = VanillaRequest.new @http_method, @uri.request_uri, @headers
|
551
572
|
|
552
|
-
|
553
|
-
|
573
|
+
if @oauth
|
574
|
+
req['Authorization'] =
|
575
|
+
SimpleOAuth::Header.new(@http_method, @uri, {}, self.oauth).to_s
|
576
|
+
elsif @auth && @auth[:username]
|
577
|
+
req.basic_auth @auth[:username], @auth[:password]
|
578
|
+
end
|
554
579
|
|
555
580
|
# Stream Multipart
|
556
581
|
if Kronk::Multipart === @body
|
data/lib/kronk/response.rb
CHANGED
@@ -67,16 +67,22 @@ class Kronk
|
|
67
67
|
|
68
68
|
@cookies = []
|
69
69
|
|
70
|
-
|
71
|
-
|
72
|
-
|
70
|
+
Array(@headers['set-cookie']).each do |cvalue|
|
71
|
+
cookie = CookieJar::CookieValidation.parse_set_cookie(cvalue).to_hash
|
72
|
+
cookie.delete :version
|
73
|
+
cookie.keys.each{|k| cookie[k.to_s] = cookie.delete(k) }
|
74
|
+
@cookies << cookie
|
75
|
+
end
|
73
76
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
77
|
+
Array(@headers['set-cookie2']).each do |cvalue|
|
78
|
+
cookie = CookieJar::CookieValidation.parse_set_cookie2(cvalue).to_hash
|
79
|
+
cookie.keys.each{|k| cookie[k.to_s] = cookie.delete(k) }
|
80
|
+
@cookies << cookie
|
78
81
|
end
|
79
82
|
|
83
|
+
Kronk.cookie_jar.set_cookies_from_headers uri, @headers unless
|
84
|
+
opts[:no_cookies] || !(URI::HTTP === uri)
|
85
|
+
|
80
86
|
self.gzip = opts[:force_gzip]
|
81
87
|
self.inflate = opts[:force_inflate]
|
82
88
|
gzip?
|
@@ -544,7 +550,7 @@ class Kronk
|
|
544
550
|
|
545
551
|
new_opts.merge!(opts)
|
546
552
|
|
547
|
-
Request.new(self.location, new_opts).
|
553
|
+
Request.new(self.location, new_opts).stream(new_opts, &block)
|
548
554
|
end
|
549
555
|
|
550
556
|
|
@@ -590,7 +596,7 @@ class Kronk
|
|
590
596
|
# See Path::Transaction for supported transform actions in the
|
591
597
|
# {ruby-path gem}[http://github.com/yaksnrainbows/ruby-path].
|
592
598
|
|
593
|
-
def data opts={}
|
599
|
+
def data opts={}, &block
|
594
600
|
data = nil
|
595
601
|
|
596
602
|
unless opts[:no_body]
|
@@ -923,29 +929,3 @@ class Kronk
|
|
923
929
|
end
|
924
930
|
end
|
925
931
|
end
|
926
|
-
|
927
|
-
|
928
|
-
class CookieJar::Cookie
|
929
|
-
def to_hash
|
930
|
-
result = {
|
931
|
-
'name' => @name,
|
932
|
-
'value' => @value,
|
933
|
-
'domain' => @domain,
|
934
|
-
'path' => @path,
|
935
|
-
}
|
936
|
-
{
|
937
|
-
'expiry' => @expiry,
|
938
|
-
'secure' => (true if @secure),
|
939
|
-
'http_only' => (true if @http_only),
|
940
|
-
'version' => (@version if version != 0),
|
941
|
-
'comment' => @comment,
|
942
|
-
'comment_url' => @comment_url,
|
943
|
-
'discard' => (true if @discard),
|
944
|
-
'ports' => @ports
|
945
|
-
}.each do |name, value|
|
946
|
-
result[name] = value if value
|
947
|
-
end
|
948
|
-
|
949
|
-
result
|
950
|
-
end
|
951
|
-
end
|
data/test/test_helper.rb
CHANGED
@@ -196,7 +196,7 @@ def expect_request req_method, url, opts={}
|
|
196
196
|
with(uri.host, uri.port, {:proxy => proxy, :ssl => !!opts.delete(:ssl)}).
|
197
197
|
returns http
|
198
198
|
|
199
|
-
http.expects(:request).with(req, nil, opts).returns resp
|
199
|
+
http.expects(:request).with(req, nil, has_entries(opts)).returns resp
|
200
200
|
|
201
201
|
yield http, req, resp if block_given?
|
202
202
|
|
data/test/test_helper_methods.rb
CHANGED
@@ -10,9 +10,9 @@ class TestHelperMethods < Test::Unit::TestCase
|
|
10
10
|
@mock_resp = Kronk::Response.new io
|
11
11
|
@mock_resp2 = Kronk::Response.new \
|
12
12
|
StringIO.new mock_resp("200_response.json")
|
13
|
-
@mock_req = stub("mock_req", :
|
13
|
+
@mock_req = stub("mock_req", :stream => @mock_resp,
|
14
14
|
:uri => URI.parse("http://host.com"))
|
15
|
-
@mock_req2 = stub("mock_req", :
|
15
|
+
@mock_req2 = stub("mock_req", :stream => @mock_resp2,
|
16
16
|
:uri => URI.parse("http://host.com"))
|
17
17
|
|
18
18
|
@mock_thread = stub("mock_thread", :join => true,
|
@@ -142,7 +142,7 @@ class TestHelperMethods < Test::Unit::TestCase
|
|
142
142
|
|
143
143
|
def test_retrieve_unparsable
|
144
144
|
mock_resp = Kronk::Response.new StringIO.new(mock_200_response)
|
145
|
-
mock_req = stub("mock_req", :
|
145
|
+
mock_req = stub("mock_req", :stream => mock_resp,
|
146
146
|
:uri => URI.parse("http://host.com"))
|
147
147
|
|
148
148
|
Kronk::Request.expects(:new).
|
@@ -163,8 +163,8 @@ class TestHelperMethods < Test::Unit::TestCase
|
|
163
163
|
def test_retrieve_two_unparsable
|
164
164
|
mock_resp = Kronk::Response.new StringIO.new(mock_200_response)
|
165
165
|
|
166
|
-
Kronk::Request.any_instance.expects(:
|
167
|
-
Kronk::Request.any_instance.expects(:
|
166
|
+
Kronk::Request.any_instance.expects(:stream).returns mock_resp
|
167
|
+
Kronk::Request.any_instance.expects(:stream).returns mock_resp
|
168
168
|
|
169
169
|
retrieve "host1.com", "host2.com", :foo => "bar"
|
170
170
|
|
data/test/test_kronk.rb
CHANGED
@@ -482,7 +482,7 @@ class TestKronk < Test::Unit::TestCase
|
|
482
482
|
def test_follow_redirect_infinite
|
483
483
|
res = Kronk::Response.new mock_301_response
|
484
484
|
req = Kronk::Request.new "http://www.google.com/"
|
485
|
-
req.stubs(:
|
485
|
+
req.stubs(:stream).returns res
|
486
486
|
|
487
487
|
Kronk::Request.stubs(:new).
|
488
488
|
with("http://www.google.com/",{:follow_redirects => true}).returns req
|
@@ -501,7 +501,7 @@ class TestKronk < Test::Unit::TestCase
|
|
501
501
|
def test_num_follow_redirect
|
502
502
|
res = Kronk::Response.new mock_301_response
|
503
503
|
req = Kronk::Request.new "http://www.google.com/"
|
504
|
-
req.stubs(:
|
504
|
+
req.stubs(:stream).returns res
|
505
505
|
|
506
506
|
Kronk::Request.expects(:new).
|
507
507
|
with("http://www.google.com/",{:follow_redirects => 3}).returns(req).
|
@@ -517,7 +517,7 @@ class TestKronk < Test::Unit::TestCase
|
|
517
517
|
def test_follow_redirect_no_redirect
|
518
518
|
res = Kronk::Response.new mock_200_response
|
519
519
|
req = Kronk::Request.new "http://www.google.com/"
|
520
|
-
req.stubs(:
|
520
|
+
req.stubs(:stream).returns res
|
521
521
|
|
522
522
|
Kronk::Request.expects(:new).with("http://www.google.com/",{}).never
|
523
523
|
Kronk::Request.expects(:new).
|
@@ -530,7 +530,7 @@ class TestKronk < Test::Unit::TestCase
|
|
530
530
|
def test_do_not_follow_redirect
|
531
531
|
res = Kronk::Response.new mock_302_response
|
532
532
|
req = Kronk::Request.new "http://www.google.com/"
|
533
|
-
req.stubs(:
|
533
|
+
req.stubs(:stream).returns res
|
534
534
|
|
535
535
|
Kronk::Request.expects(:new).with("http://www.google.com/",{}).never
|
536
536
|
Kronk::Request.expects(:new).
|
data/test/test_player.rb
CHANGED
@@ -392,8 +392,8 @@ class TestPlayer < Test::Unit::TestCase
|
|
392
392
|
with("beta-example.com", :uri_suffix => '/test', :include_headers => true).
|
393
393
|
returns req2
|
394
394
|
|
395
|
-
req1.expects(:
|
396
|
-
req2.expects(:
|
395
|
+
req1.expects(:stream).returns resp1
|
396
|
+
req2.expects(:stream).returns resp2
|
397
397
|
|
398
398
|
@got_results = nil
|
399
399
|
|
@@ -485,7 +485,7 @@ class TestPlayer < Test::Unit::TestCase
|
|
485
485
|
|
486
486
|
req.each_with_index do |r, i|
|
487
487
|
mock_res = Kronk::Response.new resp[i]
|
488
|
-
mock_req = stub("mock_req", :
|
488
|
+
mock_req = stub("mock_req", :stream => mock_res,
|
489
489
|
:uri => URI.parse("http://host.com"))
|
490
490
|
|
491
491
|
Kronk::Request.stubs(:new).with(req[i], opts).returns mock_req
|
data/test/test_request.rb
CHANGED
@@ -360,6 +360,103 @@ class TestRequest < Test::Unit::TestCase
|
|
360
360
|
end
|
361
361
|
|
362
362
|
|
363
|
+
def test_oauth
|
364
|
+
oauth = {
|
365
|
+
:token => "blah",
|
366
|
+
:token_secret => "tsecret",
|
367
|
+
:consumer_key => "ckey",
|
368
|
+
:consumer_secret => "csecret"
|
369
|
+
}
|
370
|
+
|
371
|
+
req = Kronk::Request.new "foo.com", :oauth => oauth
|
372
|
+
auth = req.http_request['Authorization']
|
373
|
+
|
374
|
+
assert auth =~ /^OAuth\s/,
|
375
|
+
":oauth option should have triggered Authorization header"
|
376
|
+
|
377
|
+
assert auth =~ / oauth_consumer_key="ckey"/,
|
378
|
+
"Authorization should have the consumer key"
|
379
|
+
assert auth =~ / oauth_token="blah"/,
|
380
|
+
"Authorization should have token"
|
381
|
+
end
|
382
|
+
|
383
|
+
|
384
|
+
def test_oauth_basic_auth_collision
|
385
|
+
oauth = {
|
386
|
+
:token => "blah",
|
387
|
+
:token_secret => "tsecret",
|
388
|
+
:consumer_key => "ckey",
|
389
|
+
:consumer_secret => "csecret"
|
390
|
+
}
|
391
|
+
|
392
|
+
req = Kronk::Request.new "foo.com", :oauth => oauth,
|
393
|
+
:auth => {:username => "foo", :password => "bar"}
|
394
|
+
|
395
|
+
assert_equal({:username => "foo", :password => "bar"}, req.auth)
|
396
|
+
assert_equal(oauth, req.oauth)
|
397
|
+
|
398
|
+
auth = req.http_request['Authorization']
|
399
|
+
|
400
|
+
assert auth =~ /^OAuth\s/,
|
401
|
+
":oauth option should have triggered Authorization header"
|
402
|
+
|
403
|
+
assert auth =~ / oauth_consumer_key="ckey"/,
|
404
|
+
"Authorization should have the consumer key"
|
405
|
+
assert auth =~ / oauth_token="blah"/,
|
406
|
+
"Authorization should have token"
|
407
|
+
end
|
408
|
+
|
409
|
+
|
410
|
+
def test_oauth_from_headers
|
411
|
+
oauth = "OAuth oauth_consumer_key=\"ckey\", \
|
412
|
+
oauth_nonce=\"e95a6580533f4b122dc1b67bf28ea320\", \
|
413
|
+
oauth_signature=\"NLYgre5962QIYBQFjCQdt5nymBc%3D\", \
|
414
|
+
oauth_signature_method=\"HMAC-SHA1\", \
|
415
|
+
oauth_timestamp=\"1344556946\", \
|
416
|
+
oauth_token=\"blah\", \
|
417
|
+
oauth_version=\"1.0\""
|
418
|
+
|
419
|
+
req = Kronk::Request.new "foo.com", :headers => {'Authorization' => oauth}
|
420
|
+
auth = req.http_request['Authorization']
|
421
|
+
|
422
|
+
assert auth =~ /^OAuth\s/,
|
423
|
+
":oauth option should have triggered Authorization header"
|
424
|
+
|
425
|
+
assert auth =~ / oauth_consumer_key="ckey"/,
|
426
|
+
"Authorization should have the consumer key"
|
427
|
+
assert auth =~ / oauth_token="blah"/,
|
428
|
+
"Authorization should have token"
|
429
|
+
end
|
430
|
+
|
431
|
+
|
432
|
+
def test_oauth_from_headers_and_opts
|
433
|
+
oauth = "OAuth oauth_consumer_key=\"ckey\", \
|
434
|
+
oauth_nonce=\"e95a6580533f4b122dc1b67bf28ea320\", \
|
435
|
+
oauth_signature=\"NLYgre5962QIYBQFjCQdt5nymBc%3D\", \
|
436
|
+
oauth_signature_method=\"HMAC-SHA1\", \
|
437
|
+
oauth_timestamp=\"1344556946\", \
|
438
|
+
oauth_token=\"blah\", \
|
439
|
+
oauth_version=\"1.0\""
|
440
|
+
|
441
|
+
oath_opt = {
|
442
|
+
}
|
443
|
+
|
444
|
+
req = Kronk::Request.new "foo.com/bar",
|
445
|
+
:oauth => {:token => "newtoken"},
|
446
|
+
:headers => {'Authorization' => oauth}
|
447
|
+
|
448
|
+
auth = req.http_request['Authorization']
|
449
|
+
|
450
|
+
assert auth =~ /^OAuth\s/,
|
451
|
+
":oauth option should have triggered Authorization header"
|
452
|
+
|
453
|
+
assert auth =~ / oauth_consumer_key="ckey"/,
|
454
|
+
"Authorization should have the consumer key"
|
455
|
+
assert auth =~ / oauth_token="newtoken"/,
|
456
|
+
"Authorization should have token"
|
457
|
+
end
|
458
|
+
|
459
|
+
|
363
460
|
def test_auth_from_headers
|
364
461
|
req = Kronk::Request.parse File.read("test/mocks/get_request.txt")
|
365
462
|
assert_equal "bob", req.auth[:username]
|
@@ -451,8 +548,7 @@ class TestRequest < Test::Unit::TestCase
|
|
451
548
|
def test_retrieve_user_agent_default
|
452
549
|
expect_request "GET", "http://example.com",
|
453
550
|
:headers => {
|
454
|
-
'User-Agent' =>
|
455
|
-
"Kronk/#{Kronk::VERSION} (http://github.com/yaksnrainbows/kronk)"
|
551
|
+
'User-Agent' => Kronk::DEFAULT_USER_AGENT
|
456
552
|
}
|
457
553
|
|
458
554
|
Kronk::Request.new("http://example.com").retrieve
|
data/test/test_response.rb
CHANGED
@@ -54,11 +54,6 @@ class TestResponse < Test::Unit::TestCase
|
|
54
54
|
end
|
55
55
|
|
56
56
|
|
57
|
-
def test_init_no_cookies_from_file
|
58
|
-
assert @html_resp.cookies.empty?
|
59
|
-
end
|
60
|
-
|
61
|
-
|
62
57
|
def test_init_cookies
|
63
58
|
Kronk.cookie_jar.expects(:add_cookie).twice
|
64
59
|
|
@@ -72,13 +67,13 @@ class TestResponse < Test::Unit::TestCase
|
|
72
67
|
"ID=99d644506f26d85e:FF=0:TM=1290788168:LM=1290788168:S=VSMemgJxlmlToFA3",
|
73
68
|
"domain"=>".google.com",
|
74
69
|
"path"=>"/",
|
75
|
-
"
|
70
|
+
"expires_at"=>Time.parse("2012-11-25 08:16:08 -0800")},
|
76
71
|
{"name"=>"NID",
|
77
72
|
"value"=>
|
78
73
|
"41=CcmNDE4SfDu5cdTOYVkrCVjlrGO-oVbdo1awh_p8auk2gI4uaX1vNznO0QN8nZH4Mh9WprRy3yI2yd_Fr1WaXVru6Xq3adlSLGUTIRW8SzX58An2nH3D2PhAY5JfcJrl",
|
79
74
|
"domain"=>".google.com",
|
80
75
|
"path"=>"/",
|
81
|
-
"
|
76
|
+
"expires_at"=>Time.parse("2011-05-28 09:16:08 -0700"),
|
82
77
|
"http_only"=>true
|
83
78
|
}]
|
84
79
|
|
@@ -101,13 +96,13 @@ class TestResponse < Test::Unit::TestCase
|
|
101
96
|
"ID=99d644506f26d85e:FF=0:TM=1290788168:LM=1290788168:S=VSMemgJxlmlToFA3",
|
102
97
|
"domain"=>".google.com",
|
103
98
|
"path"=>"/",
|
104
|
-
"
|
99
|
+
"expires_at"=>Time.parse("2012-11-25 08:16:08 -0800")},
|
105
100
|
{"name"=>"NID",
|
106
101
|
"value"=>
|
107
102
|
"41=CcmNDE4SfDu5cdTOYVkrCVjlrGO-oVbdo1awh_p8auk2gI4uaX1vNznO0QN8nZH4Mh9WprRy3yI2yd_Fr1WaXVru6Xq3adlSLGUTIRW8SzX58An2nH3D2PhAY5JfcJrl",
|
108
103
|
"domain"=>".google.com",
|
109
104
|
"path"=>"/",
|
110
|
-
"
|
105
|
+
"expires_at"=>Time.parse("2011-05-28 09:16:08 -0700"),
|
111
106
|
"http_only"=>true
|
112
107
|
}]
|
113
108
|
|
metadata
CHANGED
@@ -1,182 +1,198 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: kronk
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.9.4
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 1
|
8
|
-
- 9
|
9
|
-
- 3
|
10
|
-
version: 1.9.3
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Jeremie Castagna
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-09-06 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
21
15
|
name: json
|
22
|
-
|
23
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
24
17
|
none: false
|
25
|
-
requirements:
|
18
|
+
requirements:
|
26
19
|
- - ~>
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
|
29
|
-
segments:
|
30
|
-
- 1
|
31
|
-
- 5
|
32
|
-
version: "1.5"
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.5'
|
33
22
|
type: :runtime
|
34
|
-
version_requirements: *id001
|
35
|
-
- !ruby/object:Gem::Dependency
|
36
|
-
name: cookiejar
|
37
23
|
prerelease: false
|
38
|
-
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
25
|
none: false
|
40
|
-
requirements:
|
26
|
+
requirements:
|
41
27
|
- - ~>
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.5'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: cookiejar
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
48
37
|
version: 0.3.0
|
49
38
|
type: :runtime
|
50
|
-
version_requirements: *id002
|
51
|
-
- !ruby/object:Gem::Dependency
|
52
|
-
name: ruby-path
|
53
39
|
prerelease: false
|
54
|
-
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
55
41
|
none: false
|
56
|
-
requirements:
|
42
|
+
requirements:
|
57
43
|
- - ~>
|
58
|
-
- !ruby/object:Gem::Version
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.3.0
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: ruby-path
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
64
53
|
version: 1.0.0
|
65
54
|
type: :runtime
|
66
|
-
|
67
|
-
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.0.0
|
62
|
+
- !ruby/object:Gem::Dependency
|
68
63
|
name: mime-types
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.18.0
|
70
|
+
type: :runtime
|
69
71
|
prerelease: false
|
70
|
-
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
73
|
none: false
|
72
|
-
requirements:
|
74
|
+
requirements:
|
73
75
|
- - ~>
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
hash: 95
|
76
|
-
segments:
|
77
|
-
- 1
|
78
|
-
- 18
|
79
|
-
- 0
|
76
|
+
- !ruby/object:Gem::Version
|
80
77
|
version: 1.18.0
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: simple_oauth
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 0.1.9
|
81
86
|
type: :runtime
|
82
|
-
version_requirements: *id004
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: rdoc
|
85
87
|
prerelease: false
|
86
|
-
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 0.1.9
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: rdoc
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
87
97
|
none: false
|
88
|
-
requirements:
|
98
|
+
requirements:
|
89
99
|
- - ~>
|
90
|
-
- !ruby/object:Gem::Version
|
91
|
-
|
92
|
-
segments:
|
93
|
-
- 3
|
94
|
-
- 10
|
95
|
-
version: "3.10"
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '3.10'
|
96
102
|
type: :development
|
97
|
-
version_requirements: *id005
|
98
|
-
- !ruby/object:Gem::Dependency
|
99
|
-
name: plist
|
100
103
|
prerelease: false
|
101
|
-
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
102
105
|
none: false
|
103
|
-
requirements:
|
106
|
+
requirements:
|
104
107
|
- - ~>
|
105
|
-
- !ruby/object:Gem::Version
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '3.10'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: plist
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ~>
|
116
|
+
- !ruby/object:Gem::Version
|
111
117
|
version: 3.1.0
|
112
118
|
type: :development
|
113
|
-
version_requirements: *id006
|
114
|
-
- !ruby/object:Gem::Dependency
|
115
|
-
name: nokogiri
|
116
119
|
prerelease: false
|
117
|
-
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
118
121
|
none: false
|
119
|
-
requirements:
|
122
|
+
requirements:
|
120
123
|
- - ~>
|
121
|
-
- !ruby/object:Gem::Version
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: 3.1.0
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: nokogiri
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ~>
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '1.4'
|
127
134
|
type: :development
|
128
|
-
version_requirements: *id007
|
129
|
-
- !ruby/object:Gem::Dependency
|
130
|
-
name: mocha
|
131
135
|
prerelease: false
|
132
|
-
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
133
137
|
none: false
|
134
|
-
requirements:
|
138
|
+
requirements:
|
135
139
|
- - ~>
|
136
|
-
- !ruby/object:Gem::Version
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '1.4'
|
142
|
+
- !ruby/object:Gem::Dependency
|
143
|
+
name: mocha
|
144
|
+
requirement: !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
146
|
+
requirements:
|
147
|
+
- - ~>
|
148
|
+
- !ruby/object:Gem::Version
|
142
149
|
version: 0.9.12
|
143
150
|
type: :development
|
144
|
-
version_requirements: *id008
|
145
|
-
- !ruby/object:Gem::Dependency
|
146
|
-
name: hoe
|
147
151
|
prerelease: false
|
148
|
-
|
152
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
153
|
none: false
|
150
|
-
requirements:
|
154
|
+
requirements:
|
151
155
|
- - ~>
|
152
|
-
- !ruby/object:Gem::Version
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: 0.9.12
|
158
|
+
- !ruby/object:Gem::Dependency
|
159
|
+
name: hoe
|
160
|
+
requirement: !ruby/object:Gem::Requirement
|
161
|
+
none: false
|
162
|
+
requirements:
|
163
|
+
- - ~>
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '3.0'
|
158
166
|
type: :development
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
167
|
+
prerelease: false
|
168
|
+
version_requirements: !ruby/object:Gem::Requirement
|
169
|
+
none: false
|
170
|
+
requirements:
|
171
|
+
- - ~>
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '3.0'
|
174
|
+
description: ! 'Kronk is a command line swiss-army-knife for HTTP services.
|
175
|
+
|
176
|
+
|
163
177
|
With Kronk, you easily parse and segregate data, run diffs between
|
178
|
+
|
164
179
|
the parsed data from different queries, and easily replay logs and loadtest
|
180
|
+
|
165
181
|
your HTTP applications.
|
166
|
-
|
167
|
-
|
168
|
-
|
182
|
+
|
183
|
+
|
184
|
+
Kronk was made possible by the sponsoring of YP.com.'
|
185
|
+
email:
|
169
186
|
- yaksnrainbows@gmail.com
|
170
|
-
executables:
|
187
|
+
executables:
|
171
188
|
- kronk
|
172
189
|
extensions: []
|
173
|
-
|
174
|
-
extra_rdoc_files:
|
190
|
+
extra_rdoc_files:
|
175
191
|
- History.rdoc
|
176
192
|
- Manifest.txt
|
177
193
|
- README.rdoc
|
178
194
|
- TODO.rdoc
|
179
|
-
files:
|
195
|
+
files:
|
180
196
|
- .autotest
|
181
197
|
- History.rdoc
|
182
198
|
- Manifest.txt
|
@@ -243,39 +259,31 @@ files:
|
|
243
259
|
- .gemtest
|
244
260
|
homepage: http://kronk.me
|
245
261
|
licenses: []
|
246
|
-
|
247
262
|
post_install_message:
|
248
|
-
rdoc_options:
|
263
|
+
rdoc_options:
|
249
264
|
- --main
|
250
265
|
- README.rdoc
|
251
|
-
require_paths:
|
266
|
+
require_paths:
|
252
267
|
- lib
|
253
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
268
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
254
269
|
none: false
|
255
|
-
requirements:
|
256
|
-
- -
|
257
|
-
- !ruby/object:Gem::Version
|
258
|
-
|
259
|
-
|
260
|
-
- 0
|
261
|
-
version: "0"
|
262
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
270
|
+
requirements:
|
271
|
+
- - ! '>='
|
272
|
+
- !ruby/object:Gem::Version
|
273
|
+
version: '0'
|
274
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
263
275
|
none: false
|
264
|
-
requirements:
|
265
|
-
- -
|
266
|
-
- !ruby/object:Gem::Version
|
267
|
-
|
268
|
-
segments:
|
269
|
-
- 0
|
270
|
-
version: "0"
|
276
|
+
requirements:
|
277
|
+
- - ! '>='
|
278
|
+
- !ruby/object:Gem::Version
|
279
|
+
version: '0'
|
271
280
|
requirements: []
|
272
|
-
|
273
281
|
rubyforge_project: kronk
|
274
282
|
rubygems_version: 1.8.24
|
275
283
|
signing_key:
|
276
284
|
specification_version: 3
|
277
285
|
summary: Kronk is a command line swiss-army-knife for HTTP services
|
278
|
-
test_files:
|
286
|
+
test_files:
|
279
287
|
- test/test_assertions.rb
|
280
288
|
- test/test_cmd.rb
|
281
289
|
- test/test_data_string.rb
|