Skip to content

Commit

Permalink
🐛 Hardcode MongoDB authenticationDatabase to admin
Browse files Browse the repository at this point in the history
This will be configurable via a flag once per-database flags are added
  • Loading branch information
gabe565 committed Jul 14, 2022
1 parent 5c0b2a0 commit 4a407e6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
3 changes: 3 additions & 0 deletions internal/database/dialect/mongodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func (MongoDB) ExecCommand(conf config.Exec) *command.Builder {
"--host=127.0.0.1",
"--username="+conf.Username,
"--password="+conf.Password,
"--authenticationDatabase=admin",
)
if conf.DisableHeaders {
cmd.Push("--quiet")
Expand All @@ -91,6 +92,7 @@ func (MongoDB) DumpCommand(conf config.Dump) *command.Builder {
"--host=127.0.0.1",
"--username="+conf.Username,
"--password="+conf.Password,
"--authenticationDatabase=admin",
)
if conf.Database != "" {
cmd.Push("--db=" + conf.Database)
Expand All @@ -114,6 +116,7 @@ func (MongoDB) RestoreCommand(conf config.Restore, inputFormat sqlformat.Format)
"--host=127.0.0.1",
"--username="+conf.Username,
"--password="+conf.Password,
"--authenticationDatabase=admin",
)
if conf.Database != "" {
if conf.Clean {
Expand Down
26 changes: 13 additions & 13 deletions internal/database/dialect/mongodb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,27 +111,27 @@ func TestMongoDB_DumpCommand(t *testing.T) {
{
"default",
args{config.Dump{Global: config.Global{Database: "d", Username: "u", Password: "p"}}},
command.NewBuilder("mongodump", "--archive", "--host=127.0.0.1", "--username=u", "--password=p", "--db=d"),
command.NewBuilder("mongodump", "--archive", "--host=127.0.0.1", "--username=u", "--password=p", "--authenticationDatabase=admin", "--db=d"),
},
{
"clean",
args{config.Dump{Clean: true, Global: config.Global{Database: "d", Username: "u", Password: "p"}}},
command.NewBuilder("mongodump", "--archive", "--host=127.0.0.1", "--username=u", "--password=p", "--db=d"),
command.NewBuilder("mongodump", "--archive", "--host=127.0.0.1", "--username=u", "--password=p", "--authenticationDatabase=admin", "--db=d"),
},
{
"tables",
args{config.Dump{Tables: []string{"table1"}, Global: config.Global{Database: "d", Username: "u", Password: "p"}}},
command.NewBuilder("mongodump", "--archive", "--host=127.0.0.1", "--username=u", "--password=p", "--db=d", "--collection=table1"),
command.NewBuilder("mongodump", "--archive", "--host=127.0.0.1", "--username=u", "--password=p", "--authenticationDatabase=admin", "--db=d", "--collection=table1"),
},
{
"exclude-table",
args{config.Dump{ExcludeTable: []string{"table1", "table2"}, Global: config.Global{Database: "d", Username: "u", Password: "p"}}},
command.NewBuilder("mongodump", "--archive", "--host=127.0.0.1", "--username=u", "--password=p", "--db=d", "--excludeCollection=table1", "--excludeCollection=table2"),
command.NewBuilder("mongodump", "--archive", "--host=127.0.0.1", "--username=u", "--password=p", "--authenticationDatabase=admin", "--db=d", "--excludeCollection=table1", "--excludeCollection=table2"),
},
{
"quiet",
args{config.Dump{Global: config.Global{Database: "d", Username: "u", Password: "p", Quiet: true}}},
command.NewBuilder("mongodump", "--archive", "--host=127.0.0.1", "--username=u", "--password=p", "--db=d", "--quiet"),
command.NewBuilder("mongodump", "--archive", "--host=127.0.0.1", "--username=u", "--password=p", "--authenticationDatabase=admin", "--db=d", "--quiet"),
},
}
for _, tt := range tests {
Expand All @@ -156,17 +156,17 @@ func TestMongoDB_ExecCommand(t *testing.T) {
{
"default",
args{config.Exec{Global: config.Global{Database: "d", Username: "u", Password: "p"}}},
command.NewBuilder("mongosh", "--host=127.0.0.1", "--username=u", "--password=p", "d"),
command.NewBuilder("mongosh", "--host=127.0.0.1", "--username=u", "--password=p", "--authenticationDatabase=admin", "d"),
},
{
"disable-headers",
args{config.Exec{DisableHeaders: true, Global: config.Global{Database: "d", Username: "u", Password: "p"}}},
command.NewBuilder("mongosh", "--host=127.0.0.1", "--username=u", "--password=p", "--quiet", "d"),
command.NewBuilder("mongosh", "--host=127.0.0.1", "--username=u", "--password=p", "--authenticationDatabase=admin", "--quiet", "d"),
},
{
"command",
args{config.Exec{Command: "show databases", Global: config.Global{Database: "d", Username: "u", Password: "p"}}},
command.NewBuilder("mongosh", "--host=127.0.0.1", "--username=u", "--password=p", "--eval=show databases", "d"),
command.NewBuilder("mongosh", "--host=127.0.0.1", "--username=u", "--password=p", "--authenticationDatabase=admin", "--eval=show databases", "d"),
},
}
for _, tt := range tests {
Expand Down Expand Up @@ -311,27 +311,27 @@ func TestMongoDB_RestoreCommand(t *testing.T) {
{
"gzip",
args{config.Restore{Global: config.Global{Database: "d", Username: "u", Password: "p"}}, sqlformat.Gzip},
command.NewBuilder("mongorestore", "--archive", "--host=127.0.0.1", "--username=u", "--password=p", "--db=d"),
command.NewBuilder("mongorestore", "--archive", "--host=127.0.0.1", "--username=u", "--password=p", "--authenticationDatabase=admin", "--db=d"),
},
{
"plain",
args{config.Restore{Global: config.Global{Database: "d", Username: "u", Password: "p"}}, sqlformat.Plain},
command.NewBuilder("mongorestore", "--archive", "--host=127.0.0.1", "--username=u", "--password=p", "--db=d"),
command.NewBuilder("mongorestore", "--archive", "--host=127.0.0.1", "--username=u", "--password=p", "--authenticationDatabase=admin", "--db=d"),
},
{
"custom",
args{config.Restore{Global: config.Global{Database: "d", Username: "u", Password: "p"}}, sqlformat.Custom},
command.NewBuilder("mongorestore", "--archive", "--host=127.0.0.1", "--username=u", "--password=p", "--db=d"),
command.NewBuilder("mongorestore", "--archive", "--host=127.0.0.1", "--username=u", "--password=p", "--authenticationDatabase=admin", "--db=d"),
},
{
"clean",
args{config.Restore{Clean: true, Global: config.Global{Database: "d", Username: "u", Password: "p"}}, sqlformat.Gzip},
command.NewBuilder("mongorestore", "--archive", "--host=127.0.0.1", "--username=u", "--password=p", "--drop", "--db=d"),
command.NewBuilder("mongorestore", "--archive", "--host=127.0.0.1", "--username=u", "--password=p", "--authenticationDatabase=admin", "--drop", "--db=d"),
},
{
"quiet",
args{config.Restore{Global: config.Global{Database: "d", Username: "u", Password: "p", Quiet: true}}, sqlformat.Gzip},
command.NewBuilder("mongorestore", "--archive", "--host=127.0.0.1", "--username=u", "--password=p", "--db=d", "--quiet"),
command.NewBuilder("mongorestore", "--archive", "--host=127.0.0.1", "--username=u", "--password=p", "--authenticationDatabase=admin", "--db=d", "--quiet"),
},
}
for _, tt := range tests {
Expand Down

0 comments on commit 4a407e6

Please sign in to comment.