rfuzz 0.6

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.
Files changed (136) hide show
  1. data/COPYING +55 -0
  2. data/LICENSE +55 -0
  3. data/README +252 -0
  4. data/Rakefile +48 -0
  5. data/doc/rdoc/classes/RFuzz.html +146 -0
  6. data/doc/rdoc/classes/RFuzz/HttpClient.html +481 -0
  7. data/doc/rdoc/classes/RFuzz/HttpClient.src/M000010.html +24 -0
  8. data/doc/rdoc/classes/RFuzz/HttpClient.src/M000011.html +34 -0
  9. data/doc/rdoc/classes/RFuzz/HttpClient.src/M000012.html +49 -0
  10. data/doc/rdoc/classes/RFuzz/HttpClient.src/M000013.html +49 -0
  11. data/doc/rdoc/classes/RFuzz/HttpClient.src/M000014.html +57 -0
  12. data/doc/rdoc/classes/RFuzz/HttpClient.src/M000015.html +37 -0
  13. data/doc/rdoc/classes/RFuzz/HttpClient.src/M000016.html +26 -0
  14. data/doc/rdoc/classes/RFuzz/HttpClient.src/M000017.html +34 -0
  15. data/doc/rdoc/classes/RFuzz/HttpClient.src/M000018.html +18 -0
  16. data/doc/rdoc/classes/RFuzz/HttpClient.src/M000019.html +26 -0
  17. data/doc/rdoc/classes/RFuzz/HttpEncoding.html +294 -0
  18. data/doc/rdoc/classes/RFuzz/HttpEncoding.src/M000001.html +26 -0
  19. data/doc/rdoc/classes/RFuzz/HttpEncoding.src/M000002.html +18 -0
  20. data/doc/rdoc/classes/RFuzz/HttpEncoding.src/M000003.html +26 -0
  21. data/doc/rdoc/classes/RFuzz/HttpEncoding.src/M000004.html +18 -0
  22. data/doc/rdoc/classes/RFuzz/HttpEncoding.src/M000005.html +32 -0
  23. data/doc/rdoc/classes/RFuzz/HttpEncoding.src/M000006.html +18 -0
  24. data/doc/rdoc/classes/RFuzz/HttpEncoding.src/M000007.html +20 -0
  25. data/doc/rdoc/classes/RFuzz/HttpEncoding.src/M000008.html +20 -0
  26. data/doc/rdoc/classes/RFuzz/HttpEncoding.src/M000009.html +32 -0
  27. data/doc/rdoc/classes/RFuzz/HttpResponse.html +180 -0
  28. data/doc/rdoc/classes/RFuzz/Notifier.html +252 -0
  29. data/doc/rdoc/classes/RFuzz/Notifier.src/M000044.html +17 -0
  30. data/doc/rdoc/classes/RFuzz/Notifier.src/M000045.html +17 -0
  31. data/doc/rdoc/classes/RFuzz/Notifier.src/M000046.html +17 -0
  32. data/doc/rdoc/classes/RFuzz/Notifier.src/M000047.html +17 -0
  33. data/doc/rdoc/classes/RFuzz/Notifier.src/M000048.html +17 -0
  34. data/doc/rdoc/classes/RFuzz/Notifier.src/M000049.html +17 -0
  35. data/doc/rdoc/classes/RFuzz/RandomGenerator.html +362 -0
  36. data/doc/rdoc/classes/RFuzz/RandomGenerator.src/M000032.html +21 -0
  37. data/doc/rdoc/classes/RFuzz/RandomGenerator.src/M000033.html +23 -0
  38. data/doc/rdoc/classes/RFuzz/RandomGenerator.src/M000036.html +22 -0
  39. data/doc/rdoc/classes/RFuzz/RandomGenerator.src/M000037.html +20 -0
  40. data/doc/rdoc/classes/RFuzz/RandomGenerator.src/M000038.html +22 -0
  41. data/doc/rdoc/classes/RFuzz/RandomGenerator.src/M000039.html +20 -0
  42. data/doc/rdoc/classes/RFuzz/RandomGenerator.src/M000040.html +18 -0
  43. data/doc/rdoc/classes/RFuzz/RandomGenerator.src/M000041.html +18 -0
  44. data/doc/rdoc/classes/RFuzz/RandomGenerator.src/M000042.html +22 -0
  45. data/doc/rdoc/classes/RFuzz/RandomGenerator.src/M000043.html +18 -0
  46. data/doc/rdoc/classes/RFuzz/Sampler.html +383 -0
  47. data/doc/rdoc/classes/RFuzz/Sampler.src/M000056.html +19 -0
  48. data/doc/rdoc/classes/RFuzz/Sampler.src/M000057.html +23 -0
  49. data/doc/rdoc/classes/RFuzz/Sampler.src/M000058.html +26 -0
  50. data/doc/rdoc/classes/RFuzz/Sampler.src/M000059.html +18 -0
  51. data/doc/rdoc/classes/RFuzz/Sampler.src/M000060.html +18 -0
  52. data/doc/rdoc/classes/RFuzz/Sampler.src/M000061.html +18 -0
  53. data/doc/rdoc/classes/RFuzz/Sampler.src/M000062.html +18 -0
  54. data/doc/rdoc/classes/RFuzz/Sampler.src/M000063.html +19 -0
  55. data/doc/rdoc/classes/RFuzz/Sampler.src/M000064.html +18 -0
  56. data/doc/rdoc/classes/RFuzz/Sampler.src/M000065.html +23 -0
  57. data/doc/rdoc/classes/RFuzz/Sampler.src/M000066.html +18 -0
  58. data/doc/rdoc/classes/RFuzz/Sampler.src/M000067.html +20 -0
  59. data/doc/rdoc/classes/RFuzz/Session.html +415 -0
  60. data/doc/rdoc/classes/RFuzz/Session.src/M000020.html +31 -0
  61. data/doc/rdoc/classes/RFuzz/Session.src/M000021.html +18 -0
  62. data/doc/rdoc/classes/RFuzz/Session.src/M000022.html +18 -0
  63. data/doc/rdoc/classes/RFuzz/Session.src/M000023.html +34 -0
  64. data/doc/rdoc/classes/RFuzz/Session.src/M000024.html +19 -0
  65. data/doc/rdoc/classes/RFuzz/Session.src/M000025.html +19 -0
  66. data/doc/rdoc/classes/RFuzz/Session.src/M000026.html +26 -0
  67. data/doc/rdoc/classes/RFuzz/Session.src/M000027.html +29 -0
  68. data/doc/rdoc/classes/RFuzz/Session.src/M000028.html +19 -0
  69. data/doc/rdoc/classes/RFuzz/Session.src/M000029.html +18 -0
  70. data/doc/rdoc/classes/RFuzz/Session.src/M000030.html +18 -0
  71. data/doc/rdoc/classes/RFuzz/Session.src/M000031.html +23 -0
  72. data/doc/rdoc/classes/RFuzz/StatsTracker.html +242 -0
  73. data/doc/rdoc/classes/RFuzz/StatsTracker.src/M000050.html +19 -0
  74. data/doc/rdoc/classes/RFuzz/StatsTracker.src/M000051.html +19 -0
  75. data/doc/rdoc/classes/RFuzz/StatsTracker.src/M000052.html +18 -0
  76. data/doc/rdoc/classes/RFuzz/StatsTracker.src/M000053.html +18 -0
  77. data/doc/rdoc/classes/RFuzz/StatsTracker.src/M000054.html +28 -0
  78. data/doc/rdoc/classes/RFuzz/StatsTracker.src/M000055.html +18 -0
  79. data/doc/rdoc/created.rid +1 -0
  80. data/doc/rdoc/files/COPYING.html +168 -0
  81. data/doc/rdoc/files/LICENSE.html +168 -0
  82. data/doc/rdoc/files/README.html +473 -0
  83. data/doc/rdoc/files/lib/rfuzz/client_rb.html +111 -0
  84. data/doc/rdoc/files/lib/rfuzz/random_rb.html +116 -0
  85. data/doc/rdoc/files/lib/rfuzz/rfuzz_rb.html +109 -0
  86. data/doc/rdoc/files/lib/rfuzz/session_rb.html +111 -0
  87. data/doc/rdoc/files/lib/rfuzz/stats_rb.html +113 -0
  88. data/doc/rdoc/fr_class_index.html +35 -0
  89. data/doc/rdoc/fr_file_index.html +34 -0
  90. data/doc/rdoc/fr_method_index.html +93 -0
  91. data/doc/rdoc/index.html +24 -0
  92. data/doc/rdoc/rdoc-style.css +208 -0
  93. data/examples/amazon_headers.rb +38 -0
  94. data/examples/hpricot_pudding.rb +22 -0
  95. data/examples/kill_routes.rb +26 -0
  96. data/examples/mongrel_test_suite/lib/gen.rb +24 -0
  97. data/examples/mongrel_test_suite/test/camping/static_files.rb +9 -0
  98. data/examples/mongrel_test_suite/test/camping/upload_file.rb +9 -0
  99. data/examples/mongrel_test_suite/test/camping/upload_progress.rb +9 -0
  100. data/examples/mongrel_test_suite/test/http/base_protocol.rb +23 -0
  101. data/examples/mongrel_test_suite/test/nitro/upload_file.rb +9 -0
  102. data/examples/mongrel_test_suite/test/nitro/upload_progress.rb +9 -0
  103. data/examples/mongrel_test_suite/test/rails/static_files.rb +9 -0
  104. data/examples/mongrel_test_suite/test/rails/upload_file.rb +9 -0
  105. data/examples/mongrel_test_suite/test/rails/upload_progress.rb +9 -0
  106. data/examples/perftest.rb +30 -0
  107. data/ext/fuzzrnd/ext_help.h +14 -0
  108. data/ext/fuzzrnd/extconf.rb +6 -0
  109. data/ext/fuzzrnd/fuzzrnd.c +149 -0
  110. data/ext/http11_client/ext_help.h +14 -0
  111. data/ext/http11_client/extconf.rb +6 -0
  112. data/ext/http11_client/http11_client.c +288 -0
  113. data/ext/http11_client/http11_parser.c +629 -0
  114. data/ext/http11_client/http11_parser.h +46 -0
  115. data/ext/http11_client/http11_parser.rl +169 -0
  116. data/lib/rfuzz/client.rb +498 -0
  117. data/lib/rfuzz/random.rb +110 -0
  118. data/lib/rfuzz/rfuzz.rb +12 -0
  119. data/lib/rfuzz/session.rb +154 -0
  120. data/lib/rfuzz/stats.rb +159 -0
  121. data/resources/defaults.yaml +2 -0
  122. data/resources/words.txt +3310 -0
  123. data/test/coverage/index.html +388 -0
  124. data/test/coverage/lib-rfuzz-client_rb.html +1127 -0
  125. data/test/coverage/lib-rfuzz-random_rb.html +739 -0
  126. data/test/coverage/lib-rfuzz-session_rb.html +783 -0
  127. data/test/coverage/lib-rfuzz-stats_rb.html +788 -0
  128. data/test/server.rb +101 -0
  129. data/test/test_client.rb +164 -0
  130. data/test/test_fuzzrnd.rb +31 -0
  131. data/test/test_httpparser.rb +48 -0
  132. data/test/test_random.rb +75 -0
  133. data/test/test_session.rb +33 -0
  134. data/test/test_stats.rb +45 -0
  135. data/tools/rakehelp.rb +119 -0
  136. metadata +201 -0
@@ -0,0 +1,101 @@
1
+ require 'rubygems'
2
+ require 'mongrel'
3
+ require 'digest/md5'
4
+ require 'rfuzz/random'
5
+
6
+ $cookies_count = 0
7
+
8
+ class CookieHandler < Mongrel::HttpHandler
9
+ def process(request, response)
10
+ if request.params["HTTP_COOKIE"]
11
+ $cookies_count += 1
12
+ end
13
+
14
+ response.start do |head,out|
15
+ head["Set-Cookie"] = "_session_id=ASDFADSFASDFADSFADSFDSAFADSF"
16
+ out.write("test")
17
+ end
18
+ end
19
+ end
20
+
21
+ # Returns one of three things to the client as the response body depending
22
+ # on what the client sends:
23
+ # * the body if larger than 0
24
+ # * the HTTP_X_TESTSEND if that's given
25
+ # * the REQUEST_METHOD if nothing else
26
+ class TestHandler < Mongrel::HttpHandler
27
+ def process(request, response)
28
+ response.start do |head,out|
29
+ head["Content-Type"] = "text/html"
30
+ if request.body.length > 0
31
+ out.write(request.body.read)
32
+ elsif request.params["HTTP_X_TESTSEND"]
33
+ out.write(request.params["HTTP_X_TESTSEND"])
34
+ else
35
+ out.write(request.params["REQUEST_METHOD"])
36
+ end
37
+ end
38
+ end
39
+ end
40
+
41
+
42
+ # Returns a test chunked encoding with @random size chunks and then
43
+ # sets the X-Real-Length header to what the resulting body should be,
44
+ # and X-MD5-Sum to the hash that should result.
45
+ class ChunkedHandler < Mongrel::HttpHandler
46
+ def process(request, response)
47
+ response.start do |head,out|
48
+ head['Transfer-Encoding'] = "chunked"
49
+
50
+ chunks = []
51
+ @rand = RFuzz::RandomGenerator.new(open("resources/words.txt").read.split("\n"))
52
+ (@rand.num(20)+10).times {
53
+ chunks << @rand.base64(@rand.num(60)+10).join('')
54
+ }
55
+
56
+ result_body = chunks.join('')
57
+ head['X-Real-Length'] = result_body.length
58
+ head['X-MD5-Sum'] = Digest::MD5.new(result_body)
59
+
60
+ chunks.each_with_index {|c,i|
61
+ # chunk header
62
+ out.write("#{c.length.to_s(base=16)}#{random_chunk_header}\r\n")
63
+ out.write(c)
64
+ out.write("\r\n")
65
+ }
66
+
67
+ case @rand.num(4)
68
+ when 0
69
+ out.write("0\r\n")
70
+ when 1
71
+ out.write("\r\n")
72
+ when 2
73
+ out.write("0\r\n#{@random_chunk_header}")
74
+ when 3
75
+ out.write("\r\n#{@random_chunk_header}")
76
+ end
77
+ end
78
+ end
79
+
80
+ def random_chunk_header
81
+ if @rand.num(1) == 0
82
+ hash = @rand.hash_of(1,5,:words)[0]
83
+ hash.collect {|k,v| ";#{k}=#{v}"}
84
+ else
85
+ ""
86
+ end
87
+ end
88
+ end
89
+
90
+ config = Mongrel::Configurator.new :host => "127.0.0.1", :port => "3001" do
91
+ listener do
92
+ uri "/cookies", :handler => CookieHandler.new
93
+ uri "/test", :handler => TestHandler.new
94
+ uri "/chunked", :handler => ChunkedHandler.new
95
+ uri "/error404", :handler => Mongrel::Error404Handler.new("file missing")
96
+ redirect "/redir", "/test"
97
+ end
98
+ end
99
+
100
+
101
+ $server = Thread.new { config.run; config.join }
@@ -0,0 +1,164 @@
1
+
2
+ # Copyright (c) 2006 Zed A. Shaw
3
+ # You can redistribute it and/or modify it under the same terms as Ruby.
4
+
5
+ require 'test/unit'
6
+ require 'rfuzz/client'
7
+ load 'test/server.rb'
8
+ require 'digest/md5'
9
+
10
+ include RFuzz
11
+
12
+ class TestNotifier < Notifier
13
+ attr_reader :event_count
14
+
15
+ def initialize
16
+ @event_count = 0
17
+ end
18
+
19
+ def connect(state)
20
+ @event_count += 1
21
+ end
22
+
23
+ def send_request(state)
24
+ @event_count += 1
25
+ end
26
+
27
+ def read_header(state)
28
+ @event_count += 1
29
+ end
30
+
31
+ def read_body(state)
32
+ @event_count += 1
33
+ end
34
+
35
+ def close(state)
36
+ @event_count += 1
37
+ end
38
+ end
39
+
40
+ class RFuzzClientTest < Test::Unit::TestCase
41
+
42
+ def setup
43
+ @port = 3001
44
+ @host = "127.0.0.1"
45
+ @client = HttpClient.new(@host, @port, :redirect => 10)
46
+ end
47
+
48
+ def tearDown
49
+ end
50
+
51
+ def test_cookies
52
+ cl = HttpClient.new(@host, @port)
53
+ cl.get("/cookies")
54
+ assert cl.cookies["_session_id"]
55
+ assert_equal 0, $cookies_count
56
+ cl.get("/cookies")
57
+ assert cl.cookies["_session_id"]
58
+ assert_equal 1, $cookies_count
59
+ end
60
+
61
+ def test_get
62
+ resp = @client.get("/test/get")
63
+ assert_method "GET", resp
64
+ resp = @client.get("/test/get/query", :query => {"q" => "test"}, :head => { "X-TestSend" => "Status"})
65
+ assert_header("Status", resp)
66
+ resp = @client.get("/test/get/query/header",
67
+ :query => {"q" => "test", "a" => [1,2,3]},
68
+ :head => { "X-TestSend" => "Status"})
69
+ assert_header("Status", resp)
70
+ end
71
+
72
+ def test_redirect
73
+ resp = @client.get("/redir")
74
+ assert_equal "200", resp.http_status, "wrong status"
75
+ end
76
+
77
+ def test_post
78
+ resp = @client.post("/test/post")
79
+ assert_method "POST", resp
80
+ resp = @client.post("/test/post/header", :head => {"X-TestSend" => "Status"}, :body => "TEST BODY")
81
+ assert_body "TEST BODY", resp
82
+ end
83
+
84
+ def test_put
85
+ resp = @client.put("/test/put")
86
+ assert_method("PUT",resp)
87
+ resp = @client.put("/test/put/header", :head => {"X-TestSend" => "Status"})
88
+ assert_header("Status", resp)
89
+ resp = @client.put("/test/put/header/multi", :head => {"X-TestSend" => ["Status", "AGAIN"]})
90
+ end
91
+
92
+ def test_delete
93
+ resp = @client.delete("/test/delete")
94
+ assert_method("DELETE", resp)
95
+ end
96
+
97
+ def test_head
98
+ resp = @client.head("/test/head")
99
+ assert_method("HEAD", resp)
100
+ end
101
+
102
+ def test_status
103
+ resp = @client.get("/error404")
104
+ assert_status "404", resp
105
+ resp = @client.get("/test/200")
106
+ assert_status "200", resp
107
+ end
108
+
109
+ def test_overrides
110
+ cl = HttpClient.new(@host, @port, :head => {"X-Override" => "Test"})
111
+ assert cl.options[:head], "missing override header"
112
+ end
113
+
114
+ def test_allowed_methods
115
+ cl = HttpClient.new(@host, @port, :allowed_methods => [:nada])
116
+ assert_raises RuntimeError do
117
+ cl.get("/test/wrongmethod")
118
+ end
119
+ end
120
+
121
+
122
+ def test_notifier
123
+ cl = HttpClient.new(@host, @port, :notifier => TestNotifier.new)
124
+ cl.get("/test/notifier")
125
+ assert_equal 10, cl.notifier.event_count, "not all events fired"
126
+
127
+ # try to get notified about errors
128
+ assert_raises Errno::ECONNREFUSED do
129
+ cl = HttpClient.new(@host, "300", :notifier => TestNotifier.new)
130
+ cl.get("/test/notifier/fail")
131
+ end
132
+
133
+ assert_equal 2, cl.notifier.event_count, "not all events fired"
134
+ end
135
+
136
+
137
+ def test_chunked_encoding
138
+ 50.times do
139
+ resp = @client.get("/chunked")
140
+ assert_equal resp["X_REAL_LENGTH"].to_i, resp.http_body.length
141
+ assert_equal resp["X_MD5_SUM"],Digest::MD5.new(resp.http_body).to_s
142
+ end
143
+ end
144
+
145
+
146
+ def assert_method(method, resp)
147
+ assert_equal method, resp.http_body
148
+ end
149
+
150
+ def assert_body(body, resp)
151
+ assert_equal body, resp.http_body
152
+ end
153
+
154
+ def assert_header(sent, resp)
155
+ assert_equal sent, resp.http_body
156
+ end
157
+
158
+ def assert_status(status, resp)
159
+ assert_equal status, resp.http_status
160
+ end
161
+
162
+
163
+
164
+ end
@@ -0,0 +1,31 @@
1
+ # Copyright (c) 2006 Zed A. Shaw
2
+ # You can redistribute it and/or modify it under the same terms as Ruby.
3
+
4
+ require 'test/unit'
5
+ require 'fuzzrnd'
6
+
7
+ include RFuzz
8
+
9
+ class FuzzRndTest < Test::Unit::TestCase
10
+
11
+ def test_seed_data
12
+ fr = FuzzRnd.new("TEST SEED")
13
+ d1 = fr.data(100)
14
+ assert_equal 100, d1.length, "wrong length"
15
+
16
+ d2 = fr.seed("TEST SEED").data(100)
17
+ assert_equal 100, d2.length, "wrong length"
18
+
19
+ assert_equal d1,d2, "same keys should produce same random"
20
+ end
21
+
22
+
23
+ def test_gen_numbers
24
+ fr = FuzzRnd.new("TEST SEED")
25
+ ints = fr.data(100 * 4).unpack("N*")
26
+ assert_equal 100,ints.length, "didn't get 100 ints"
27
+
28
+ floats = fr.data(50 * 8).unpack("G*")
29
+ assert_equal 50,floats.length, "didn't get 50 floats"
30
+ end
31
+ end
@@ -0,0 +1,48 @@
1
+
2
+ # Copyright (c) 2006 Zed A. Shaw
3
+ # You can redistribute it and/or modify it under the same terms as Ruby.
4
+
5
+ require 'test/unit'
6
+ require 'http11_client'
7
+ require 'socket'
8
+
9
+ include RFuzz
10
+
11
+ class HttpClientParserTest < Test::Unit::TestCase
12
+
13
+ def test_parse_simple
14
+ parser = HttpClientParser.new
15
+ req = HttpResponse.new
16
+ http = "HTTP/1.1 200 OK\r\nContent-Length: 20\r\n\r\n01234567890123456789"
17
+ nread = parser.execute(req, http, 0)
18
+ assert_equal 39, nread, "Failed to parse the full HTTP request after #{nread}"
19
+ assert parser.finished?, "Parser didn't finish"
20
+ assert !parser.error?, "Parser had error"
21
+ assert nread == parser.nread, "Number read returned from execute does not match"
22
+ assert_equal "20", req["CONTENT_LENGTH"], "Wrong content length header"
23
+ parser.reset
24
+ assert parser.nread == 0, "Number read after reset should be 0"
25
+ end
26
+
27
+ def parse(body, size, expect_req)
28
+ parser = HttpClientParser.new
29
+ req = HttpResponse.new
30
+ nread = parser.execute(req, body, 0)
31
+ assert_equal nread, body.length
32
+ assert !parser.error?
33
+ assert parser.finished?
34
+
35
+ # check data results
36
+ assert_equal size, req.http_chunk_size.to_i
37
+ expect_req.each {|k,v|assert_not_nil k; assert_equal req[k.upcase], v}
38
+ end
39
+
40
+ def test_http_parser
41
+ parse "3;test=stuff;lone\r\n", 3, {"test" => "stuff", "lone" => ""}
42
+ parse "0\r\n",0,{}
43
+ parse "\r\n",0,{}
44
+ parse ";test;test2=test2\r\n",0,{"test" => "", "test2" => "test2"}
45
+ parse "0;test;test2=test2\r\n",0,{"test" => "", "test2" => "test2"}
46
+ end
47
+
48
+ end
@@ -0,0 +1,75 @@
1
+ # Copyright (c) 2006 Zed A. Shaw
2
+ # You can redistribute it and/or modify it under the same terms as Ruby.
3
+
4
+ require 'test/unit'
5
+ require 'socket'
6
+ require 'rfuzz/random'
7
+
8
+ include RFuzz
9
+
10
+ class RandomGeneratorTest < Test::Unit::TestCase
11
+ def setup
12
+ @rand = RandomGenerator.new(open("resources/words.txt").read.split("\n"))
13
+ end
14
+
15
+ def test_headers
16
+ h = @rand.headers(20,10)
17
+ assert_equal 20,h.length, "wrong number of headers"
18
+
19
+ [:words,:base64,:uris,:byte_array,:ints,:floats].each do |t|
20
+ h = @rand.headers(20,10,type=t)
21
+ assert_equal 20,h.length
22
+ end
23
+
24
+ end
25
+
26
+ def test_queries
27
+ q = @rand.queries(20,10)
28
+ assert_equal 20,q.length, "wrong number of queries"
29
+
30
+ [:base64,:uris,:byte_array,:ints,:floats].each do |t|
31
+ q = @rand.queries(20,10,type=t)
32
+ assert_equal 20,q.length
33
+ end
34
+
35
+ end
36
+
37
+ def test_uris
38
+ u = @rand.uris(20, 10)
39
+ assert_equal 20,u.length,"wrong number of uris"
40
+ end
41
+
42
+ def test_words
43
+ w = @rand.words(100)
44
+ assert_equal 100,w.length,"wrong number of words"
45
+ end
46
+
47
+ def test_bytes
48
+ b = @rand.bytes(100)
49
+ assert_not_nil b
50
+ end
51
+
52
+ def test_base64
53
+ b = @rand.base64(100,20)
54
+ assert_not_nil b
55
+ assert_equal 100,b.length
56
+ end
57
+
58
+ def test_num
59
+ b1 = @rand.num(100)
60
+ assert_not_nil b1
61
+ assert b1 < 100, "returned by greater than 10"
62
+ end
63
+
64
+ def test_ints
65
+ i = @rand.ints(100)
66
+ assert_equal 100, i.length, "wrong length"
67
+ end
68
+
69
+ def test_floats
70
+ f = @rand.floats(100)
71
+ assert_equal 100, f.length, "wrong length"
72
+ end
73
+
74
+ end
75
+
@@ -0,0 +1,33 @@
1
+ # Copyright (c) 2006 Zed A. Shaw
2
+ # You can redistribute it and/or modify it under the same terms as Ruby.
3
+
4
+ require 'test/unit'
5
+ require 'rfuzz/session'
6
+ include RFuzz
7
+
8
+ class SessionTest < Test::Unit::TestCase
9
+
10
+ def test_simple_session
11
+ s = Session.new :host => "localhost", :port => 3001
12
+ s.run 3, :save_as => ["test/runs.csv","test/counts.csv"] do |c,r|
13
+ len = r.num(10) + 1
14
+ s.count :len, len
15
+ uris = r.uris(10,len)
16
+
17
+ uris.each do |u|
18
+ s.count_errors(:legal) do
19
+ # first sample for legal uris
20
+ resp = c.get(u)
21
+ s.count resp.http_status
22
+ s.track :status, resp.http_status
23
+ end
24
+ end
25
+ end
26
+
27
+ assert_equal 3, s.tracking.length
28
+ assert File.exist?("test/runs.csv")
29
+ assert File.exist?("test/counts.csv")
30
+ File.unlink "test/counts.csv"
31
+ File.unlink "test/runs.csv"
32
+ end
33
+ end