Skip to content

Commit db2b1a3

Browse files
committed
Merge pull request #11 from zendesk/sdavidovitz/regex_audience
allow passing regexp for audience verification
2 parents 9cb2207 + 8e86671 commit db2b1a3

File tree

2 files changed

+42
-13
lines changed

2 files changed

+42
-13
lines changed

lib/samlr/condition.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def not_on_or_after_satisfied?
3535

3636
def audience_satisfied?
3737
audience.nil? || options[:audience].nil? ||
38-
audience == options[:audience]
38+
options[:audience] === audience
3939
end
4040

4141
private

test/unit/test_condition.rb

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ def condition(before, after)
88
Samlr::Condition.new(element, {})
99
end
1010

11+
def verify!
12+
Time.stub(:now, Time.at(1344379365)) do
13+
subject.verify!
14+
end
15+
end
16+
1117
describe Samlr::Condition do
1218
before do
1319
@not_before = (Time.now - 10*60)
@@ -25,17 +31,13 @@ def condition(before, after)
2531
end
2632

2733
it "raises an exception" do
28-
Time.stub(:now, Time.at(1344379365)) do
29-
assert subject.not_on_or_after_satisfied?
30-
assert subject.not_before_satisfied?
31-
refute subject.audience_satisfied?
34+
refute subject.audience_satisfied?
3235

33-
begin
34-
subject.verify!
35-
flunk "Expected exception"
36-
rescue Samlr::ConditionsError => e
37-
assert_match /Audience/, e.message
38-
end
36+
begin
37+
verify!
38+
flunk "Expected exception"
39+
rescue Samlr::ConditionsError => e
40+
assert_match /Audience/, e.message
3941
end
4042
end
4143
end
@@ -46,8 +48,35 @@ def condition(before, after)
4648
end
4749

4850
it "does not raise an exception" do
49-
Time.stub(:now, Time.at(1344379365)) do
50-
assert subject.verify!
51+
assert verify!
52+
end
53+
end
54+
55+
describe "using a regex" do
56+
describe "valid regex" do
57+
before do
58+
response.options[:audience] = /example\.(org|com)/
59+
end
60+
61+
it "does not raise an exception" do
62+
assert verify!
63+
end
64+
end
65+
66+
describe "invalid regex" do
67+
before do
68+
response.options[:audience] = /\A[a-z]\z/
69+
end
70+
71+
it "raises an exception" do
72+
refute subject.audience_satisfied?
73+
74+
begin
75+
verify!
76+
flunk "Expected exception"
77+
rescue Samlr::ConditionsError => e
78+
assert_match /Audience/, e.message
79+
end
5180
end
5281
end
5382
end

0 commit comments

Comments
 (0)