-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from coveooss/add-bcrypt
Add new bcrypt output to quantum password
- Loading branch information
Showing
6 changed files
with
543 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,5 @@ terraform-provider-quantum | |
|
||
main.tf | ||
crash.log | ||
|
||
*.code-workspace |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
language: go | ||
go: | ||
- 1.9.x | ||
- 1.13.x | ||
|
||
sudo: false | ||
|
||
|
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,10 @@ | ||
module github.com/coveo/terraform-provider-quantum | ||
|
||
go 1.13 | ||
|
||
require ( | ||
github.com/hashicorp/terraform v0.12.18 | ||
github.com/tidwall/gjson v1.1.2 | ||
github.com/tidwall/match v1.0.0 | ||
golang.org/x/crypto v0.0.0-20191206172530-e9b2fee46413 | ||
) |
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,82 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/resource" | ||
"github.com/hashicorp/terraform/terraform" | ||
|
||
"golang.org/x/crypto/bcrypt" | ||
) | ||
|
||
func testQuantumPasswordBasic(t *testing.T) { | ||
passwordRegex12 := regexp.MustCompile(`^.{12}$`) | ||
passwordRegex10 := regexp.MustCompile(`^.{10}$`) | ||
bcryptRegex := regexp.MustCompile(`^\$2[ayb]\$.{56}$`) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccQuantumPasswordResource(12), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestMatchResourceAttr( | ||
"quantum_password.test", | ||
"password", | ||
passwordRegex12, | ||
), | ||
resource.TestMatchResourceAttr( | ||
"quantum_password.test", | ||
"bcrypt", | ||
bcryptRegex, | ||
), | ||
testAccQuantumPasswordBcrypt("quantum_password.test"), | ||
), | ||
}, | ||
// Force a rotation of password | ||
{ | ||
Config: testAccQuantumPasswordResource(10), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestMatchResourceAttr( | ||
"quantum_password.test", | ||
"password", | ||
passwordRegex10, | ||
), | ||
resource.TestMatchResourceAttr( | ||
"quantum_password.test", | ||
"bcrypt", | ||
bcryptRegex, | ||
), | ||
testAccQuantumPasswordBcrypt("quantum_password.test"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccQuantumPasswordResource(length int) string { | ||
return fmt.Sprintf(` | ||
resource "quantum_password" "test" { | ||
special_chars = "" | ||
length = %d | ||
} | ||
`, length) | ||
} | ||
|
||
func testAccQuantumPasswordBcrypt(resourceName string) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
// retrieve the resource by name from state | ||
rs, ok := s.RootModule().Resources[resourceName] | ||
if !ok { | ||
return fmt.Errorf("Not found: %s", resourceName) | ||
} | ||
|
||
err := bcrypt.CompareHashAndPassword([]byte(rs.Primary.Attributes["bcrypt"]), []byte(rs.Primary.Attributes["password"])) | ||
if err != nil { | ||
return fmt.Errorf("Bcrypt does not match: %s (%s)", resourceName, err) | ||
} | ||
|
||
return nil | ||
} | ||
} |