diff --git a/authentikos/authentikos.go b/authentikos/authentikos.go index c3c250794cc..96cad292e4e 100755 --- a/authentikos/authentikos.go +++ b/authentikos/authentikos.go @@ -306,16 +306,19 @@ func getOauthTokenCreator(o options) (tokenCreator, error) { client, err := clientCreator(forceRefresh) if err != nil { + printVerbose(fmt.Sprintf("Failed to create oauth token client: %v.", err), o.verbose) return withBackoff(1, maxTries-tries, create).(tokenCreator)(forceRefresh, tries-1) } token, err := client.TokenSource.Token() if err != nil { + printVerbose(fmt.Sprintf("Failed to get oauth token from client: %v.", err), o.verbose) return withBackoff(1, maxTries-tries, create).(tokenCreator)(forceRefresh, tries-1) } if isExpired(o, token) { // Force recreate the token if it will expire before the next reconciliation. + printVerbose("Token will expire before next reconciliation.", o.verbose) return withBackoff(1, maxTries-tries, create).(tokenCreator)(true, tries-1) } diff --git a/authentikos/authentikos_test.go b/authentikos/authentikos_test.go index 446d5ee8a5e..2bd08019497 100755 --- a/authentikos/authentikos_test.go +++ b/authentikos/authentikos_test.go @@ -28,30 +28,37 @@ import ( "golang.org/x/oauth2" ) -func makeFile(data string, readable bool) string { +func makeFile(data string, readable bool) (string, error) { f, _ := ioutil.TempFile("", "") fname := f.Name() - _ = ioutil.WriteFile(fname, []byte(data), 0644) + if err := ioutil.WriteFile(fname, []byte(data), 0644); err != nil { + return "", fmt.Errorf("failed to write file: %w", err) + } if !readable { - _ = os.Chmod(fname, 0000) + if err := os.Chmod(fname, 0000); err != nil { + return "", fmt.Errorf("failed to make file unreadable: %w", err) + } } - return fname + return fname, nil } func TestValidateFlags(t *testing.T) { creds := "super secret data" template := "{{.Token}}" - deletedCredsFile := makeFile(creds, true) - validTFile := makeFile(template, true) - invalidTFile := makeFile(template, false) - + deletedCredsFile, err := makeFile(creds, true) + if err != nil { + t.Errorf("Error making deleted creds file: %v.", err) + } + validTFile, err := makeFile(template, true) + if err != nil { + t.Errorf("Error making valid template file: %v.", err) + } os.Remove(deletedCredsFile) defer os.Remove(validTFile) - defer os.Remove(invalidTFile) testCases := []struct { name string @@ -106,11 +113,6 @@ func TestValidateFlags(t *testing.T) { args: []string{"--template=" + template, "--template-file=/path/to/file"}, expectedErr: true, }, - { - name: "error: template-file unreadable", - args: []string{"--template-file=" + invalidTFile}, - expectedErr: true, - }, { name: "error: creds does not exist", args: []string{"--creds=" + deletedCredsFile},