Skip to content

Commit

Permalink
fix: Config client authentication exec command should not fail when a…
Browse files Browse the repository at this point in the history
…rgs is null

Signed-off-by: Sun Seng David TAN <sutan@redhat.com>
  • Loading branch information
sunix committed Sep 2, 2022
1 parent 0d8bafc commit de32b96
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 1 deletion.
Expand Up @@ -764,8 +764,9 @@ protected static List<String> getAuthenticatorCommandFromExecConfig(ExecConfig e
command = getCommandWithFullyQualifiedPath(command, systemPathValue);
List<String> args = exec.getArgs();
if (args != null) {
argv.add(command + " " + String.join(" ", args));
command += " " + String.join(" ", args);
}
argv.add(command);
return argv;
}

Expand Down
Expand Up @@ -57,6 +57,11 @@ public class ConfigTest {
private static final String TEST_KUBECONFIG_EXEC_WIN_FILE = Utils
.filePath(ConfigTest.class.getResource("/test-kubeconfig-exec-win"));

private static final String TEST_KUBECONFIG_EXEC_FILE_NULL_ARGS = Utils
.filePath(ConfigTest.class.getResource("/test-kubeconfig-exec-null-args"));
private static final String TEST_KUBECONFIG_EXEC_FILE_WIN_NULL_ARGS = Utils
.filePath(ConfigTest.class.getResource("/test-kubeconfig-exec-win-null-args"));

private static final String TEST_KUBECONFIG_NO_CURRENT_CONTEXT_FILE = Utils
.filePath(ConfigTest.class.getResource("/test-kubeconfig-nocurrentctxt.yml"));

Expand Down Expand Up @@ -446,6 +451,21 @@ void honorClientAuthenticatorCommands() throws Exception {
assertEquals("HELLO WORLD", config.getOauthToken());
}

@Test
void should_accept_client_authentication_commands_with_null_args() throws Exception {

if (FileSystem.getCurrent() == FileSystem.WINDOWS) {
System.setProperty(Config.KUBERNETES_KUBECONFIG_FILE, TEST_KUBECONFIG_EXEC_FILE_WIN_NULL_ARGS);
} else {
Files.setPosixFilePermissions(Paths.get(TEST_TOKEN_GENERATOR_FILE), PosixFilePermissions.fromString("rwxrwxr-x"));
System.setProperty(Config.KUBERNETES_KUBECONFIG_FILE, TEST_KUBECONFIG_EXEC_FILE_NULL_ARGS);
}

Config config = Config.autoConfigure(null);
assertNotNull(config);
assertEquals("HELLO", config.getOauthToken());
}

@Test
void shouldBeUsedTokenSuppliedByProvider() {

Expand Down
@@ -0,0 +1,22 @@
apiVersion: v1
kind: Config
clusters:
- cluster:
server: https://wherever
name: test
contexts:
- context:
cluster: test
user: test
name: test
current-context: test
users:
- name: test
user:
exec:
apiVersion: client.authentication.k8s.io/v1alpha1
args: null
command: ./token-generator
env:
- name: PART1
value: hello
@@ -0,0 +1,22 @@
apiVersion: v1
kind: Config
clusters:
- cluster:
server: https://wherever
name: test
contexts:
- context:
cluster: test
user: test
name: test
current-context: test
users:
- name: test
user:
exec:
apiVersion: client.authentication.k8s.io/v1alpha1
args: null
command: ".\\token-generator-win.bat"
env:
- name: PART1
value: hello

0 comments on commit de32b96

Please sign in to comment.