Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(rest connector): add skip decoding field for rest outbound connector #3840

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion connectors/gitlab/element-templates/gitlab-connector.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "https://unpkg.com/@camunda/zeebe-element-templates-json-schema/resources/schema.json",
"name": "GitLab Outbound Connector",
"id": "io.camunda.connectors.GitLab.v1",
"version": 5,
"version": 6,
"description": "Manage GitLab issues, branches, releases, and more",
"metadata": {
"keywords": [
Expand Down Expand Up @@ -654,6 +654,19 @@
]
}
},
{
"id": "skipEncoding",
"label": "Skip URL encoding",
"description": "Skip the default URL decoding and encoding behavior",
"optional": true,
"group": "endpoint",
"binding": {
"name": "skipEncoding",
"type": "zeebe:input"
},
"value": "true",
"type": "Hidden"
},
{
"label": "Issue ID",
"description": "The internal ID of a project’s issue",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ public class ApacheRequestUriBuilder implements ApacheRequestPartBuilder {

@Override
public void build(ClassicRequestBuilder builder, HttpCommonRequest request) {
builder.setUri(UrlEncoder.toEncodedUri(request.getUrl()));
builder.setUri(UrlEncoder.toEncodedUri(request.getUrl(), request.getSkipEncoding()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@
public class UrlEncoder {
private static final Logger LOG = LoggerFactory.getLogger(ApacheRequestUriBuilder.class);

public static URI toEncodedUri(String requestUrl) {
public static URI toEncodedUri(String requestUrl, Boolean skipEncoding) {
try {
// We try to decode the URL first, because it might be encoded already
// which would lead to double encoding. Decoding is safe here, because it does nothing if
// the URL is not encoded.
if (skipEncoding) {
ztefanie marked this conversation as resolved.
Show resolved Hide resolved
return URI.create(requestUrl);
}
var decodedUrl = URLDecoder.decode(requestUrl, StandardCharsets.UTF_8);
var url = new URL(decodedUrl);
// Only this URI constructor escapes the URL properly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,15 @@ public class HttpCommonRequest {
description = "Store the response as a document in the document store")
private boolean storeResponse;

@TemplateProperty(
ztefanie marked this conversation as resolved.
Show resolved Hide resolved
label = "Skip URL encoding",
description = "Skip the default URL decoding and encoding behavior",
type = TemplateProperty.PropertyType.Hidden,
feel = Property.FeelMode.disabled,
group = "endpoint",
optional = true)
private String skipEncoding;
ztefanie marked this conversation as resolved.
Show resolved Hide resolved

public Object getBody() {
return body;
}
Expand Down Expand Up @@ -139,6 +148,14 @@ public void setQueryParameters(Map<String, String> queryParameters) {
this.queryParameters = queryParameters;
}

public boolean getSkipEncoding() {
return Objects.equals(skipEncoding, "true");
ztefanie marked this conversation as resolved.
Show resolved Hide resolved
}

public void setSkipEncoding(final String skipEncoding) {
this.skipEncoding = skipEncoding;
}

public boolean hasAuthentication() {
return authentication != null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,23 @@ public void shouldReturn200_whenEscapedSpaceInPathAndQueryParametersInPath(
assertThat(result).isNotNull();
assertThat(result.status()).isEqualTo(200);
}

@ParameterizedTest
@EnumSource(HttpMethod.class)
public void shouldKeepOriginalEscaping_whenSkipEscapingIsSet(
github-advanced-security[bot] marked this conversation as resolved.
Fixed
Show resolved Hide resolved
HttpMethod method, WireMockRuntimeInfo wmRuntimeInfo) {
stubFor(any(urlEqualTo("/path%2Fwith%2Fencoding")).willReturn(ok()));
stubFor(any(urlEqualTo("/path/with/encoding")).willReturn(badRequest()));
HttpCommonRequest request = new HttpCommonRequest();
request.setMethod(method);
request.setUrl(wmRuntimeInfo.getHttpBaseUrl() + "/path%2Fwith%2Fencoding");
request.setSkipEncoding("true");

HttpCommonResult result = customApacheHttpClient.execute(request);
ztefanie marked this conversation as resolved.
Show resolved Hide resolved

assertThat(result).isNotNull();
assertThat(result.status()).isEqualTo(200);
}
}

@Nested
Expand Down
2 changes: 1 addition & 1 deletion connectors/http/rest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,6 @@ leading to the following result
| Connector Info | |
| --- | --- |
| Type | io.camunda:http-json:1 |
| Version | 9 |
| Version | 10 |
| Supported element types | |

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"keywords" : [ ]
},
"documentationRef" : "https://docs.camunda.io/docs/components/connectors/protocol/rest/",
"version" : 9,
"version" : 10,
"category" : {
"id" : "connectors",
"name" : "Connectors"
Expand Down Expand Up @@ -402,6 +402,17 @@
"type" : "zeebe:input"
},
"type" : "Boolean"
}, {
"id" : "skipEncoding",
"label" : "Skip URL encoding",
"description" : "Skip the default URL decoding and encoding behavior",
"optional" : true,
"group" : "endpoint",
"binding" : {
"name" : "skipEncoding",
"type" : "zeebe:input"
},
"type" : "Hidden"
}, {
"id" : "connectionTimeoutInSeconds",
"label" : "Connection timeout in seconds",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"keywords" : [ ]
},
"documentationRef" : "https://docs.camunda.io/docs/components/connectors/protocol/rest/",
"version" : 9,
"version" : 10,
"category" : {
"id" : "connectors",
"name" : "Connectors"
Expand Down Expand Up @@ -407,6 +407,17 @@
"type" : "zeebe:input"
},
"type" : "Boolean"
}, {
ztefanie marked this conversation as resolved.
Show resolved Hide resolved
"id" : "skipEncoding",
"label" : "Skip URL encoding",
"description" : "Skip the default URL decoding and encoding behavior",
"optional" : true,
"group" : "endpoint",
"binding" : {
"name" : "skipEncoding",
"type" : "zeebe:input"
},
"type" : "Hidden"
}, {
"id" : "connectionTimeoutInSeconds",
"label" : "Connection timeout in seconds",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"authentication",
"headers",
"queryParameters",
"skipEncoding",
"connectionTimeoutInSeconds",
"readTimeoutInSeconds",
"writeTimeoutInSeconds",
Expand All @@ -46,7 +47,7 @@
description = "Invoke REST API",
inputDataClass = HttpJsonRequest.class,
outputDataClass = HttpCommonResult.class,
version = 9,
version = 10,
propertyGroups = {
@PropertyGroup(id = "authentication", label = "Authentication"),
@PropertyGroup(id = "endpoint", label = "HTTP endpoint"),
Expand Down
Loading