-
Notifications
You must be signed in to change notification settings - Fork 73
CNF-23374: Migrate away from deprecated ioutil #202
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,6 @@ package oauthserver | |
| import ( | ||
| "context" | ||
| "fmt" | ||
| "io/ioutil" | ||
| "net/http" | ||
| "os" | ||
| "path/filepath" | ||
|
|
@@ -35,13 +34,13 @@ func TestGetMissingSessionSecretsFile(t *testing.T) { | |
| } | ||
|
|
||
| func TestGetInvalidSessionSecretsFile(t *testing.T) { | ||
| tmpfile, err := ioutil.TempFile("", "invalid.yaml") | ||
| tmpfile, err := os.CreateTemp("", "invalid.yaml") | ||
| if err != nil { | ||
| t.Fatalf("unexpected error: %v", err) | ||
| } | ||
| defer os.Remove(tmpfile.Name()) | ||
|
|
||
| if err := ioutil.WriteFile(tmpfile.Name(), []byte("invalid content"), os.FileMode(0600)); err != nil { | ||
| if err := os.WriteFile(tmpfile.Name(), []byte("invalid content"), os.FileMode(0600)); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
|
Comment on lines
+43
to
45
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use These tests use Also applies to: 61-63, 90-92 🤖 Prompt for AI Agents |
||
|
|
||
|
|
@@ -52,7 +51,7 @@ func TestGetInvalidSessionSecretsFile(t *testing.T) { | |
| } | ||
|
|
||
| func TestGetEmptySessionSecretsFile(t *testing.T) { | ||
| tmpfile, err := ioutil.TempFile("", "empty.yaml") | ||
| tmpfile, err := os.CreateTemp("", "empty.yaml") | ||
| if err != nil { | ||
| t.Fatalf("unexpected error: %v", err) | ||
| } | ||
|
|
@@ -66,7 +65,7 @@ func TestGetEmptySessionSecretsFile(t *testing.T) { | |
| if err != nil { | ||
| t.Errorf("Unexpected error: %v", err) | ||
| } | ||
| if err := ioutil.WriteFile(tmpfile.Name(), []byte(yaml), os.FileMode(0600)); err != nil { | ||
| if err := os.WriteFile(tmpfile.Name(), []byte(yaml), os.FileMode(0600)); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
|
|
||
|
|
@@ -168,7 +167,7 @@ func TestConfigureTransport_ProxyCAFileNotFound(t *testing.T) { | |
| } | ||
|
|
||
| func TestGetValidSessionSecretsFile(t *testing.T) { | ||
| tmpfile, err := ioutil.TempFile("", "valid.yaml") | ||
| tmpfile, err := os.CreateTemp("", "valid.yaml") | ||
| if err != nil { | ||
| t.Fatalf("unexpected error: %v", err) | ||
| } | ||
|
|
@@ -186,7 +185,7 @@ func TestGetValidSessionSecretsFile(t *testing.T) { | |
| if err != nil { | ||
| t.Errorf("Unexpected error: %v", err) | ||
| } | ||
| if err := ioutil.WriteFile(tmpfile.Name(), []byte(yaml), os.FileMode(0600)); err != nil { | ||
| if err := os.WriteFile(tmpfile.Name(), []byte(yaml), os.FileMode(0600)); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handle request-body read errors in the Keystone test handler.
The handler ignores errors from
io.ReadAll(r.Body)(body, _ := ...). If that fails, the subsequentjson.Unmarshalassertion won’t clearly indicate the underlying read problem.💡 Suggested fix
🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1, this seems like a valid addition/fix here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@liouk, thanks for the confirmation! Here is the suggested fix for the PR author to apply:This ensures a body-read failure surfaces immediately with a clear error, rather than being silently swallowed and potentially causing a confusing
json.Unmarshalfailure downstream.