-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use md5 hashing for redshift_user passwords
- Loading branch information
1 parent
8c558d1
commit 004a620
Showing
3 changed files
with
62 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ package redshift | |
import ( | ||
"database/sql" | ||
"fmt" | ||
"os" | ||
"strconv" | ||
"strings" | ||
"testing" | ||
|
||
|
@@ -24,6 +26,7 @@ func TestAccRedshiftUser_Basic(t *testing.T) { | |
|
||
testAccCheckRedshiftUserExists("[email protected]"), | ||
resource.TestCheckResourceAttr("redshift_user.with_email", "name", "[email protected]"), | ||
testAccCheckRedshiftUserCanLogin("[email protected]", "Foobarbaz1"), | ||
|
||
testAccCheckRedshiftUserExists("user_defaults"), | ||
resource.TestCheckResourceAttr("redshift_user.user_with_defaults", "name", "user_defaults"), | ||
|
@@ -284,3 +287,43 @@ func TestPermanentUsername(t *testing.T) { | |
t.Fatalf("permanentUsername should strip \"IAMA:\" prefix. Expected %s but was %s", expected, result) | ||
} | ||
} | ||
|
||
func testAccCheckRedshiftUserCanLogin(user string, password string) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
// there doesn't seem to be a good way to extract the provider configuration | ||
// at runtime. However we know we've configured the provider with default settings | ||
// so we can mimic the same behavior | ||
port, ok := os.LookupEnv("REDSHIFT_PORT") | ||
if !ok { | ||
port = "5439" | ||
} | ||
portNum, err := strconv.Atoi(port) | ||
if err != nil { | ||
return fmt.Errorf("Unable to check if user can login due to bad REDSHIFT_PORT: %s", err) | ||
} | ||
database, ok := os.LookupEnv("REDSHIFT_DATABASE") | ||
if !ok { | ||
database = "redshift" | ||
} | ||
sslMode, ok := os.LookupEnv("REDSHIFT_SSLMODE") | ||
if !ok { | ||
sslMode = "require" | ||
} | ||
config := &Config{ | ||
Host: os.Getenv("REDSHIFT_HOST"), | ||
Port: portNum, | ||
Username: user, | ||
Password: password, | ||
Database: database, | ||
SSLMode: sslMode, | ||
MaxConns: defaultProviderMaxOpenConnections, | ||
} | ||
|
||
client, err := config.Client() | ||
if err != nil { | ||
return fmt.Errorf("User is unable to login %s", err) | ||
} | ||
defer client.Close() | ||
return nil | ||
} | ||
} |