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 4535 - support file uploads with filenames containing single quote #4538

Merged
merged 1 commit into from
Nov 4, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#### Bugs
* Fix #4534: Java Generator CLI default handling of skipGeneratedAnnotations
* Fix #4535: The shell command string will now have single quotes sanitized
* Fix #4547: preventing timing issues with leader election cancel

#### Improvements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,26 +185,26 @@ public Loggable withLogWaitTimeout(Integer logWaitTimeout) {
public PortForward portForward(int port, ReadableByteChannel in, WritableByteChannel out) {
try {
return new PortForwarderWebsocket(httpClient, this.context.getExecutor()).forward(getResourceUrl(), port, in, out);
} catch (Throwable t) {
throw KubernetesClientException.launderThrowable(t);
} catch (Exception e) {
throw KubernetesClientException.launderThrowable(e);
}
}

@Override
public LocalPortForward portForward(int port) {
try {
return new PortForwarderWebsocket(httpClient, this.context.getExecutor()).forward(getResourceUrl(), port);
} catch (Throwable t) {
throw KubernetesClientException.launderThrowable(t);
} catch (Exception e) {
throw KubernetesClientException.launderThrowable(e);
}
}

@Override
public LocalPortForward portForward(int port, int localPort) {
try {
return new PortForwarderWebsocket(httpClient, this.context.getExecutor()).forward(getResourceUrl(), port, localPort);
} catch (Throwable t) {
throw KubernetesClientException.launderThrowable(t);
} catch (Exception e) {
throw KubernetesClientException.launderThrowable(e);
}
}

Expand Down Expand Up @@ -274,8 +274,8 @@ public ExecWatch exec(String... command) {
try {
URL url = getExecURLWithCommandParams(actualCommands);
return setupConnectionToPod(url.toURI());
} catch (Throwable t) {
throw KubernetesClientException.launderThrowable(forOperationType("exec"), t);
} catch (Exception e) {
throw KubernetesClientException.launderThrowable(forOperationType("exec"), e);
}
}

Expand All @@ -284,8 +284,8 @@ public ExecWatch attach() {
try {
URL url = getAttachURL();
return setupConnectionToPod(url.toURI());
} catch (Throwable t) {
throw KubernetesClientException.launderThrowable(forOperationType("attach"), t);
} catch (Exception e) {
throw KubernetesClientException.launderThrowable(forOperationType("attach"), e);
}
}

Expand Down Expand Up @@ -591,7 +591,7 @@ public BytesLimitTerminateTimeTailPrettyLoggable usingTimestamps() {
}

public static String shellQuote(String value) {
return "'" + value.replace("'", "'\\\\''") + "'";
return "'" + value.replace("'", "'\\''") + "'";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,24 @@ void createExecCommandForUpload_withNormalFile_shouldCreateValidExecCommandForUp
assertThat(result, equalTo("mkdir -p '/tmp/foo' && base64 -d - > '/tmp/foo/cp.log'"));
}

@Test
void createExecCommandForUpload_withSingleQuoteInPath() {
// When
String result = PodUpload.createExecCommandForUpload("/tmp/fo'o/cp.log");

// Then
assertThat(result, equalTo("mkdir -p '/tmp/fo\'\\'\'o' && base64 -d - > '/tmp/fo\'\\'\'o/cp.log'"));
}

@Test
void createExecCommandForUpload_withMultipleSingleQuotesInPath() {
// When
String result = PodUpload.createExecCommandForUpload("/tmp/f'o'o/c'p.log");

// Then
assertThat(result, equalTo("mkdir -p '/tmp/f\'\\'\'o\'\\'\'o' && base64 -d - > '/tmp/f\'\\'\'o\'\\'\'o/c\'\\'\'p.log'"));
}

void uploadFileAndVerify(PodUploadTester<Boolean> fileUploadMethodToTest) throws IOException, InterruptedException {
this.operation = operation.file("/mock/dir/file");
WebSocket.Builder builder = Mockito.mock(WebSocket.Builder.class, Mockito.RETURNS_SELF);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ void uploadFile() throws IOException {

assertUploaded("pod-standard", tmpFile, "/tmp/toBeUploaded");
assertUploaded("pod-standard", tmpFile, "/tmp/001_special_!@#\\$^&(.mp4");
assertUploaded("pod-standard", tmpFile, "/tmp/002'special");
}

private void assertUploaded(String podName, final Path tmpFile, String filename) throws IOException {
Expand Down