-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathservice_url_converter_spec.rb
More file actions
203 lines (153 loc) · 5.66 KB
/
Copy pathservice_url_converter_spec.rb
File metadata and controls
203 lines (153 loc) · 5.66 KB
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
require 'spec_helper'
require 'addressable/template'
RSpec.describe WebValve::ServiceUrlConverter do
let(:url) { "http://bar.com" }
subject { described_class.new(url: url) }
describe '#regexp' do
it "returns a regexp" do
expect(subject.regexp).to be_a(Regexp)
end
context "with a regexp" do
let(:url) { %r{\Ahttp://foo\.com} }
it "returns the same object" do
expect(subject.regexp).to be_a(Regexp)
expect(subject.regexp).to equal(url)
end
end
context "with an Addressable::Template" do
let(:url) { Addressable::Template.new("http://foo.com{/path*}") }
it "returns the same object so WebMock can match against it directly" do
expect(subject.regexp).to equal(url)
end
end
context "with an empty url" do
let(:url) { "" }
it "matches empty string" do
expect("").to match(subject.regexp)
end
it "matches a string starting with a URL delimiter because the rest is just interpreted as suffix" do
expect(":do:do:dodo:do:do").to match(subject.regexp)
end
it "doesn't match a string that doesn't start with a delimiter" do
expect("jamietart:do:do:dodo:do:do").not_to match(subject.regexp)
end
end
context "with a boundary char on the end" do
let(:url) { "http://bar.com/" }
it "matches arbitrary suffixes" do
expect("http://bar.com/baz/bump/beep").to match(subject.regexp)
end
end
context "with multiple asterisks" do
let(:url) { "http://bar.com/**/bump" }
it "matches like a single asterisk" do
expect("http://bar.com/foo/bump").to match(subject.regexp)
end
it "doesn't match like a filesystem glob" do
expect("http://bar.com/foo/bar/bump").not_to match(subject.regexp)
end
end
context "with a trailing *" do
let(:url) { "http://bar.com/*" }
it "matches when empty" do
expect("http://bar.com/").to match(subject.regexp)
end
it "matches when existing" do
expect("http://bar.com/foobaloo").to match(subject.regexp)
end
it "matches with additional tokens" do
expect("http://bar.com/foobaloo/wink").to match(subject.regexp)
end
it "doesn't match when missing the trailing slash tho" do
expect("http://bar.com").not_to match(subject.regexp)
end
end
context "with a totally wildcarded protocol" do
let(:url) { "*://bar.com" }
it "matches http" do
expect("http://bar.com/").to match(subject.regexp)
end
it "matches anything else" do
expect("gopher://bar.com/").to match(subject.regexp)
end
it "matches empty" do
expect("://bar.com").to match(subject.regexp)
end
end
context "with a wildcarded partial protocol" do
let(:url) { "http*://bar.com" }
it "matches empty" do
expect("http://bar.com/").to match(subject.regexp)
end
it "matches full" do
expect("https://bar.com/").to match(subject.regexp)
end
end
context "with a TLD that is a substring of another TLD" do
let(:url) { "http://bar.co" }
it "doesn't match a different TLD when extending" do
expect("http://bar.com").not_to match(subject.regexp)
end
end
context "with a wildcard subdomain" do
let(:url) { "http://*.bar.com" }
it "matches" do
expect("http://foo.bar.com").to match(subject.regexp)
end
it "doesn't match when too many subdomains" do
expect("http://beep.foo.bar.com").not_to match(subject.regexp)
end
end
context "with a partial postfix wildcard subdomain" do
let(:url) { "http://foo*.bar.com" }
it "matches when present" do
expect("http://foobaz.bar.com").to match(subject.regexp)
end
it "matches when empty" do
expect("http://foo.bar.com").to match(subject.regexp)
end
it "doesn't match when out of order" do
expect("http://bazfoo.bar.com").not_to match(subject.regexp)
end
end
context "with a partial prefix wildcard subdomain" do
let(:url) { "http://*baz.bar.com" }
it "matches when present" do
expect("http://foobaz.bar.com").to match(subject.regexp)
end
it "matches when empty" do
expect("http://baz.bar.com").to match(subject.regexp)
end
end
context "with a wildcarded basic auth url" do
let(:url) { "http://*:*@bar.com" }
it "matches when present" do
expect("http://bilbo:baggins@bar.com").to match(subject.regexp)
end
it "doesn't match when malformed" do
expect("http://bilbobaggins@bar.com").not_to match(subject.regexp)
end
it "doesn't match when missing password part" do
expect("http://bilbo@bar.com").not_to match(subject.regexp)
end
end
context "with a wildcarded path" do
let(:url) { "http://bar.com/*/whatever" }
it "matches with arbitrarily spicy but legal, non-URL-significant characters" do
expect("http://bar.com/a0-_~[]!$'(),;%+/whatever").to match(subject.regexp)
end
it "doesn't match when you throw a URL-significant char in there" do
expect("http://bar.com/life=love/whatever").not_to match(subject.regexp)
end
end
context "with a wildcarded query param" do
let(:url) { "http://bar.com/whatever?foo=*&bar=bump" }
it "matches when present" do
expect("http://bar.com/whatever?foo=baz&bar=bump").to match(subject.regexp)
end
it "doesn't match when you throw a URL-significant char in there" do
expect("http://bar.com/whatever?foo=baz#&bar=bump").not_to match(subject.regexp)
end
end
end
end