-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
It iso now possible to define a command that is executed in order to optain the password. This is useful in situations, where your database is manged by a cloud provider and you are using the cloud providers IAM solution to gain the password. Fixes #154
- Loading branch information
1 parent
eb695ac
commit 28081b7
Showing
11 changed files
with
166 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package database | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
) | ||
|
||
func TestResolvePassword(t *testing.T) { | ||
type testCase struct { | ||
title string | ||
dbConfig DBConfig | ||
want string | ||
wantErr bool | ||
} | ||
|
||
testCases := []testCase{ | ||
{ | ||
title: "only password", | ||
dbConfig: DBConfig{ | ||
Passwd: "test", | ||
}, | ||
want: "test", | ||
}, | ||
{ | ||
title: "only command", | ||
dbConfig: DBConfig{ | ||
PasswdCmd: []string{"echo", "-n", "secure"}, | ||
}, | ||
want: "secure", | ||
}, | ||
{ | ||
title: "password and command", | ||
dbConfig: DBConfig{ | ||
Passwd: "test", | ||
PasswdCmd: []string{"echo", "-n", "secure"}, | ||
}, | ||
want: "secure", | ||
}, | ||
{ | ||
title: "failing command", | ||
dbConfig: DBConfig{ | ||
Passwd: "test", | ||
PasswdCmd: []string{"false"}, | ||
}, | ||
wantErr: true, | ||
}, | ||
} | ||
|
||
for _, tt := range testCases { | ||
t.Run(tt.title, func(t *testing.T) { | ||
got, err := tt.dbConfig.ResolvePassword() | ||
if err != nil { | ||
if !tt.wantErr { | ||
t.Errorf("ResolvePassword() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
} | ||
if diff := cmp.Diff(tt.want, got); diff != "" { | ||
t.Errorf("unmatch (- want, + got):\n%s", diff) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters