Skip to content

Commit

Permalink
Test a couple failure conditions attempting to rotate root user creds
Browse files Browse the repository at this point in the history
  • Loading branch information
grubchr committed May 10, 2018
1 parent 4c92496 commit f416457
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion plugin/elastic/elastic_db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func initializeDatabase(response, connURL *string) *Database {
}

mockRawconfig := make(map[string]interface{})
mockRawconfig["password"] = "abcdefg123456"
mockRawconfig["password"] = "testpassword"

return &Database{
connectionProducer: &connectionProducer{
Expand Down Expand Up @@ -247,3 +247,25 @@ func TestRotateRootCredentialsSuccess(t *testing.T) {
assert.Nil(t, err)
assert.Equal(t, db.RawConfig["password"], response["password"])
}

func TestRotateRootCredentialsFailWithoutConnectionCredentials(t *testing.T) {
res := `{}`

db := initializeDatabase(&res, nil)
db.Username = ""

_, err := db.RotateRootCredentials(testdata.NewMockVaultContext(), []string{})

assert.Equal(t, "Both the username and password are required.", err.Error())
}

func TestRotateRootCredentialsFailOnBadUsername(t *testing.T) {
res := `{}`

db := initializeDatabase(&res, nil)
db.Username = "nouser"

_, err := db.RotateRootCredentials(testdata.NewMockVaultContext(), []string{})

assert.Equal(t, "user doesn't exist", err.Error())
}

0 comments on commit f416457

Please sign in to comment.