/
toolbar_spec.rb
135 lines (111 loc) · 4.17 KB
/
toolbar_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe Rack::Bug do
it "inserts the Rack::Bug toolbar" do
response = get "/"
response.should have_selector("div#rack_bug")
end
it "updates the Content-Length" do
response = get "/"
response["Content-Length"].should == response.body.size.to_s
end
it "serves the Rack::Bug assets under /__rack_bug__/" do
response = get "/__rack_bug__/bug.css"
response.should be_ok
end
it "modifies HTML responses with a charset" do
response = get "/", :content_type => "application/xhtml+xml; charset=utf-8"
response.should have_selector("div#rack_bug")
end
it "does not modify XMLHttpRequest responses" do
response = get "/", {}, { :xhr => true }
response.should_not have_selector("div#rack_bug")
end
it "modifies XHTML responses" do
response = get "/", :content_type => "application/xhtml+xml"
response.should have_selector("div#rack_bug")
end
it "does not modify non-HTML responses" do
response = get "/", :content_type => "text/csv"
response.should_not have_selector("div#rack_bug")
end
it "does not modify server errors" do
response = get "/error"
response.should_not have_selector("div#rack_bug")
end
context "redirected when not configured to intercept redirects" do
it "passes the redirect unmodified" do
response = get "/redirect"
response.status.should == 302
end
it "does not show the interception page" do
response = get "/redirect"
response.body.should_not contain("Location: /")
end
it "does not insert the toolbar" do
header 'cookie', ""
response = get "/redirect"
response.should_not have_selector("div#rack_bug")
end
it "does not insert the toolbar if even toolbar requested" do
response = get "/redirect"
response.should_not have_selector("div#rack_bug")
end
end
context "redirected when configured to intercept redirects" do
it "shows the interception page" do
response = get "/redirect", {}, "rack-bug.intercept_redirects" => true
response.should have_selector("div#rack_bug")
end
it "should provide a link to the target URL" do
response = get "/redirect", {}, "rack-bug.intercept_redirects" => true
response.should have_selector("a[href='http://example.org/']")
end
it "inserts the toolbar if requested" do
response = get "/redirect", {}, "rack-bug.intercept_redirects" => true
response.should have_selector("div#rack_bug")
end
it "does not inserts the toolbar if not requested" do
header 'cookie', ""
response = get "/redirect", {}, "rack-bug.intercept_redirects" => true
response.should_not have_selector("div#rack_bug")
end
end
context "configured with an IP address restriction" do
before do
rack_env "rack-bug.ip_masks", [IPAddr.new("127.0.0.1/255.255.255.0")]
end
it "inserts the Rack::Bug toolbar when the IP matches" do
response = get_via_rack "/", {}, "REMOTE_ADDR" => "127.0.0.2"
response.should have_selector("div#rack_bug")
end
it "is disabled when the IP doesn't match" do
response = get_via_rack "/", {}, "REMOTE_ADDR" => "128.0.0.1"
response.should_not have_selector("div#rack_bug")
end
it "doesn't use any panels" do
DummyPanel.should_not_receive(:new)
rack_env "rack-bug.panel_classes", [DummyPanel]
get_via_rack "/", {}, "REMOTE_ADDR" => "128.0.0.1"
end
end
context "configured with a password" do
before do
rack_env "rack-bug.password", "secret"
end
it "inserts the Rack::Bug toolbar when the password matches" do
sha = "545049d1c5e2a6e0dfefd37f9a9e0beb95241935"
set_cookie ["rack_bug_enabled=1", "rack_bug_password=#{sha}"]
response = get_via_rack "/"
response.should have_selector("div#rack_bug")
end
it "is disabled when the password doesn't match" do
response = get_via_rack "/"
response.should_not have_selector("div#rack_bug")
end
it "doesn't use any panels" do
DummyPanel.should_not_receive(:new)
rack_env "rack-bug.panel_classes", [DummyPanel]
get_via_rack "/"
end
end
end