2 * Copyright [2005] [University Corporation for Advanced Internet Development, Inc.]
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package edu.internet2.middleware.shibboleth.idp;
21 import org.apache.commons.codec.binary.Base64;
23 import edu.internet2.middleware.shibboleth.utils.FileUtils;
26 * MockObject unit tests for Shibboleth IdP Single Sign On component
28 * @author Will Norris (wnorris@memphis.edu)
30 public class SSOTest extends IdpTestCase {
33 * Initialize SSO request object
35 private void initRequest() {
37 request.setRemoteAddr("127.0.0.1");
38 request.setContextPath("/shibboleth-idp");
39 request.setProtocol("HTTP/1.1");
40 request.setScheme("https");
41 request.setServerName("idp.example.org");
42 request.setServerPort(443);
44 request.setMethod("GET");
45 request.setRequestURL("https://idp.example.org/shibboleth-idp/SSO");
46 request.setRequestURI("https://idp.example.org/shibboleth-idp/SSO");
50 * Basic working SSO flow using Artifact
54 public void testBasicSsoArtifactFlow() throws Exception {
56 resetServlet("data/idp/blackbox/conf/standard");
59 request.setupAddParameter("target", "https://sp.example.org/cgi-bin/login.cgi");
60 request.setupAddParameter("shire", "https://sp.example.org/Shibboleth.sso/SAML/Artifact");
61 request.setupAddParameter("providerId", "urn:x-shibtest:SP");
62 request.setRemoteUser("gpburdell");
66 assertTrue(response.getHeader("Location").matches(
67 "https://sp.example.org/Shibboleth.sso/SAML/Artifact?.*"
68 + "TARGET=https%3A%2F%2Fsp.example.org%2Fcgi-bin%2Flogin.cgi" + "&SAMLart=[^&]+"
73 * Basic working SSO flow using POST
77 public void testBasicSsoPostFlow() throws Exception {
79 resetServlet("data/idp/blackbox/conf/ssoPost");
82 request.setupAddParameter("target", "https://sp.example.org/cgi-bin/login.cgi");
83 request.setupAddParameter("shire", "https://sp.example.org/Shibboleth.sso/SAML/POST");
84 request.setupAddParameter("providerId", "urn:x-shibtest:SP");
85 request.setRemoteUser("gpburdell");
89 String bin64assertion = (String) request.getAttribute("assertion");
90 String assertion = new String(Base64.decodeBase64(bin64assertion.getBytes()));
92 assertTrue(responsesAreEqual(FileUtils.readFileToString(new File("data/idp/blackbox/sso/response01.txt"),
93 "utf-8"), assertion));
97 * SSO flow with invalid SP Acceptance URL
101 public void testSsoFlowWithInvalidSpAcceptanceUrl() throws Exception {
103 resetServlet("data/idp/blackbox/conf/standard");
106 request.setupAddParameter("target", "https://sp.example.org/cgi-bin/login.cgi");
107 request.setupAddParameter("shire", "https://invalid.edu/Shibboleth.sso/SAML/Artifact");
108 request.setupAddParameter("providerId", "urn:x-shibtest:SP");
109 request.setRemoteUser("gpburdell");
113 assertEquals("org.opensaml.SAMLException: Invalid assertion consumer service URL.", request
114 .getAttribute("errorText"));
118 * SSO flow with signed assertions
122 public void testSsoFlowWithSignedAssertions() throws Exception {
124 resetServlet("data/idp/blackbox/conf/signAssertions");
127 request.setupAddParameter("target", "https://sp.example.org/cgi-bin/login.cgi");
128 request.setupAddParameter("shire", "https://sp.example.org/Shibboleth.sso/SAML/POST");
129 request.setupAddParameter("providerId", "urn:x-shibtest:SP");
130 request.setRemoteUser("gpburdell");
134 String bin64assertion = (String) request.getAttribute("assertion");
135 String assertion = new String(Base64.decodeBase64(bin64assertion.getBytes()));
137 assertTrue(responsesAreEqual(FileUtils.readFileToString(new File("data/idp/blackbox/sso/response03.txt"),
138 "utf-8"), assertion));