forked from SAML-Toolkits/ruby-saml
-
Notifications
You must be signed in to change notification settings - Fork 7
/
request_test.rb
53 lines (42 loc) · 1.89 KB
/
request_test.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
require File.expand_path(File.join(File.dirname(__FILE__), "test_helper"))
class RequestTest < Test::Unit::TestCase
context "Authrequest" do
should "create the deflated SAMLRequest URL parameter" do
settings = Onelogin::Saml::Settings.new
settings.idp_sso_target_url = "http://stuff.com"
auth_url = Onelogin::Saml::Authrequest.new.create(settings)
assert auth_url =~ /^http:\/\/stuff\.com\?SAMLRequest=/
payload = CGI.unescape(auth_url.split("=").last)
decoded = Base64.decode64(payload)
zstream = Zlib::Inflate.new(-Zlib::MAX_WBITS)
inflated = zstream.inflate(decoded)
zstream.finish
zstream.close
assert_match /^<samlp:AuthnRequest/, inflated
end
should "accept extra parameters" do
settings = Onelogin::Saml::Settings.new
settings.idp_sso_target_url = "http://stuff.com"
auth_url = Onelogin::Saml::Authrequest.new.create(settings, { :hello => "there" })
assert auth_url =~ /&hello=there$/
auth_url = Onelogin::Saml::Authrequest.new.create(settings, { :hello => nil })
assert auth_url =~ /&hello=$/
end
context "when the target url doesn't contain a query string" do
should "create the SAMLRequest parameter correctly" do
settings = Onelogin::Saml::Settings.new
settings.idp_sso_target_url = "http://stuff.com"
auth_url = Onelogin::Saml::Authrequest.new.create(settings)
assert auth_url =~ /^http:\/\/stuff.com\?SAMLRequest/
end
end
context "when the target url contains a query string" do
should "create the SAMLRequest parameter correctly" do
settings = Onelogin::Saml::Settings.new
settings.idp_sso_target_url = "http://stuff.com?field=value"
auth_url = Onelogin::Saml::Authrequest.new.create(settings)
assert auth_url =~ /^http:\/\/stuff.com\?field=value&SAMLRequest/
end
end
end
end