Skip to content
This repository has been archived by the owner on Aug 7, 2023. It is now read-only.

Commit

Permalink
Fix template encoding + add test #18
Browse files Browse the repository at this point in the history
  • Loading branch information
Eduardo Lopez authored Aug 13, 2018
1 parent c01613c commit 747d2f6
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 10 deletions.
16 changes: 8 additions & 8 deletions pkg/provider/data_lambda.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package provider
import (
"archive/zip"
"bytes"
"html/template"
"io"
"io/ioutil"
"os"
"path"
"path/filepath"
"sort"
"text/template"

"github.com/chanzuckerberg/terraform-provider-bless/pkg/util"
"github.com/gobuffalo/packr"
Expand Down Expand Up @@ -189,13 +189,13 @@ func (l *resourceLambda) getBlessConfig(d *schema.ResourceData) (io.Reader, erro
return nil, errors.Wrap(err, "Could not load template")
}
blessConfig := blessConfig{
Name: d.Get(schemaServiceName).(string),
LoggingLevel: d.Get(schemaLoggingLevel).(string),
UsernameValidation: d.Get(schemaUsernameValidation).(string),
EncryptedPassword: d.Get(schemaEncryptedPassword).(string),
EncryptedPrivateKey: d.Get(schemaEncryptedPrivateKey).(string),
KMSAuthKeyID: d.Get(schemaKMSAuthKeyID).(string),
KMSAuthRemoteUsernamesAllowed: d.Get(schemaKMSAuthRemoteUsernamesAllowed).(string),
Name: d.Get(schemaServiceName).(string),
LoggingLevel: d.Get(schemaLoggingLevel).(string),
UsernameValidation: d.Get(schemaUsernameValidation).(string),
EncryptedPassword: d.Get(schemaEncryptedPassword).(string),
EncryptedPrivateKey: d.Get(schemaEncryptedPrivateKey).(string),
KMSAuthKeyID: d.Get(schemaKMSAuthKeyID).(string),
KMSAuthRemoteUsernamesAllowed: d.Get(schemaKMSAuthRemoteUsernamesAllowed).(string),
KMSAuthValidateRemoteUsernameAgainstIAMGroups: d.Get(schemaKMSAuthValidateRemoteUsernameAgainstIAMGroups).(bool),
KMSAuthIAMGroupNameFormat: d.Get(schemaKMSAuthIAMGroupNameFormat).(string),
}
Expand Down
44 changes: 42 additions & 2 deletions pkg/provider/data_lambda_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package provider_test

import (
"archive/zip"
"bufio"
"strings"
"testing"

r "github.com/hashicorp/terraform/helper/resource"
Expand All @@ -24,15 +27,15 @@ func TestLambdaCreate(t *testing.T) {
data "bless_lambda" "zip" {
encrypted_ca = "aaaa"
encrypted_password = "bbbb"
encrypted_password = "bb+bb"
service_name = "test"
kmsauth_key_id = "keyID"
output_path = "/tmp/test.zip"
}
data "bless_lambda" "zip2" {
encrypted_ca = "aaaa"
encrypted_password = "bbbb"
encrypted_password = "bb+bb"
service_name = "test"
kmsauth_key_id = "keyID"
output_path = "/tmp/test2.zip"
Expand All @@ -52,6 +55,8 @@ func TestLambdaCreate(t *testing.T) {
a.NotEmpty(output1)
a.NotEmpty(output2)
// Check hashes are equal

validateBlessConfig(t, "/tmp/test.zip")
a.Equal(output1, output2)
return nil
},
Expand Down Expand Up @@ -102,3 +107,38 @@ func TestLambdaCreate(t *testing.T) {
},
})
}

func validateBlessConfig(t *testing.T, zipPath string) {
a := assert.New(t)

r, err := zip.OpenReader(zipPath)
a.Nil(err)
defer r.Close()

configFound := false
privateKeyFound := false

for _, f := range r.File {
if f.Name != "bless_deploy.cfg" {
continue
}
configFound = true
fc, err := f.Open()
a.Nil(err)
defer fc.Close()
scanner := bufio.NewScanner(fc)

for scanner.Scan() {
if strings.Contains(scanner.Text(), "bb+bb") {
privateKeyFound = true
break
}
}
a.Nil(scanner.Err())

break // Found the config file
}

a.True(configFound)
a.True(privateKeyFound)
}

0 comments on commit 747d2f6

Please sign in to comment.