Skip to content

Commit

Permalink
Use only the basename (filename) and not the full path for the pinnip…
Browse files Browse the repository at this point in the history
…ed binary
  • Loading branch information
joshuatcasey committed Sep 21, 2023
1 parent 1ac8691 commit 19177fd
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 27 deletions.
6 changes: 5 additions & 1 deletion cmd/pinniped/cmd/kubeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"io"
"net/http"
"os"
"path/filepath"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -268,7 +269,10 @@ func newExecConfig(deps kubeconfigDeps, flags getKubeconfigParams) (*clientcmdap

execConfig.InstallHint = flags.installHint
var err error
execConfig.Command, err = deps.getPathToSelf()
execConfig.Command, err = func() (string, error) {
command, err := deps.getPathToSelf()
return filepath.Base(command), err
}()
if err != nil {
return nil, fmt.Errorf("could not determine the Pinniped executable path: %w", err)
}
Expand Down
57 changes: 31 additions & 26 deletions cmd/pinniped/cmd/kubeconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ func TestGetKubeconfig(t *testing.T) {
name string
args func(string, string) []string
env map[string]string
getPathToSelf string
getPathToSelfErr error
getClientsetErr error
conciergeObjects func(string, string) []runtime.Object
Expand Down Expand Up @@ -1368,7 +1369,7 @@ func TestGetKubeconfig(t *testing.T) {
- --upstream-identity-provider-name=some-ldap-idp
- --upstream-identity-provider-type=ldap
- --upstream-identity-provider-flow=cli_password
command: '.../path/to/pinniped'
command: pinniped
env: []
installHint: The pinniped CLI does not appear to be installed. See https://get.pinniped.dev/cli
for more details
Expand All @@ -1383,7 +1384,8 @@ func TestGetKubeconfig(t *testing.T) {
},
},
{
name: "valid static token",
name: "valid static token",
getPathToSelf: "../../other/path/other-executable",
args: func(issuerCABundle string, issuerURL string) []string {
return []string{
"--kubeconfig", "./testdata/kubeconfig.yaml",
Expand Down Expand Up @@ -1437,7 +1439,7 @@ func TestGetKubeconfig(t *testing.T) {
- --concierge-endpoint=https://fake-server-url-value
- --concierge-ca-bundle-data=ZmFrZS1jZXJ0aWZpY2F0ZS1hdXRob3JpdHktZGF0YS12YWx1ZQ==
- --token=test-token
command: '.../path/to/pinniped'
command: other-executable
env: []
installHint: The pinniped CLI does not appear to be installed. See https://get.pinniped.dev/cli
for more details
Expand Down Expand Up @@ -1502,7 +1504,7 @@ func TestGetKubeconfig(t *testing.T) {
- --concierge-ca-bundle-data=ZmFrZS1jZXJ0aWZpY2F0ZS1hdXRob3JpdHktZGF0YS12YWx1ZQ==
- --credential-cache=
- --token-env=TEST_TOKEN
command: '.../path/to/pinniped'
command: pinniped
env: []
installHint: The pinniped CLI does not appear to be installed. See https://get.pinniped.dev/cli
for more details
Expand Down Expand Up @@ -1572,7 +1574,7 @@ func TestGetKubeconfig(t *testing.T) {
- --scopes=offline_access,openid,pinniped:request-audience,username,groups
- --ca-bundle-data=%s
- --request-audience=test-audience
command: '.../path/to/pinniped'
command: pinniped
env: []
installHint: The pinniped CLI does not appear to be installed. See https://get.pinniped.dev/cli
for more details
Expand Down Expand Up @@ -1658,7 +1660,7 @@ func TestGetKubeconfig(t *testing.T) {
- --session-cache=/path/to/cache/dir/sessions.yaml
- --debug-session-cache
- --request-audience=test-audience
command: '.../path/to/pinniped'
command: pinniped
env: []
installHint: The pinniped CLI does not appear to be installed. See https://get.pinniped.dev/cli
for more details
Expand Down Expand Up @@ -1771,7 +1773,7 @@ func TestGetKubeconfig(t *testing.T) {
- --scopes=offline_access,openid,pinniped:request-audience,username,groups
- --ca-bundle-data=%s
- --request-audience=test-audience
command: '.../path/to/pinniped'
command: pinniped
env: []
installHint: The pinniped CLI does not appear to be installed. See https://get.pinniped.dev/cli
for more details
Expand Down Expand Up @@ -1880,7 +1882,7 @@ func TestGetKubeconfig(t *testing.T) {
- --scopes=offline_access,openid,pinniped:request-audience,username,groups
- --ca-bundle-data=%s
- --request-audience=test-audience
command: '.../path/to/pinniped'
command: pinniped
env: []
installHint: The pinniped CLI does not appear to be installed. See https://get.pinniped.dev/cli
for more details
Expand Down Expand Up @@ -1959,7 +1961,7 @@ func TestGetKubeconfig(t *testing.T) {
- --request-audience=test-audience
- --upstream-identity-provider-name=some-ldap-idp
- --upstream-identity-provider-type=ldap
command: '.../path/to/pinniped'
command: pinniped
env: []
installHint: The pinniped CLI does not appear to be installed. See https://get.pinniped.dev/cli
for more details
Expand Down Expand Up @@ -2038,7 +2040,7 @@ func TestGetKubeconfig(t *testing.T) {
- --request-audience=test-audience
- --upstream-identity-provider-name=some-oidc-idp
- --upstream-identity-provider-type=oidc
command: '.../path/to/pinniped'
command: pinniped
env: []
installHint: The pinniped CLI does not appear to be installed. See https://get.pinniped.dev/cli
for more details
Expand Down Expand Up @@ -2113,7 +2115,7 @@ func TestGetKubeconfig(t *testing.T) {
- --scopes=offline_access,openid,pinniped:request-audience,username,groups
- --ca-bundle-data=%s
- --request-audience=test-audience
command: '.../path/to/pinniped'
command: pinniped
env: []
installHint: The pinniped CLI does not appear to be installed. See https://get.pinniped.dev/cli
for more details
Expand Down Expand Up @@ -2186,7 +2188,7 @@ func TestGetKubeconfig(t *testing.T) {
- --scopes=offline_access,openid,pinniped:request-audience,username,groups
- --ca-bundle-data=%s
- --request-audience=test-audience
command: '.../path/to/pinniped'
command: pinniped
env: []
installHint: The pinniped CLI does not appear to be installed. See https://get.pinniped.dev/cli
for more details
Expand Down Expand Up @@ -2266,7 +2268,7 @@ func TestGetKubeconfig(t *testing.T) {
- --scopes=offline_access,openid,pinniped:request-audience,username,groups
- --ca-bundle-data=%s
- --request-audience=test-audience
command: '.../path/to/pinniped'
command: pinniped
env: []
installHint: The pinniped CLI does not appear to be installed. See https://get.pinniped.dev/cli
for more details
Expand Down Expand Up @@ -2355,7 +2357,7 @@ func TestGetKubeconfig(t *testing.T) {
- --request-audience=test-audience
- --upstream-identity-provider-name=some-oidc-idp
- --upstream-identity-provider-type=oidc
command: '.../path/to/pinniped'
command: pinniped
env: []
installHint: The pinniped CLI does not appear to be installed. See https://get.pinniped.dev/cli
for more details
Expand Down Expand Up @@ -2443,7 +2445,7 @@ func TestGetKubeconfig(t *testing.T) {
- --request-audience=test-audience
- --upstream-identity-provider-name=some-oidc-idp
- --upstream-identity-provider-type=oidc
command: '.../path/to/pinniped'
command: pinniped
env: []
installHint: The pinniped CLI does not appear to be installed. See https://get.pinniped.dev/cli
for more details
Expand Down Expand Up @@ -2531,7 +2533,7 @@ func TestGetKubeconfig(t *testing.T) {
- --request-audience=test-audience
- --upstream-identity-provider-name=some-oidc-idp
- --upstream-identity-provider-type=oidc
command: '.../path/to/pinniped'
command: pinniped
env: []
installHint: The pinniped CLI does not appear to be installed. See https://get.pinniped.dev/cli
for more details
Expand Down Expand Up @@ -2610,7 +2612,7 @@ func TestGetKubeconfig(t *testing.T) {
- --upstream-identity-provider-name=some-oidc-idp
- --upstream-identity-provider-type=oidc
- --upstream-identity-provider-flow=foobar
command: '.../path/to/pinniped'
command: pinniped
env: []
installHint: The pinniped CLI does not appear to be installed. See https://get.pinniped.dev/cli
for more details
Expand Down Expand Up @@ -2693,7 +2695,7 @@ func TestGetKubeconfig(t *testing.T) {
- --upstream-identity-provider-name=some-oidc-idp
- --upstream-identity-provider-type=oidc
- --upstream-identity-provider-flow=foobar
command: '.../path/to/pinniped'
command: pinniped
env: []
installHint: The pinniped CLI does not appear to be installed. See https://get.pinniped.dev/cli
for more details
Expand Down Expand Up @@ -2751,7 +2753,7 @@ func TestGetKubeconfig(t *testing.T) {
- --ca-bundle-data=%s
- --upstream-identity-provider-name=some-ldap-idp
- --upstream-identity-provider-type=ldap
command: '.../path/to/pinniped'
command: pinniped
env: []
installHint: The pinniped CLI does not appear to be installed. See https://get.pinniped.dev/cli
for more details
Expand Down Expand Up @@ -2812,7 +2814,7 @@ func TestGetKubeconfig(t *testing.T) {
- --ca-bundle-data=%s
- --upstream-identity-provider-name=some-ldap-idp
- --upstream-identity-provider-type=ldap
command: '.../path/to/pinniped'
command: pinniped
env: []
installHint: The pinniped CLI does not appear to be installed. See https://get.pinniped.dev/cli
for more details
Expand Down Expand Up @@ -2873,7 +2875,7 @@ func TestGetKubeconfig(t *testing.T) {
- --ca-bundle-data=%s
- --upstream-identity-provider-name=some-ldap-idp
- --upstream-identity-provider-type=ldap
command: '.../path/to/pinniped'
command: pinniped
env: []
installHint: The pinniped CLI does not appear to be installed. See https://get.pinniped.dev/cli
for more details
Expand Down Expand Up @@ -2935,7 +2937,7 @@ func TestGetKubeconfig(t *testing.T) {
- --ca-bundle-data=%s
- --upstream-identity-provider-name=some-ldap-idp
- --upstream-identity-provider-type=ldap
command: '.../path/to/pinniped'
command: pinniped
env: []
installHint: The pinniped CLI does not appear to be installed. See https://get.pinniped.dev/cli
for more details
Expand Down Expand Up @@ -2998,7 +3000,7 @@ func TestGetKubeconfig(t *testing.T) {
- --upstream-identity-provider-name=some-ldap-idp
- --upstream-identity-provider-type=ldap
- --upstream-identity-provider-flow=foobar
command: '.../path/to/pinniped'
command: pinniped
env: []
installHint: The pinniped CLI does not appear to be installed. See https://get.pinniped.dev/cli
for more details
Expand Down Expand Up @@ -3059,7 +3061,7 @@ func TestGetKubeconfig(t *testing.T) {
- --upstream-identity-provider-name=some-ldap-idp
- --upstream-identity-provider-type=ldap
- --upstream-identity-provider-flow=cli_password
command: '.../path/to/pinniped'
command: pinniped
env: []
installHint: The pinniped CLI does not appear to be installed. See https://get.pinniped.dev/cli
for more details
Expand Down Expand Up @@ -3119,7 +3121,7 @@ func TestGetKubeconfig(t *testing.T) {
- --upstream-identity-provider-name=some-ldap-idp
- --upstream-identity-provider-type=ldap
- --upstream-identity-provider-flow=cli_password
command: '.../path/to/pinniped'
command: pinniped
env: []
installHint: The pinniped CLI does not appear to be installed. See https://get.pinniped.dev/cli
for more details
Expand Down Expand Up @@ -3185,7 +3187,7 @@ func TestGetKubeconfig(t *testing.T) {
- --concierge-endpoint=https://fake-server-url-value
- --concierge-ca-bundle-data=ZmFrZS1jZXJ0aWZpY2F0ZS1hdXRob3JpdHktZGF0YS12YWx1ZQ==
- --token=test-token
command: '.../path/to/pinniped'
command: pinniped
env: []
installHint: Test installHint message
provideClusterInfo: true
Expand Down Expand Up @@ -3234,6 +3236,9 @@ func TestGetKubeconfig(t *testing.T) {
if tt.getPathToSelfErr != nil {
return "", tt.getPathToSelfErr
}
if tt.getPathToSelf != "" {
return tt.getPathToSelf, nil
}
return ".../path/to/pinniped", nil
},
getClientset: func(clientConfig clientcmd.ClientConfig, apiGroupSuffix string) (conciergeclientset.Interface, error) {
Expand Down

0 comments on commit 19177fd

Please sign in to comment.