From 95b21a826e5d81fdeabcf4673a9e87047edaec9d Mon Sep 17 00:00:00 2001 From: Thomas Date: Wed, 4 Dec 2019 22:54:51 +0100 Subject: to some more code quality tasks --- .../eaaf/core/impl/idp/auth/IdentityLinkTest.java | 101 +++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 eaaf_core/src/test/java/at/gv/egiz/eaaf/core/impl/idp/auth/IdentityLinkTest.java (limited to 'eaaf_core/src/test/java/at/gv/egiz/eaaf/core/impl/idp/auth/IdentityLinkTest.java') diff --git a/eaaf_core/src/test/java/at/gv/egiz/eaaf/core/impl/idp/auth/IdentityLinkTest.java b/eaaf_core/src/test/java/at/gv/egiz/eaaf/core/impl/idp/auth/IdentityLinkTest.java new file mode 100644 index 00000000..db97f4ca --- /dev/null +++ b/eaaf_core/src/test/java/at/gv/egiz/eaaf/core/impl/idp/auth/IdentityLinkTest.java @@ -0,0 +1,101 @@ +package at.gv.egiz.eaaf.core.impl.idp.auth; + +import java.io.ByteArrayInputStream; +import java.io.UnsupportedEncodingException; +import java.math.BigInteger; +import java.security.PublicKey; +import java.security.interfaces.RSAPublicKey; + +import org.apache.commons.lang3.RandomStringUtils; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.BlockJUnit4ClassRunner; +import org.springframework.util.Base64Utils; + +import at.gv.egiz.eaaf.core.exceptions.EaafParserException; +import at.gv.egiz.eaaf.core.impl.idp.auth.data.IdentityLink; +import at.gv.egiz.eaaf.core.impl.idp.auth.data.SimpleIdentityLinkAssertionParser; + +@RunWith(BlockJUnit4ClassRunner.class) +public class IdentityLinkTest { + + private IdentityLink idl = null; + + /** + * jUnit test set-up. + * @throws EaafParserException In case of an error + * @throws UnsupportedEncodingException In case of an unsupported encoding + */ + @Before + public void testInit() throws EaafParserException, UnsupportedEncodingException { + idl = (IdentityLink) new SimpleIdentityLinkAssertionParser( + new ByteArrayInputStream(Base64Utils.decode(AuthenticationDataBuilderTest.DUMMY_IDL_2.getBytes("UTF-8")))).parseIdentityLink(); + + } + + @Test + public void checkElement() { + Assert.assertNotNull("DateOfBirth", idl.getDateOfBirth()); + Assert.assertNotNull("FamilyName", idl.getFamilyName()); + Assert.assertNotNull("GivenNamae", idl.getGivenName()); + Assert.assertNotNull("baseIdType", idl.getIdentificationType()); + Assert.assertNotNull("baseid", idl.getIdentificationValue()); + Assert.assertNotNull("IssuerInstant", idl.getIssueInstant()); + Assert.assertNotNull("name", idl.getName()); + Assert.assertNotNull("prPerson", idl.getPrPerson()); + Assert.assertNotNull("Assertion element", idl.getSamlAssertion()); + Assert.assertNotNull("Assertion serialized", idl.getSerializedSamlAssertion()); + Assert.assertNotNull("Transform ref", idl.getDsigReferenceTransforms()); + Assert.assertEquals("Transform Size not match", 1, idl.getDsigReferenceTransforms().length); + + } + + @Test + public void checkPubKeys() { + PublicKey[] publicKey = new RSAPublicKey[2]; + publicKey[0] = generatePubKey(); + publicKey[1] = generatePubKey(); + + idl.setPublicKey(publicKey ); + + Assert.assertNotNull("PubKey", idl.getPublicKey()); + Assert.assertEquals("PubKeys not match", publicKey.length, idl.getPublicKey().length); + + } + + private PublicKey generatePubKey() { + return new RSAPublicKey() { + private static final long serialVersionUID = 1L; + + @Override + public BigInteger getModulus() { + return new BigInteger(RandomStringUtils.randomNumeric(10)); + } + + @Override + public String getFormat() { + // TODO Auto-generated method stub + return null; + } + + @Override + public byte[] getEncoded() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getAlgorithm() { + // TODO Auto-generated method stub + return null; + } + + @Override + public BigInteger getPublicExponent() { + return new BigInteger(RandomStringUtils.randomNumeric(2)); + } + }; + } +} -- cgit v1.2.3