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

error parsing database password in database.yml #402

Closed
Tracked by #770
rezan83 opened this issue Jun 25, 2019 · 5 comments · Fixed by #774
Closed
Tracked by #770

error parsing database password in database.yml #402

rezan83 opened this issue Jun 25, 2019 · 5 comments · Fixed by #774
Assignees
Labels
bug Something isn't working s: fixed was fixed or solution offered
Milestone

Comments

@rezan83
Copy link

rezan83 commented Jun 25, 2019

Description

my database pass was something like this: longname#?
when running dev it failed to make transaction giving the error: could not create new transaction: dial tcp: address tcp/longname: unknown port

Expected Behavior

one should be able to make whatever password he wants for the database

Actual Behavior

because there was no actual tcp with the name tcp/longname I thought that its a parsing problem with the #? part of the password. I have no idea why and how!

Info

for me, I simply solved the problem with changing the password and delete the #? part and using only ordinary characters and that's how I made sure that that was the problem

@markbates markbates pinned this issue Jun 25, 2019
@markbates markbates unpinned this issue Jun 25, 2019
@markbates markbates pinned this issue Jun 25, 2019
@markbates markbates unpinned this issue Jun 25, 2019
@markbates markbates transferred this issue from gobuffalo/buffalo Jun 25, 2019
@stanislas-m stanislas-m added bug Something isn't working s: triage Some tests need to be run to confirm the issue labels Jun 26, 2019
@stanislas-m
Copy link
Member

Hi @rezan83, can you provide more info about your setup? At least your OS and the database used. Thanks!

@stanislas-m stanislas-m added status-waiting-for-reply and removed s: triage Some tests need to be run to confirm the issue labels Jun 29, 2019
@rezan83
Copy link
Author

rezan83 commented Jun 29, 2019

ubuntu 19.04, postgres 11.4

@stanislas-m stanislas-m added s: triage Some tests need to be run to confirm the issue and removed status-waiting-for-reply labels Jun 29, 2019
@rezan83
Copy link
Author

rezan83 commented Jun 29, 2019

the output of buffalo info:
`### Buffalo Version
v0.14.2

App Information

Pwd=/home/rezan/go/src/github.com/buffalo_project/first
Root=/home/rezan/go/src/github.com/buffalo_project/first
GoPath=/home/rezan/go
PackagePkg=github.com/buffalo_project/first
ActionsPkg=github.com/buffalo_project/first/actions
ModelsPkg=github.com/buffalo_project/first/models
GriftsPkg=github.com/buffalo_project/first/grifts
WithModules=false
Name=first
Bin=bin/first
VCS=git
WithPop=true
WithSQLite=false
WithDep=false
WithWebpack=true
WithNodeJs=true
WithYarn=true
WithDocker=true
WithGrifts=true
AsWeb=true
AsAPI=false
PackageJSON={map[]}

Go Version

go version go1.12.6 linux/amd64

Go Env

GOARCH="amd64"
GOBIN=""
GOCACHE="/home/rezan/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/rezan/go"
GOPROXY=""
GORACE=""
GOROOT="/snap/go/3947"
GOTMPDIR=""
GOTOOLDIR="/snap/go/3947/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build958201183=/tmp/go-build -gno-record-gcc-switches"

Node Version

v10.15.2

NPM Version

6.9.0

Yarn Version

1.12.3

PostgreSQL Version

PostgreSQL Not Found

MySQL Version

MySQL Not Found

SQLite Version

3.27.2 2019-02-25 16:06:06 bd49a8271d650fa89e446b42e513b595a717b9212c91dd384aab871fc1d0alt1

Dep Version

could not find a Gopkg.toml file

Dep Status

could not find a Gopkg.toml file

config/buffalo-app.toml

name = "first"
bin = "bin/first"
vcs = "git"
with_pop = true
with_sqlite = false
with_dep = false
with_webpack = true
with_nodejs = true
with_yarn = true
with_docker = true
with_grifts = true
as_web = true
as_api = false

config/buffalo-plugins.toml

[[plugin]]
binary = "buffalo-plugins"
go_get = "github.com/gobuffalo/buffalo-plugins"

[[plugin]]
binary = "buffalo-pop"
go_get = "github.com/gobuffalo/buffalo-pop"
`

@stanislas-m stanislas-m self-assigned this Jun 30, 2019
@andrewmelis
Copy link

andrewmelis commented Sep 9, 2019

This issue bit me as well while using postgres. Turns out it was an "issue" with lib/pq's use of net/url to parse connection strings that contain reserved characters (see RFC 3986). Reserved characters in a connection string need to be URL encoded for things to work properly.

This comment in lib/pq pointed me in the right direction: lib/pq#787 (comment)

Also, here's a go playground illustrating the issue in case it helps: https://play.golang.org/p/bqArco_cMyP


Changing pass to pass# in Test_ConnectionDetails_Finalize is sufficient to reproduce the issue

URL: "postgres://user:pass@host:port/database",
}
err := cd.Finalize()
r.NoError(err)
r.Equal("database", cd.Database)
r.Equal("postgres", cd.Dialect)
r.Equal("host", cd.Host)
r.Equal("pass", cd.Password)

following the breadcrumbs...

if up, ok := urlParser[cd.Dialect]; ok {
return up(cd)
}

name, err = pg.ParseURL(name)

pg "github.com/lib/pq"

then, over in lib/pq, ParseUrl calls net/url
https://github.com/lib/pq/blob/78223426e7c66d631117c0a9da1b7f3fde4d23a5/url.go#L6-L33


The next question is what to do about the situation. I can understand the use of the underlying url parsing library, but it seems clear that some users (myself included) expect to be able to use an unaltered password when specifying connection details.

Is a note in the documentation visible enough as a solution? Should something be responsible for encoding any passwords that include reserved characters so that things just work?

@onesick
Copy link

onesick commented Sep 10, 2019

@andrewmelis

Hey Andrew, you are on the right track. I just had to solve the same problem where my password used a reserved character. The solution is you put all the address string information into url.URL struct. You can put userinfo into url.URL.User = url.UserPassword(user, password). You can print out the final constructed url string and can see that it is encoded to verify.

@sio4 sio4 added this to the v6.0.7 milestone Sep 20, 2022
@sio4 sio4 mentioned this issue Sep 20, 2022
30 tasks
@sio4 sio4 removed the s: triage Some tests need to be run to confirm the issue label Sep 22, 2022
@sio4 sio4 self-assigned this Sep 22, 2022
@sio4 sio4 closed this as completed in #774 Sep 24, 2022
@sio4 sio4 added the s: fixed was fixed or solution offered label Sep 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working s: fixed was fixed or solution offered
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants