SignatureManipulationHelper { public static void removeSignature( Document msg, int which ) { List<Element> signatures = DomUtilities.findChildren( msg, "Signature", NamespaceConstants.URI_NS_DS, true ); Element toRemove = signatures.get( which ); toRemove.getParentNode().removeChild( toRemove ); } private  SignatureManipulationHelper(); static void doubleSignature( Document msg, int whichToDouble, int whichToReplace ); static void removeSignature( Document msg, int which );  }
@Test public void testRemoveSignature_one_contained() { Document doc = generateDummySamlDocument( true, false, false ); List<Element> sigList = DomUtilities.findChildren( doc.getDocumentElement(), "Signature", URI_NS_DS, true ); assertEquals( 1, sigList.size() ); SignatureManipulationHelper.removeSignature( doc, 0 ); sigList = DomUtilities.findChildren( doc.getDocumentElement(), "Signature", URI_NS_DS, true ); assertTrue( sigList.isEmpty() ); }
@Test public void testRemoveSignature_0_two_contained() { Document doc = generateDummySamlDocument( true, true, false ); List<Element> sigList = DomUtilities.findChildren( doc.getDocumentElement(), "Signature", URI_NS_DS, true ); assertEquals( 2, sigList.size() ); SignatureManipulationHelper.removeSignature( doc, 0 ); sigList = DomUtilities.findChildren( doc.getDocumentElement(), "Signature", URI_NS_DS, true ); assertEquals( 1, sigList.size() ); assertEquals( "Assertion", sigList.get( 0 ).getParentNode().getLocalName() ); SignatureManipulationHelper.removeSignature( doc, 0 ); sigList = DomUtilities.findChildren( doc.getDocumentElement(), "Signature", URI_NS_DS, true ); assertTrue( sigList.isEmpty() ); }
@Test public void testRemoveSignature_1_two_contained() { Document doc = generateDummySamlDocument( true, true, false ); List<Element> sigList = DomUtilities.findChildren( doc.getDocumentElement(), "Signature", URI_NS_DS, true ); assertEquals( 2, sigList.size() ); SignatureManipulationHelper.removeSignature( doc, 1 ); sigList = DomUtilities.findChildren( doc.getDocumentElement(), "Signature", URI_NS_DS, true ); assertEquals( 1, sigList.size() ); assertEquals( "Response", sigList.get( 0 ).getParentNode().getLocalName() ); SignatureManipulationHelper.removeSignature( doc, 0 ); sigList = DomUtilities.findChildren( doc.getDocumentElement(), "Signature", URI_NS_DS, true ); assertTrue( sigList.isEmpty() ); }
@Test public void testRemoveSignature_0_two_contained_prepended() { Document doc = generateDummySamlDocument( true, true, true ); List<Element> sigList = DomUtilities.findChildren( doc.getDocumentElement(), "Signature", URI_NS_DS, true ); assertEquals( 2, sigList.size() ); SignatureManipulationHelper.removeSignature( doc, 0 ); sigList = DomUtilities.findChildren( doc.getDocumentElement(), "Signature", URI_NS_DS, true ); assertEquals( 1, sigList.size() ); assertEquals( "Assertion", sigList.get( 0 ).getParentNode().getLocalName() ); SignatureManipulationHelper.removeSignature( doc, 0 ); sigList = DomUtilities.findChildren( doc.getDocumentElement(), "Signature", URI_NS_DS, true ); assertTrue( sigList.isEmpty() ); }
@Test public void testRemoveSignature_1_two_contained_prepended() { Document doc = generateDummySamlDocument( true, true, true ); List<Element> sigList = DomUtilities.findChildren( doc.getDocumentElement(), "Signature", URI_NS_DS, true ); assertEquals( 2, sigList.size() ); SignatureManipulationHelper.removeSignature( doc, 1 ); sigList = DomUtilities.findChildren( doc.getDocumentElement(), "Signature", URI_NS_DS, true ); assertEquals( 1, sigList.size() ); assertEquals( "Response", sigList.get( 0 ).getParentNode().getLocalName() ); SignatureManipulationHelper.removeSignature( doc, 0 ); sigList = DomUtilities.findChildren( doc.getDocumentElement(), "Signature", URI_NS_DS, true ); assertTrue( sigList.isEmpty() ); }