diff options
Diffstat (limited to 'bindings/java/tests')
| -rw-r--r-- | bindings/java/tests/BindingTests.java | 113 | ||||
| -rw-r--r-- | bindings/java/tests/LoginTest.java | 61 |
2 files changed, 75 insertions, 99 deletions
diff --git a/bindings/java/tests/BindingTests.java b/bindings/java/tests/BindingTests.java index 53a508df..10b08f2b 100644 --- a/bindings/java/tests/BindingTests.java +++ b/bindings/java/tests/BindingTests.java @@ -42,22 +42,9 @@ import java.util.*; public class BindingTests extends TestCase { - String[] toStringArray(Object[] array) { - String[] str = new String[array.length]; - int i; - for (i=0;i<array.length;i++) - str[i] = (String)array[i]; - return str; - } - SamlAssertion[] toSamlAssertionArray(Object[] array) { - SamlAssertion[] str = new SamlAssertion[array.length]; - int i; - for (i=0;i<array.length;i++) - str[i] = (SamlAssertion)array[i]; - return str; - } public static void main(String args[]) { junit.textui.TestRunner.run(suite()); + System.gc(); } public static Test suite() { @@ -120,27 +107,33 @@ public class BindingTests extends TestCase { assertEquals(respondWith.get(0), "first string"); assertEquals(respondWith.get(1), "second string"); assertEquals(respondWith.get(2), "third string"); - authnRequest.setRespondWith(toStringArray(respondWith.toArray())); - assertEquals(authnRequest.getRespondWith()[0], "first string"); - assertEquals(authnRequest.getRespondWith()[1], "second string"); - assertEquals(authnRequest.getRespondWith()[2], "third string"); + authnRequest.setRespondWith(respondWith); + assertEquals(authnRequest.getRespondWith().get(0), "first string"); + assertEquals(authnRequest.getRespondWith().get(1), "second string"); + assertEquals(authnRequest.getRespondWith().get(2), "third string"); assertEquals(respondWith.get(0), "first string"); assertEquals(respondWith.get(1), "second string"); assertEquals(respondWith.get(2), "third string"); respondWith = null; - assertEquals(authnRequest.getRespondWith()[0], "first string"); - assertEquals(authnRequest.getRespondWith()[1], "second string"); - assertEquals(authnRequest.getRespondWith()[2], "third string"); - respondWith = Arrays.asList(authnRequest.getRespondWith()); + assertEquals(authnRequest.getRespondWith().get(0), "first string"); + assertEquals(authnRequest.getRespondWith().get(1), "second string"); + assertEquals(authnRequest.getRespondWith().get(2), "third string"); + respondWith = authnRequest.getRespondWith(); assertEquals(respondWith.get(0), "first string"); assertEquals(respondWith.get(1), "second string"); assertEquals(respondWith.get(2), "third string"); respondWith = null; - assertEquals(authnRequest.getRespondWith()[0], "first string"); - assertEquals(authnRequest.getRespondWith()[1], "second string"); - assertEquals(authnRequest.getRespondWith()[2], "third string"); + assertEquals(authnRequest.getRespondWith().get(0), "first string"); + assertEquals(authnRequest.getRespondWith().get(1), "second string"); + assertEquals(authnRequest.getRespondWith().get(2), "third string"); + authnRequest.removeFromRespondWith("second string"); + assertEquals(authnRequest.getRespondWith().get(0), "first string"); + assertEquals(authnRequest.getRespondWith().get(1), "third string"); + authnRequest.addToRespondWith("second string"); + assertEquals(authnRequest.getRespondWith().get(0), "first string"); + assertEquals(authnRequest.getRespondWith().get(1), "third string"); + assertEquals(authnRequest.getRespondWith().get(2), "second string"); authnRequest.setRespondWith(null); - System.out.println("coin"+authnRequest.getRespondWith()); assertNull(authnRequest.getRespondWith()); authnRequest = null; @@ -174,34 +167,25 @@ public class BindingTests extends TestCase { assertEquals(((SamlAssertion) assertions.get(0)).getAssertionId(), "assertion 1"); assertEquals(((SamlAssertion) assertions.get(1)).getAssertionId(), "assertion 2"); assertEquals(((SamlAssertion) assertions.get(2)).getAssertionId(), "assertion 3"); - response.setAssertion(toSamlAssertionArray(assertions.toArray())); - assertEquals(((SamlAssertion) response.getAssertion()[0]).getAssertionId(), - "assertion 1"); - assertEquals(((SamlAssertion) response.getAssertion()[1]).getAssertionId(), - "assertion 2"); - assertEquals(((SamlAssertion) response.getAssertion()[2]).getAssertionId(), - "assertion 3"); + response.setAssertion(assertions); + assertEquals(((SamlAssertion) response.getAssertion().get(0)).getAssertionId(), "assertion 1"); + assertEquals(((SamlAssertion) response.getAssertion().get(1)).getAssertionId(), "assertion 2"); + assertEquals(((SamlAssertion) response.getAssertion().get(2)).getAssertionId(), "assertion 3"); assertEquals(((SamlAssertion) assertions.get(0)).getAssertionId(), "assertion 1"); assertEquals(((SamlAssertion) assertions.get(1)).getAssertionId(), "assertion 2"); assertEquals(((SamlAssertion) assertions.get(2)).getAssertionId(), "assertion 3"); assertions = null;; - assertEquals(((SamlAssertion) response.getAssertion()[0]).getAssertionId(), - "assertion 1"); - assertEquals(((SamlAssertion) response.getAssertion()[1]).getAssertionId(), - "assertion 2"); - assertEquals(((SamlAssertion) response.getAssertion()[2]).getAssertionId(), - "assertion 3"); - assertions = Arrays.asList(response.getAssertion()); + assertEquals(((SamlAssertion) response.getAssertion().get(0)).getAssertionId(), "assertion 1"); + assertEquals(((SamlAssertion) response.getAssertion().get(1)).getAssertionId(), "assertion 2"); + assertEquals(((SamlAssertion) response.getAssertion().get(2)).getAssertionId(), "assertion 3"); + assertions = response.getAssertion(); assertEquals(((SamlAssertion) assertions.get(0)).getAssertionId(), "assertion 1"); assertEquals(((SamlAssertion) assertions.get(1)).getAssertionId(), "assertion 2"); assertEquals(((SamlAssertion) assertions.get(2)).getAssertionId(), "assertion 3"); assertions = null; - assertEquals(((SamlAssertion) response.getAssertion()[0]).getAssertionId(), - "assertion 1"); - assertEquals(((SamlAssertion) response.getAssertion()[1]).getAssertionId(), - "assertion 2"); - assertEquals(((SamlAssertion) response.getAssertion()[2]).getAssertionId(), - "assertion 3"); + assertEquals(((SamlAssertion) response.getAssertion().get(0)).getAssertionId(), "assertion 1"); + assertEquals(((SamlAssertion) response.getAssertion().get(1)).getAssertionId(), "assertion 2"); + assertEquals(((SamlAssertion) response.getAssertion().get(2)).getAssertionId(), "assertion 3"); response.setAssertion(null); assertNull(response.getAssertion()); @@ -215,15 +199,9 @@ public class BindingTests extends TestCase { assertNull(authnRequest.getExtension()); - String actionString1 = "<lib:Extension xmlns:lib=\"urn:liberty:iff:2003-08\">\n" - + " <action>do 1</action>\n" - + "</lib:Extension>"; - String actionString2 = "<lib:Extension xmlns:lib=\"urn:liberty:iff:2003-08\">\n" - + " <action>do 2</action>\n" - + "</lib:Extension>"; - String actionString3 = "<lib:Extension xmlns:lib=\"urn:liberty:iff:2003-08\">\n" - + " <action>do 3</action>\n" - + "</lib:Extension>"; + String actionString1 = "<lib:Extension xmlns:lib=\"urn:liberty:iff:2003-08\">\n" + " <action>do 1</action>\n" + "</lib:Extension>"; + String actionString2 = "<lib:Extension xmlns:lib=\"urn:liberty:iff:2003-08\">\n" + " <action>do 2</action>\n" + "</lib:Extension>"; + String actionString3 = "<lib:Extension xmlns:lib=\"urn:liberty:iff:2003-08\">\n" + " <action>do 3</action>\n" + "</lib:Extension>"; List extension = new ArrayList(); assertEquals(extension.size(), 0); extension.add(actionString1); @@ -239,25 +217,25 @@ public class BindingTests extends TestCase { assertEquals(extension.get(0), actionString1); assertEquals(extension.get(1), actionString2); assertEquals(extension.get(2), actionString3); - authnRequest.setExtension(toStringArray(extension.toArray())); - assertEquals(authnRequest.getExtension()[0], actionString1); - assertEquals(authnRequest.getExtension()[1], actionString2); - assertEquals(authnRequest.getExtension()[2], actionString3); + authnRequest.setExtension(extension); + assertEquals(authnRequest.getExtension().get(0), actionString1); + assertEquals(authnRequest.getExtension().get(1), actionString2); + assertEquals(authnRequest.getExtension().get(2), actionString3); assertEquals(extension.get(0), actionString1); assertEquals(extension.get(1), actionString2); assertEquals(extension.get(2), actionString3); extension = null; - assertEquals(authnRequest.getExtension()[0], actionString1); - assertEquals(authnRequest.getExtension()[1], actionString2); - assertEquals(authnRequest.getExtension()[2], actionString3); - extension = Arrays.asList(authnRequest.getExtension()); + assertEquals(authnRequest.getExtension().get(0), actionString1); + assertEquals(authnRequest.getExtension().get(1), actionString2); + assertEquals(authnRequest.getExtension().get(2), actionString3); + extension = authnRequest.getExtension(); assertEquals(extension.get(0), actionString1); assertEquals(extension.get(1), actionString2); assertEquals(extension.get(2), actionString3); extension = null; - assertEquals(authnRequest.getExtension()[0], actionString1); - assertEquals(authnRequest.getExtension()[1], actionString2); - assertEquals(authnRequest.getExtension()[2], actionString3); + assertEquals(authnRequest.getExtension().get(0), actionString1); + assertEquals(authnRequest.getExtension().get(1), actionString2); + assertEquals(authnRequest.getExtension().get(2), actionString3); authnRequest.setExtension(null); assertNull(authnRequest.getExtension()); @@ -272,8 +250,7 @@ public class BindingTests extends TestCase { assertNull(login.getRequest()); login.setRequest((SamlpRequestAbstract) new LibAuthnRequest()); ((LibAuthnRequest) login.getRequest()).setConsent(LassoConstants.LASSO_LIB_CONSENT_OBTAINED); - assertEquals(((LibAuthnRequest) login.getRequest()).getConsent(), - LassoConstants.LASSO_LIB_CONSENT_OBTAINED); + assertEquals(((LibAuthnRequest) login.getRequest()).getConsent(), LassoConstants.LASSO_LIB_CONSENT_OBTAINED); login.setRequest(null); assertNull(login.getRequest()); diff --git a/bindings/java/tests/LoginTest.java b/bindings/java/tests/LoginTest.java index 755ffd7b..d3d29d49 100644 --- a/bindings/java/tests/LoginTest.java +++ b/bindings/java/tests/LoginTest.java @@ -42,30 +42,30 @@ import com.entrouvert.lasso.*; public class LoginTest extends TestCase { public String generateIdentityProviderDump() { Server server = new Server( - "../../tests/data/idp1-la/metadata.xml", - "../../tests/data/idp1-la/private-key-raw.pem", + "../../../tests/data/idp1-la/metadata.xml", + "../../../tests/data/idp1-la/private-key-raw.pem", null, - "../../tests/data/idp1-la/certificate.pem"); + "../../../tests/data/idp1-la/certificate.pem"); server.addProvider( - lasso.PROVIDER_ROLE_SP, - "../../tests/data/sp1-la/metadata.xml", - "../../tests/data/sp1-la/public-key.pem", - "../../tests/data/ca1-la/certificate.pem"); + LassoConstants.LASSO_PROVIDER_ROLE_SP, + "../../../tests/data/sp1-la/metadata.xml", + "../../../tests/data/sp1-la/public-key.pem", + "../../../tests/data/ca1-la/certificate.pem"); String serverDump = server.dump(); return serverDump; } public String generateServiceProviderDump() { Server server = new Server( - "../../tests/data/sp1-la/metadata.xml", - "../../tests/data/sp1-la/private-key-raw.pem", + "../../../tests/data/sp1-la/metadata.xml", + "../../../tests/data/sp1-la/private-key-raw.pem", null, - "../../tests/data/sp1-la/certificate.pem"); + "../../../tests/data/sp1-la/certificate.pem"); server.addProvider( - lasso.PROVIDER_ROLE_IDP, - "../../tests/data/idp1-la/metadata.xml", - "../../tests/data/idp1-la/public-key.pem", - "../../tests/data/ca1-la/certificate.pem"); + LassoConstants.LASSO_PROVIDER_ROLE_IDP, + "../../../tests/data/idp1-la/metadata.xml", + "../../../tests/data/idp1-la/public-key.pem", + "../../../tests/data/ca1-la/certificate.pem"); String serverDump = server.dump(); return serverDump; } @@ -97,11 +97,11 @@ public class LoginTest extends TestCase { assertNotNull(spDump); sp = Server.newFromDump(spDump); spLogin = new Login(sp); - spLogin.initAuthnRequest("https://idp1/metadata", lasso.HTTP_METHOD_REDIRECT); + spLogin.initAuthnRequest("https://idp1/metadata", LassoConstants.LASSO_HTTP_METHOD_REDIRECT); authnRequest = (LibAuthnRequest) spLogin.getRequest(); authnRequest.setIsPassive(false); - authnRequest.setNameIdPolicy(lasso.LIB_NAMEID_POLICY_TYPE_FEDERATED); - authnRequest.setConsent(lasso.LIB_CONSENT_OBTAINED); + authnRequest.setNameIdPolicy(LassoConstants.LASSO_LIB_NAMEID_POLICY_TYPE_FEDERATED); + authnRequest.setConsent(LassoConstants.LASSO_LIB_CONSENT_OBTAINED); relayState = "fake"; authnRequest.setRelayState(relayState); spLogin.buildAuthnRequestMsg(); @@ -120,15 +120,15 @@ public class LoginTest extends TestCase { userAuthenticated = true; userConsentObtained = false; idpLogin.validateRequestMsg(userAuthenticated, userConsentObtained); - authenticationMethod = lasso.SAML_AUTHENTICATION_METHOD_PASSWORD; + authenticationMethod = LassoConstants.LASSO_SAML_AUTHENTICATION_METHOD_PASSWORD; idpLogin.buildAssertion( authenticationMethod, null, // authenticationInstant null, // reauthenticateOnOrAfter null, // notBefore null);// notOnOrAfter - assertEquals(lasso.LOGIN_PROTOCOL_PROFILE_BRWS_ART, idpLogin.getProtocolProfile()); - idpLogin.buildArtifactMsg(lasso.HTTP_METHOD_REDIRECT); + assertEquals(LassoConstants.LASSO_LOGIN_PROTOCOL_PROFILE_BRWS_ART, idpLogin.getProtocolProfile()); + idpLogin.buildArtifactMsg(LassoConstants.LASSO_HTTP_METHOD_REDIRECT); idpIdentityDump = idpLogin.getIdentity().dump(); assertNotNull(idpIdentityDump); idpSessionDump = idpLogin.getSession().dump(); @@ -139,12 +139,13 @@ public class LoginTest extends TestCase { nameIdentifier = ((SamlNameIdentifier)idpLogin.getNameIdentifier()).getContent(); artifact = idpLogin.getAssertionArtifact(); assertNotNull(artifact); - method = lasso.HTTP_METHOD_REDIRECT; + method = LassoConstants.LASSO_HTTP_METHOD_REDIRECT; // Service provider assertion consumer. spDump = generateServiceProviderDump(); assertNotNull(spDump); sp = Server.newFromDump(spDump); + soapEndpoint = spLogin.getMsgUrl(); spLogin = new Login(sp); spLogin.initRequest(responseQuery, method); spLogin.buildRequestMsg(); @@ -154,8 +155,8 @@ public class LoginTest extends TestCase { assertNotNull(soapRequestMsg); // Identity provider SOAP endpoint. - requestType = lasso.getRequestTypeFromSoapMsg(soapRequestMsg); - assertEquals(lasso.REQUEST_TYPE_LOGIN, requestType); + requestType = LassoJNI.getRequestTypeFromSoapMsg(soapRequestMsg); + assertEquals(LassoConstants.LASSO_REQUEST_TYPE_LOGIN, requestType); idpDump = generateIdentityProviderDump(); assertNotNull(idpDump); idp = Server.newFromDump(idpDump); @@ -181,9 +182,9 @@ public class LoginTest extends TestCase { assertNotNull(spSession); spSessionDump = spSession.dump(); assertNotNull(spSessionDump); - assertion = (SamlAssertion) spSession.getAssertions("https://idp1/metadata").getItem(0); + assertion = (SamlAssertion) spSession.getAssertions("https://idp1/metadata").get(0); authenticationMethod = assertion.getAuthenticationStatement().getAuthenticationMethod(); - assertEquals(lasso.SAML_AUTHENTICATION_METHOD_PASSWORD, authenticationMethod); + assertEquals(LassoConstants.LASSO_SAML_AUTHENTICATION_METHOD_PASSWORD, authenticationMethod); // Service provider logout. spDump = generateServiceProviderDump(); @@ -195,14 +196,14 @@ public class LoginTest extends TestCase { spLogout.setIdentityFromDump(spIdentityDump); assertNotNull(spSessionDump); spLogout.setSessionFromDump(spSessionDump); - spLogout.initRequest(null, lasso.HTTP_METHOD_ANY); + spLogout.initRequest(null, LassoConstants.LASSO_HTTP_METHOD_ANY); spLogout.buildRequestMsg(); soapEndpoint = spLogout.getMsgUrl(); soapRequestMsg = spLogout.getMsgBody(); // Identity provider SOAP endpoint. - requestType = lasso.getRequestTypeFromSoapMsg(soapRequestMsg); - assertEquals(lasso.REQUEST_TYPE_LOGOUT, requestType); + requestType = LassoJNI.getRequestTypeFromSoapMsg(soapRequestMsg); + assertEquals(LassoConstants.LASSO_REQUEST_TYPE_LOGOUT, requestType); idpDump = generateIdentityProviderDump(); assertNotNull(idpDump); idp = Server.newFromDump(idpDump); @@ -235,10 +236,8 @@ public class LoginTest extends TestCase { } public static void main(String args[]) { - System.out.println(System.mapLibraryName("jlasso")); - lasso.init(); junit.textui.TestRunner.run(suite()); - lasso.shutdown(); + System.gc(); } } |
