Skip to content

Commit

Permalink
Merge pull request #42 from asteris-llc/fix/template-0600
Browse files Browse the repository at this point in the history
resource(template): fix permissions
  • Loading branch information
BrianHicks committed Jun 6, 2016
2 parents cac9121 + bad701f commit 4b34b5f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion resource/template.go
Expand Up @@ -70,7 +70,7 @@ func (t *Template) Check() (string, bool, error) {
func (t *Template) Apply() (string, bool, error) {
dest := t.Destination()
content := t.Content()
err := ioutil.WriteFile(dest, []byte(content), 0755)
err := ioutil.WriteFile(dest, []byte(content), 0600)
if err != nil {
return "", false, err
}
Expand Down
26 changes: 26 additions & 0 deletions resource/template_test.go
Expand Up @@ -150,3 +150,29 @@ func TestTemplateApply(t *testing.T) {
assert.Equal(t, "1", string(content))
assert.NoError(t, err)
}

func TestTemplateApplyPermission(t *testing.T) {
t.Parallel()

tmpfile, err := ioutil.TempFile("", "test-template-apply-permission")
require.NoError(t, err)
defer func() { require.NoError(t, os.Remove(tmpfile.Name())) }()

tmpl := resource.Template{
RawDestination: tmpfile.Name(),
RawContent: "{{1}}",
}
assert.NoError(t, tmpl.Prepare(&resource.Module{}))
assert.NoError(t, tmpl.Validate())

_, success, err := tmpl.Apply()
assert.True(t, success)
assert.NoError(t, err)

// stat the new file
stat, err := os.Stat(tmpfile.Name())
assert.NoError(t, err)

perm := stat.Mode().Perm()
assert.Equal(t, os.FileMode(0600), perm)
}

0 comments on commit 4b34b5f

Please sign in to comment.