/******************************************************************************* * Copyright 2014 Federal Chancellery Austria * MOA-ID has been developed in a cooperation between BRZ, the Federal * Chancellery Austria - ICT staff unit, and Graz University of Technology. * * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by * the European Commission - subsequent versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: * http://www.osor.eu/eupl/ * * Unless required by applicable law or agreed to in writing, software * distributed under the Licence is distributed on an "AS IS" basis, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and * limitations under the Licence. * * This product combines work with different licenses. See the "NOTICE" text * file for details on the various modules and licenses. * The "NOTICE" text file is part of the distribution. Any derivative works * that you distribute must include a readable copy of the "NOTICE" text file. ******************************************************************************/ /* * Copyright 2003 Federal Chancellery Austria * MOA-ID has been developed in a cooperation between BRZ, the Federal * Chancellery Austria - ICT staff unit, and Graz University of Technology. * * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by * the European Commission - subsequent versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: * http://www.osor.eu/eupl/ * * Unless required by applicable law or agreed to in writing, software * distributed under the Licence is distributed on an "AS IS" basis, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and * limitations under the Licence. * * This product combines work with different licenses. See the "NOTICE" text * file for details on the various modules and licenses. * The "NOTICE" text file is part of the distribution. Any derivative works * that you distribute must include a readable copy of the "NOTICE" text file. */ package test.at.gv.egovernment.moa.id.auth.parser; import at.gv.egovernment.moa.id.auth.builder.SAMLArtifactBuilder; import at.gv.egovernment.moa.id.auth.parser.SAMLArtifactParser; import at.gv.egovernment.moa.id.util.Random; import test.at.gv.egovernment.moa.id.UnitTestCase; /* * @author Paul Ivancsics * @version $Id$ */ public class SAMLArtifactParserTest extends UnitTestCase { private static String URL1 = "http://moa.gv.at/auth"; private static String URL2 = "https://moa.gv.at/auth"; public SAMLArtifactParserTest(String name) { super(name); } public void testParseTypeCode() throws Exception { String sessionID = Random.nextRandom(); String samlArtifact = new SAMLArtifactBuilder().build(URL1, sessionID, null); byte[] typeCode = new SAMLArtifactParser(samlArtifact).parseTypeCode(); assertEquals(typeCode[0], 0); assertEquals(typeCode[1], 1); } public void testParseAssertionHandleSameSessionID() throws Exception { // SAML artifacts for different authURL's but same sessionID MUST give same assertion handle String sessionID = Random.nextRandom(); String samlArtifact1 = new SAMLArtifactBuilder().build(URL1, sessionID, null); String samlArtifact2 = new SAMLArtifactBuilder().build(URL2, sessionID, null); String assertionHandle1 = new SAMLArtifactParser(samlArtifact1).parseAssertionHandle(); String assertionHandle2 = new SAMLArtifactParser(samlArtifact2).parseAssertionHandle(); assertEquals(assertionHandle1, assertionHandle2); } public void testParseAssertionHandleSameURL() throws Exception { // SAML artifacts for same authURL but different sessionID's MUST give different assertion handles String sessionID1 = Random.nextRandom(); String sessionID2 = Random.nextRandom(); String samlArtifact1 = new SAMLArtifactBuilder().build(URL1, sessionID1, null); String samlArtifact2 = new SAMLArtifactBuilder().build(URL1, sessionID2, null); String assertionHandle1 = new SAMLArtifactParser(samlArtifact1).parseAssertionHandle(); String assertionHandle2 = new SAMLArtifactParser(samlArtifact2).parseAssertionHandle(); assertFalse(assertionHandle1.equals(assertionHandle2)); } public void testParseAssertionHandleSameSAMLArtifact() throws Exception { // SAML artifact parsed twice MUST give same assertion handle each time String sessionID = Random.nextRandom(); String samlArtifact = new SAMLArtifactBuilder().build(URL1, sessionID, null); String assertionHandle1 = new SAMLArtifactParser(samlArtifact).parseAssertionHandle(); String assertionHandle2 = new SAMLArtifactParser(samlArtifact).parseAssertionHandle(); assertEquals(assertionHandle1, assertionHandle2); } }