Skip to content

fixed password endline bug #5500

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

Closed
wants to merge 3 commits into from
Closed

Conversation

moki1202
Copy link
Contributor

@moki1202 moki1202 commented Aug 5, 2023

Which issue(s) this PR fixes:
Fixes #5444

Checklist

  • Tests updated
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

Copy link
Member

@friedrichg friedrichg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And also mention the fix in the changelog

@@ -77,7 +78,8 @@ func New(cfg Config) (DB, error) {
if err != nil {
return nil, fmt.Errorf("Could not read database password file: %v", err)
}
u.User = url.UserPassword(u.User.Username(), string(passwordBytes))
password := strings.TrimSpace(string(passwordBytes))
u.User = url.UserPassword(u.User.Username(), password)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but it's not complete. Ideally for every change we modify or add a tests.

you can extract a function that returns url u and error as needed and test that function.

@moki1202
Copy link
Contributor Author

moki1202 commented Dec 1, 2023

@friedrichg Please let me know if this is what you asked for. If correct, I'll add a few more test cases.

Copy link
Member

@friedrichg friedrichg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple of nits

@@ -4,6 +4,9 @@
package dbtest
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't modify this file, this is part of integration tests

@@ -26,3 +29,48 @@ func Setup(t *testing.T) db.DB {
func Cleanup(t *testing.T, database db.DB) {
require.NoError(t, database.Close())
}

func TestUserPasswordFromPasswordFile(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create a file called db_test.go next to db.go and move this test there.

Comment on lines 36 to 37
defer tempFile.Close()
defer os.Remove(tempFile.Name())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defer functions have a specific order.
In this case we are removing and then closing. We want the opposite.
https://go.dev/tour/flowcontrol/13#:~:text=Deferred%20function%20calls%20are%20pushed,in%2Dfirst%2Dout%20order.

return nil, fmt.Errorf("--database.password-file requires username in --database.uri")
}
passwordBytes, err := os.ReadFile(cfg.PasswordFile)
updatedUrl, err := SetUserPassword(u, cfg.PasswordFile)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
updatedUrl, err := SetUserPassword(u, cfg.PasswordFile)
updatedURL, err := SetUserPassword(u, cfg.PasswordFile)

So it passes linting

@moki1202
Copy link
Contributor Author

moki1202 commented Feb 7, 2024

@friedrichg should I add few more testcases here? please let me know if this PR needs further tweaks.

@friedrichg
Copy link
Member

@moki1202 the lint has to pass and the changelog entry is missing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Configsdb: postgres auth fails after v1.15.0
2 participants