diff --git a/ballerina/modules/soap12/tests/soap12_client_test.bal b/ballerina/modules/soap12/tests/soap12_client_test.bal index 414db04..ccb90ea 100644 --- a/ballerina/modules/soap12/tests/soap12_client_test.bal +++ b/ballerina/modules/soap12/tests/soap12_client_test.bal @@ -17,7 +17,13 @@ import soap.wssec; import ballerina/mime; import ballerina/test; +import ballerina/crypto; +const string KEY_ALIAS = "wss40"; +const string KEY_PASSWORD = "security"; +const string KEY_STORE_PATH = "modules/wssec/tests/resources/wss40.p12"; +const string X509_KEY_STORE_PATH = "modules/wssec/tests/resources/x509_certificate.p12"; +const string X509_KEY_STORE_PATH_2 = "modules/wssec/tests/resources/x509_certificate_2.p12"; const wssec:TransportBindingConfig TRANSPORT_BINDING = "TransportBinding"; const wssec:NoPolicy NO_POLICY = "NoPolicy"; @@ -193,3 +199,164 @@ function testSendReceiveError() returns error? { test:assertTrue(response is Error); test:assertEquals((response).message(), SOAP_RESPONSE_ERROR); } + + +@test:Config { + groups: ["soap12", "send_receive"] +} +function testSendReceiveWithTimestampTokenSecurity() returns error? { + Client soapClient = check new ("http://www.dneonline.com/calculator.asmx?WSDL", + { + inboundSecurity: [ + { + timeToLive: 600 + } + ] + } + ); + xml body = xml ` + + + 2 + 3 + + + `; + xml|mime:Entity[] response = check soapClient->sendReceive(body, "http://tempuri.org/Add"); + xml expected = xml `soap:MustUnderstandSystem.Web.Services.Protocols.SoapHeaderException: SOAP header Security was not understood. + at System.Web.Services.Protocols.SoapHeaderHandling.SetHeaderMembers(SoapHeaderCollection headers, Object target, SoapHeaderMapping[] mappings, SoapHeaderDirection direction, Boolean client) + at System.Web.Services.Protocols.SoapServerProtocol.CreateServerInstance() + at System.Web.Services.Protocols.WebServiceHandler.Invoke() + at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()`; + + test:assertEquals(response.toString(), expected.toString()); +} + +@test:Config { + groups: ["soap12", "send_receive"] +} +function testSendReceiveWithUsernameTokenSecurity() returns error? { + Client soapClient = check new ("http://www.dneonline.com/calculator.asmx?WSDL", + { + inboundSecurity: { + username: "user", + password: "password", + passwordType: wssec:TEXT + }, + outboundSecurity: {} + } + ); + xml body = xml ` + + + 2 + 3 + + + `; + xml|mime:Entity[] response = check soapClient->sendReceive(body, "http://tempuri.org/Add"); + xml expected = xml `soap:MustUnderstandSystem.Web.Services.Protocols.SoapHeaderException: SOAP header Security was not understood. + at System.Web.Services.Protocols.SoapHeaderHandling.SetHeaderMembers(SoapHeaderCollection headers, Object target, SoapHeaderMapping[] mappings, SoapHeaderDirection direction, Boolean client) + at System.Web.Services.Protocols.SoapServerProtocol.CreateServerInstance() + at System.Web.Services.Protocols.WebServiceHandler.Invoke() + at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()`; + + test:assertEquals(response.toString(), expected.toString()); +} + +@test:Config { + groups: ["soap12", "send_receive"] +} +function testSendReceiveWithAsymmetricBindingSecurity() returns error? { + crypto:KeyStore serverKeyStore = { + path: X509_KEY_STORE_PATH, + password: KEY_PASSWORD + }; + + crypto:PublicKey serverPublicKey = check crypto:decodeRsaPublicKeyFromTrustStore(serverKeyStore, KEY_ALIAS); + + crypto:KeyStore clientKeyStore = { + path: X509_KEY_STORE_PATH_2, + password: KEY_PASSWORD + }; + crypto:PrivateKey clientPrivateKey = check crypto:decodeRsaPrivateKeyFromKeyStore(clientKeyStore, KEY_ALIAS, KEY_PASSWORD); + + Client soapClient = check new ("http://www.dneonline.com/calculator.asmx?WSDL", + { + inboundSecurity: { + signatureAlgorithm: wssec:RSA_SHA256, + encryptionAlgorithm: wssec:RSA_ECB, + signatureKey: clientPrivateKey, + encryptionKey: serverPublicKey + } + } + ); + xml body = xml ` + + + 2 + 3 + + + `; + xml|mime:Entity[] response = check soapClient->sendReceive(body, "http://tempuri.org/Add"); + xml expected = xml `soap:MustUnderstandSystem.Web.Services.Protocols.SoapHeaderException: SOAP header Security was not understood. + at System.Web.Services.Protocols.SoapHeaderHandling.SetHeaderMembers(SoapHeaderCollection headers, Object target, SoapHeaderMapping[] mappings, SoapHeaderDirection direction, Boolean client) + at System.Web.Services.Protocols.SoapServerProtocol.CreateServerInstance() + at System.Web.Services.Protocols.WebServiceHandler.Invoke() + at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()`; + + test:assertEquals(response.toString(), expected.toString()); +} + +@test:Config { + groups: ["soap12", "send_receive"] +} +function testSendReceiveWithSymmetricBindingSecurity() returns error? { + crypto:KeyStore serverKeyStore = { + path: X509_KEY_STORE_PATH, + password: KEY_PASSWORD + }; + crypto:PublicKey serverPublicKey = check crypto:decodeRsaPublicKeyFromTrustStore(serverKeyStore, KEY_ALIAS); + + crypto:KeyStore keyStore = { + path: KEY_STORE_PATH, + password: KEY_PASSWORD + }; + crypto:PrivateKey symmetricKey = check crypto:decodeRsaPrivateKeyFromKeyStore(keyStore, KEY_ALIAS, KEY_PASSWORD); + + Client soapClient = check new ("http://www.dneonline.com/calculator.asmx?WSDL", + { + inboundSecurity: { + signatureAlgorithm: wssec:RSA_SHA256, + encryptionAlgorithm: wssec:RSA_ECB, + symmetricKey: symmetricKey, + servicePublicKey: serverPublicKey + } + } + ); + xml body = xml ` + + + 2 + 3 + + + `; + xml|mime:Entity[] response = check soapClient->sendReceive(body, "http://tempuri.org/Add"); + xml expected = xml `soap:MustUnderstandSystem.Web.Services.Protocols.SoapHeaderException: SOAP header Security was not understood. + at System.Web.Services.Protocols.SoapHeaderHandling.SetHeaderMembers(SoapHeaderCollection headers, Object target, SoapHeaderMapping[] mappings, SoapHeaderDirection direction, Boolean client) + at System.Web.Services.Protocols.SoapServerProtocol.CreateServerInstance() + at System.Web.Services.Protocols.WebServiceHandler.Invoke() + at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()`; + + test:assertEquals(response.toString(), expected.toString()); +}