Skip to content

Commit

Permalink
provider: Update initial auth tests
Browse files Browse the repository at this point in the history
Signed-off-by: Din Music <[email protected]>
  • Loading branch information
MusicDin committed Sep 20, 2024
1 parent fc659cc commit 4881b92
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions internal/provider/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ func TestAccProvider_trustToken(t *testing.T) {
token := acctest.ConfigureTrustToken(t)
configDir := t.TempDir()

invalidToken := `
ewogICJjbGllbnRfbmFtZSI6ICJ0bXBfdG9rZW4iLAogICJmaW5nZXJwcmludCI6ICJZb3VfaGF2
ZV9kZWNvZGVkX2FfdGVtcG9yYXJ5X3Rva2VuLkNvbmdyYXR1bGF0aW9ucyEiLAogICJhZGRyZXNz
ZXMiOiBbCiAgICAiMTI3LjAuMC4xOjg0NDMiCiAgXSwKICAic2VjcmV0IjogIlRoaXNfaXNfYV90
b3Bfc2VjcmV0LkRvX25vdF90ZWxsX2l0X3RvX2FueW9uZSEiLAogICJleHBpcmVzX2F0IjogIjAw
MDEtMDEtMDFUMDA6MDA6MDBaIgp9Cg==`

resource.Test(t, resource.TestCase{
PreCheck: func() {
acctest.PreCheck(t)
Expand All @@ -49,8 +56,8 @@ func TestAccProvider_trustToken(t *testing.T) {
Steps: []resource.TestStep{
{
// Ensure authentication fails with incorrect token.
Config: testAccProvider_remoteServer(configDir, "", "invalid", true),
ExpectError: regexp.MustCompile(`not authorized`),
Config: testAccProvider_remoteServer(configDir, "", invalidToken, true),
ExpectError: regexp.MustCompile(`fingerprint mismatch between certificate token`),
},
{
// Ensure authentication succeeds with correct token.
Expand Down Expand Up @@ -153,7 +160,7 @@ func TestAccProvider_generateClientCertificate(t *testing.T) {
}

func TestAccProvider_acceptRemoteCertificate(t *testing.T) {
token := acctest.ConfigureTrustToken(t)
password := acctest.ConfigureTrustPassword(t)
configDir := t.TempDir()

resource.Test(t, resource.TestCase{
Expand All @@ -165,12 +172,12 @@ func TestAccProvider_acceptRemoteCertificate(t *testing.T) {
Steps: []resource.TestStep{
{
// Ensure authentication fails if remote server is not accepted.
Config: testAccProvider_remoteServer(configDir, "", token, false),
Config: testAccProvider_remoteServer(configDir, password, "", false),
ExpectError: regexp.MustCompile(`Failed to accept server certificate`),
},
{
// Ensure authentication succeeds if remote server is accepted.
Config: testAccProvider_remoteServer(configDir, "", token, true),
Config: testAccProvider_remoteServer(configDir, password, "", true),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("lxd_noop.noop", "remote", "tf-remote"),
resource.TestCheckResourceAttr("lxd_noop.noop", "project", "default"),
Expand Down

0 comments on commit 4881b92

Please sign in to comment.