Skip to content

Commit

Permalink
Merge pull request #127 from ballerina-platform/intermittent-fix
Browse files Browse the repository at this point in the history
Fix intermittent errors in test cases
  • Loading branch information
Nuvindu authored Apr 26, 2024
2 parents 34d8e5f + 242c675 commit a33336a
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 32 deletions.
28 changes: 28 additions & 0 deletions ballerina/modules/soap11/tests/http_secured_service.bal
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com).
//
// WSO2 LLC. licenses this file to you under the Apache License,
// Version 2.0 (the "License"); you may not use this file except
// in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

import ballerina/http;

service / on new http:Listener(9091) {

resource function post .() returns xml|error {
return xml `<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><soap:Fault><faultcode>soap:MustUnderstand</faultcode><faultstring>System.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()</faultstring></soap:Fault></soap:Body></soap:Envelope>`;
}
}
4 changes: 4 additions & 0 deletions ballerina/modules/soap11/tests/http_soap_service.bal
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ crypto:PublicKey serverPublicKey = check crypto:decodeRsaPublicKeyFromTrustStore

service / on new http:Listener(9090) {

resource function post .() returns xml|error {
return xml `<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><AddResponse xmlns="http://tempuri.org/"><AddResult>5</AddResult></AddResponse></soap:Body></soap:Envelope>`;
}

resource function post getPayload(http:Request request) returns http:Response|error {
http:Response response = new;
response.setPayload(check (check request.getBodyParts())[0].getXml());
Expand Down
23 changes: 11 additions & 12 deletions ballerina/modules/soap11/tests/soap11_client_test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ function testSendOnly() returns error? {
</soap:Body>
</soap:Envelope>`;

Client soapClient = check new ("http://www.dneonline.com/calculator.asmx?WSDL");
Client soapClient = check new ("http://localhost:9090");
check soapClient->sendOnly(body, "http://tempuri.org/Add");
}

Expand All @@ -206,8 +206,8 @@ function testSendOnlyError() returns error? {
@test:Config {
groups: ["soap11", "send_receive"]
}
function testsendReceive() returns error? {
Client soapClient = check new ("http://www.dneonline.com/calculator.asmx?WSDL",
function testSendReceive() returns error? {
Client soapClient = check new ("http://localhost:9090",
{
inboundSecurity: NO_POLICY,
outboundSecurity: {}
Expand Down Expand Up @@ -244,10 +244,9 @@ function testSendReceiveWithHeaders() returns error? {
</soap:Body>
</soap:Envelope>`;

Client soapClient = check new ("http://www.dneonline.com/calculator.asmx?WSDL");
Client soapClient = check new ("http://localhost:9090");

xml response = check soapClient->sendReceive(body, "http://tempuri.org/Add",
{foo: ["bar1", "bar2"]});
xml response = check soapClient->sendReceive(body, "http://tempuri.org/Add", {foo: ["bar1", "bar2"]});
xml expected = xml `<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><AddResponse xmlns="http://tempuri.org/"><AddResult>5</AddResult></AddResponse></soap:Body></soap:Envelope>`;
test:assertEquals(response, expected);
}
Expand All @@ -256,7 +255,7 @@ function testSendReceiveWithHeaders() returns error? {
groups: ["soap11"]
}
function testTransportBindingError() returns error? {
Client|Error soapClient = new ("http://www.dneonline.com/calculator.asmx?WSDL",
Client|Error soapClient = new ("http://localhost:9090",
inboundSecurity = TRANSPORT_BINDING
);
test:assertTrue(soapClient is Error);
Expand All @@ -267,7 +266,7 @@ function testTransportBindingError() returns error? {
groups: ["soap11"]
}
function testTransportBindingError2() returns error? {
Client|Error soapClient = new ("http://www.dneonline.com/calculator.asmx?WSDL",
Client|Error soapClient = new ("http://localhost:9090",
inboundSecurity = [
TRANSPORT_BINDING
]
Expand Down Expand Up @@ -300,7 +299,7 @@ function testSendReceiveError() returns error? {
groups: ["soap11", "send_receive"]
}
function testSendReceiveWithTimestampTokenSecurity() returns error? {
Client soapClient = check new ("http://www.dneonline.com/calculator.asmx?WSDL",
Client soapClient = check new ("http://localhost:9091",
{
inboundSecurity: [
{
Expand Down Expand Up @@ -332,7 +331,7 @@ function testSendReceiveWithTimestampTokenSecurity() returns error? {
groups: ["soap11", "send_receive"]
}
function testSendReceiveWithUsernameTokenSecurity() returns error? {
Client soapClient = check new ("http://www.dneonline.com/calculator.asmx?WSDL",
Client soapClient = check new ("http://localhost:9091",
{
inboundSecurity: {
username: "user",
Expand Down Expand Up @@ -378,7 +377,7 @@ function testSendReceiveWithAsymmetricBindingSecurity() returns error? {
};
crypto:PrivateKey clientPrivateKey = check crypto:decodeRsaPrivateKeyFromKeyStore(clientKeyStore, KEY_ALIAS, KEY_PASSWORD);

Client soapClient = check new ("http://www.dneonline.com/calculator.asmx?WSDL",
Client soapClient = check new ("http://localhost:9091",
{
inboundSecurity: {
signatureAlgorithm: soap:RSA_SHA256,
Expand Down Expand Up @@ -424,7 +423,7 @@ function testSendReceiveWithSymmetricBindingSecurity() returns error? {
};
crypto:PrivateKey symmetricKey = check crypto:decodeRsaPrivateKeyFromKeyStore(keyStore, KEY_ALIAS, KEY_PASSWORD);

Client soapClient = check new ("http://www.dneonline.com/calculator.asmx?WSDL",
Client soapClient = check new ("http://localhost:9091",
{
inboundSecurity: {
signatureAlgorithm: soap:RSA_SHA256,
Expand Down
29 changes: 29 additions & 0 deletions ballerina/modules/soap12/tests/http_secured_service.bal
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com)
//
// WSO2 LLC. licenses this file to you under the Apache License,
// Version 2.0 (the "License"); you may not use this file except
// in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

import ballerina/http;

service / on new http:Listener(9091) {

resource function post .() returns xml|error {
return xml `<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><soap:Fault><soap:Code><soap:Value>soap:Sender</soap:Value></soap:Code><soap:Reason><soap:Text xml:lang="en">System.Web.Services.Protocols.SoapException: Unable to handle request without a valid action parameter. Please supply a valid soap action.
at System.Web.Services.Protocols.Soap12ServerProtocolHelper.RouteRequest()
at System.Web.Services.Protocols.SoapServerProtocol.RouteRequest(SoapServerMessage message)
at System.Web.Services.Protocols.SoapServerProtocol.Initialize()
at System.Web.Services.Protocols.ServerProtocol.SetContext(Type type, HttpContext context, HttpRequest request, HttpResponse response)
at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean&amp; abortProcessing)</soap:Text></soap:Reason><soap:Detail/></soap:Fault></soap:Body></soap:Envelope>`;
}
}
4 changes: 4 additions & 0 deletions ballerina/modules/soap12/tests/http_soap_service.bal
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ crypto:PublicKey serverPublicKey = check crypto:decodeRsaPublicKeyFromTrustStore

service / on new http:Listener(9090) {

resource function post .() returns xml|error {
return xml `<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><AddResponse xmlns="http://tempuri.org/"><AddResult>5</AddResult></AddResponse></soap:Body></soap:Envelope>`;
}

resource function post getPayload(http:Request request) returns http:Response|error {
http:Response response = new;
response.setPayload(check (check request.getBodyParts())[0].getXml());
Expand Down
42 changes: 22 additions & 20 deletions ballerina/modules/soap12/tests/soap12_client_test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function testSendOnly12() returns error? {
</soap:Body>
</soap:Envelope>`;

Client soapClient = check new ("http://www.dneonline.com/calculator.asmx?WSDL");
Client soapClient = check new ("http://localhost:9090");

check soapClient->sendOnly(body, "http://tempuri.org/Add");
}
Expand Down Expand Up @@ -103,7 +103,7 @@ function testSendReceive12WithAction() returns error? {
groups: ["soap12", "send_receive"]
}
function testSendReceive12() returns error? {
Client soapClient = check new ("http://www.dneonline.com/calculator.asmx?WSDL");
Client soapClient = check new ("http://localhost:9090");
xml body = xml `<soap:Envelope
xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding">
Expand Down Expand Up @@ -252,7 +252,7 @@ function testSendReceive12WithHeaders() returns error? {
</soap:Body>
</soap:Envelope>`;

Client soapClient = check new ("http://www.dneonline.com/calculator.asmx?WSDL");
Client soapClient = check new ("http://localhost:9090");

xml response = check soapClient->sendReceive(body, headers = {foo: ["bar1", "bar2"]});

Expand All @@ -275,7 +275,7 @@ function testSendOnly12WithoutSoapAction() returns error? {
</soap:Body>
</soap:Envelope>`;

Client soapClient = check new ("http://www.dneonline.com/calculator.asmx?WSDL");
Client soapClient = check new ("http://localhost:9090");

check soapClient->sendOnly(body);
}
Expand All @@ -284,7 +284,7 @@ function testSendOnly12WithoutSoapAction() returns error? {
groups: ["soap12"]
}
function testTransportBindingError() returns error? {
Client|Error soapClient = new ("http://www.dneonline.com/calculator.asmx?WSDL", inboundSecurity = TRANSPORT_BINDING);
Client|Error soapClient = new ("http://localhost:9091", inboundSecurity = TRANSPORT_BINDING);
test:assertTrue(soapClient is Error);
test:assertEquals((<Error>soapClient).message(), SOAP_CLIENT_ERROR);
}
Expand All @@ -293,7 +293,7 @@ function testTransportBindingError() returns error? {
groups: ["soap12"]
}
function testTransportBindingError2() returns error? {
Client|Error soapClient = new ("http://www.dneonline.com/calculator.asmx?WSDL",
Client|Error soapClient = new ("http://localhost:9091",
inboundSecurity = [
TRANSPORT_BINDING
]
Expand Down Expand Up @@ -326,7 +326,7 @@ function testSendReceiveError() returns error? {
groups: ["soap12", "send_receive"]
}
function testSendReceiveWithTimestampTokenSecurity() returns error? {
Client soapClient = check new ("http://www.dneonline.com/calculator.asmx?WSDL",
Client soapClient = check new ("http://localhost:9091",
{
inboundSecurity: [
{
Expand All @@ -346,11 +346,12 @@ function testSendReceiveWithTimestampTokenSecurity() returns error? {
</soap:Body>
</soap:Envelope>`;
xml response = check soapClient->sendReceive(body);
xml expected = xml `<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><soap:Fault><soap:Code><soap:Value>soap:MustUnderstand</soap:Value></soap:Code><soap:Reason><soap:Text xml:lang="en">System.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()</soap:Text></soap:Reason></soap:Fault></soap:Body></soap:Envelope>`;
xml expected = xml `<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><soap:Fault><soap:Code><soap:Value>soap:Sender</soap:Value></soap:Code><soap:Reason><soap:Text xml:lang="en">System.Web.Services.Protocols.SoapException: Unable to handle request without a valid action parameter. Please supply a valid soap action.
at System.Web.Services.Protocols.Soap12ServerProtocolHelper.RouteRequest()
at System.Web.Services.Protocols.SoapServerProtocol.RouteRequest(SoapServerMessage message)
at System.Web.Services.Protocols.SoapServerProtocol.Initialize()
at System.Web.Services.Protocols.ServerProtocol.SetContext(Type type, HttpContext context, HttpRequest request, HttpResponse response)
at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean&amp; abortProcessing)</soap:Text></soap:Reason><soap:Detail/></soap:Fault></soap:Body></soap:Envelope>`;

test:assertEquals(response.toString(), expected.toString());
}
Expand All @@ -359,7 +360,7 @@ function testSendReceiveWithTimestampTokenSecurity() returns error? {
groups: ["soap12", "send_receive"]
}
function testSendReceiveWithUsernameTokenSecurity() returns error? {
Client soapClient = check new ("http://www.dneonline.com/calculator.asmx?WSDL",
Client soapClient = check new ("http://localhost:9091",
{
inboundSecurity: {
username: "user",
Expand All @@ -380,11 +381,12 @@ function testSendReceiveWithUsernameTokenSecurity() returns error? {
</soap:Body>
</soap:Envelope>`;
xml response = check soapClient->sendReceive(body);
xml expected = xml `<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><soap:Fault><soap:Code><soap:Value>soap:MustUnderstand</soap:Value></soap:Code><soap:Reason><soap:Text xml:lang="en">System.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()</soap:Text></soap:Reason></soap:Fault></soap:Body></soap:Envelope>`;
xml expected = xml `<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><soap:Fault><soap:Code><soap:Value>soap:Sender</soap:Value></soap:Code><soap:Reason><soap:Text xml:lang="en">System.Web.Services.Protocols.SoapException: Unable to handle request without a valid action parameter. Please supply a valid soap action.
at System.Web.Services.Protocols.Soap12ServerProtocolHelper.RouteRequest()
at System.Web.Services.Protocols.SoapServerProtocol.RouteRequest(SoapServerMessage message)
at System.Web.Services.Protocols.SoapServerProtocol.Initialize()
at System.Web.Services.Protocols.ServerProtocol.SetContext(Type type, HttpContext context, HttpRequest request, HttpResponse response)
at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean&amp; abortProcessing)</soap:Text></soap:Reason><soap:Detail/></soap:Fault></soap:Body></soap:Envelope>`;

test:assertEquals(response.toString(), expected.toString());
}
Expand All @@ -406,7 +408,7 @@ function testSendReceiveWithAsymmetricBindingSecurity() returns error? {
};
crypto:PrivateKey clientPrivateKey = check crypto:decodeRsaPrivateKeyFromKeyStore(clientKeyStore, KEY_ALIAS, KEY_PASSWORD);

Client soapClient = check new ("http://www.dneonline.com/calculator.asmx?WSDL",
Client soapClient = check new ("http://localhost:9091",
{
inboundSecurity: {
signatureAlgorithm: soap:RSA_SHA256,
Expand Down Expand Up @@ -453,7 +455,7 @@ function testSendReceiveWithSymmetricBindingSecurity() returns error? {
};
crypto:PrivateKey symmetricKey = check crypto:decodeRsaPrivateKeyFromKeyStore(keyStore, KEY_ALIAS, KEY_PASSWORD);

Client soapClient = check new ("http://www.dneonline.com/calculator.asmx?WSDL",
Client soapClient = check new ("http://localhost:9091",
{
inboundSecurity: {
signatureAlgorithm: soap:RSA_SHA256,
Expand Down

0 comments on commit a33336a

Please sign in to comment.