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

chore: add missing error checks #202

Merged
merged 1 commit into from
Jul 13, 2023
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
10 changes: 8 additions & 2 deletions caching_file_reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ func TestCachingFileReader(t *testing.T) {
})

// Write initial content to file and check that we can read it.
ioutil.WriteFile(f.Name(), []byte(content1), 0o644)
err = ioutil.WriteFile(f.Name(), []byte(content1), 0o644)
if err != nil {
t.Error(err)
}
got, err := r.ReadFile()
if err != nil {
t.Error(err)
Expand All @@ -40,7 +43,10 @@ func TestCachingFileReader(t *testing.T) {
}

// Write new content to the file.
ioutil.WriteFile(f.Name(), []byte(content2), 0o644)
err = ioutil.WriteFile(f.Name(), []byte(content2), 0o644)
if err != nil {
t.Error(err)
}

// Advance simulated time, but not enough for cache to expire.
currentTime = currentTime.Add(30 * time.Second)
Expand Down
13 changes: 10 additions & 3 deletions cmd/vault-plugin-auth-kubernetes/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ import (

func main() {
apiClientMeta := &api.PluginAPIClientMeta{}

flags := apiClientMeta.FlagSet()
flags.Parse(os.Args[1:])
if err := flags.Parse(os.Args[1:]); err != nil {
fatal(err)
}

tlsConfig := apiClientMeta.GetTLSConfig()
tlsProviderFunc := api.VaultPluginTLSProvider(tlsConfig)
Expand All @@ -28,7 +31,11 @@ func main() {
TLSProviderFunc: tlsProviderFunc,
})
if err != nil {
log.L().Error("plugin shutting down", "error", err)
os.Exit(1)
fatal(err)
}
}

func fatal(err error) {
log.L().Error("plugin shutting down", "error", err)
os.Exit(1)
}
20 changes: 16 additions & 4 deletions path_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,20 @@ func setupLocalFiles(t *testing.T, b logical.Backend) func() {
if err != nil {
t.Fatal(err)
}
cert.WriteString(testLocalCACert)
_, err = cert.WriteString(testLocalCACert)
if err != nil {
t.Fatal(err)
}
cert.Close()

token, err := ioutil.TempFile("", "token")
if err != nil {
t.Fatal(err)
}
token.WriteString(testLocalJWT)
_, err = token.WriteString(testLocalJWT)
if err != nil {
t.Fatal(err)
}
token.Close()
b.(*kubeAuthBackend).localCACertReader = newCachingFileReader(cert.Name(), caReloadPeriod, time.Now)
b.(*kubeAuthBackend).localSATokenReader = newCachingFileReader(token.Name(), jwtReloadPeriod, time.Now)
Expand Down Expand Up @@ -484,7 +490,10 @@ func TestConfig_LocalJWTRenewal(t *testing.T) {
token2 := "after-renewal"

// Write initial token to the temp file.
ioutil.WriteFile(f.Name(), []byte(token1), 0o644)
err = ioutil.WriteFile(f.Name(), []byte(token1), 0o644)
if err != nil {
t.Error(err)
}

data := map[string]interface{}{
"kubernetes_host": "host",
Expand Down Expand Up @@ -513,7 +522,10 @@ func TestConfig_LocalJWTRenewal(t *testing.T) {
}

// Write new value to the token file to simulate renewal.
ioutil.WriteFile(f.Name(), []byte(token2), 0o644)
err = ioutil.WriteFile(f.Name(), []byte(token2), 0o644)
if err != nil {
t.Error(err)
}

// Load again to check we still got the old cached token from memory.
conf, err = b.(*kubeAuthBackend).loadConfig(context.Background(), storage)
Expand Down