~ubuntu-branches/ubuntu/lucid/puppet/lucid-security

« back to all changes in this revision

Viewing changes to spec/unit/parser/functions/shellquote.rb

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2009-12-23 00:48:10 UTC
  • mfrom: (1.1.10 upstream) (3.1.7 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091223004810-3i4oryds922g5n59
Tags: 0.25.1-3ubuntu1
* Merge from debian testing.  Remaining changes:
  - debian/rules:
    + Don't start puppet when first installing puppet.
  - debian/puppet.conf, lib/puppet/defaults.rb:
    + Move templates to /etc/puppet
  - lib/puppet/defaults.rb:
    + Fix /var/lib/puppet/state ownership.
  - man/man8/puppet.conf.8: 
    + Fix broken URL in manpage.
  - debian/control:
    + Update maintainer accordint to spec.
    + Puppetmaster Recommends -> Suggests
    + Created puppet-testsuite as a seperate. Allow the users to run puppet's 
      testsuite.
  - tests/Rakefile: Fix rakefile so that the testsuite can acutally be ran.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/bin/env ruby
 
2
 
 
3
require File.dirname(__FILE__) + '/../../../spec_helper'
 
4
 
 
5
describe "the shellquote function" do
 
6
 
 
7
    before :each do
 
8
        @scope = Puppet::Parser::Scope.new()
 
9
    end
 
10
 
 
11
    it "should exist" do
 
12
        Puppet::Parser::Functions.function("shellquote").should == "function_shellquote"
 
13
    end
 
14
 
 
15
 
 
16
    it "should handle no arguments" do
 
17
        result = @scope.function_shellquote([])
 
18
        result.should(eql(""))
 
19
    end
 
20
 
 
21
    it "should handle several simple arguments" do
 
22
        result = @scope.function_shellquote(
 
23
            ['foo', 'bar@example.com', 'localhost:/dev/null', 'xyzzy+-4711,23'])
 
24
        result.should(eql(
 
25
            'foo bar@example.com localhost:/dev/null xyzzy+-4711,23'))
 
26
    end
 
27
 
 
28
    it "should handle array arguments" do
 
29
        result = @scope.function_shellquote(
 
30
            ['foo', ['bar@example.com', 'localhost:/dev/null'],
 
31
             'xyzzy+-4711,23'])
 
32
        result.should(eql(
 
33
            'foo bar@example.com localhost:/dev/null xyzzy+-4711,23'))
 
34
    end
 
35
 
 
36
    it "should quote unsafe characters" do
 
37
        result = @scope.function_shellquote(
 
38
            ['/etc/passwd ', '(ls)', '*', '[?]', "'&'"])
 
39
        result.should(eql(
 
40
            '"/etc/passwd " "(ls)" "*" "[?]" "\'&\'"'))
 
41
    end
 
42
 
 
43
    it "should deal with double quotes" do
 
44
        result = @scope.function_shellquote(
 
45
           ['"foo"bar"'])
 
46
        result.should(eql(
 
47
            '\'"foo"bar"\''))
 
48
    end
 
49
 
 
50
    it "should cope with dollar signs" do
 
51
        result = @scope.function_shellquote(
 
52
           ['$PATH', 'foo$bar', '"x$"'])
 
53
        result.should(eql(
 
54
            "'$PATH' 'foo$bar' '\"x$\"'"))
 
55
    end
 
56
 
 
57
    it "should deal with apostrophes (single quotes)" do
 
58
        result = @scope.function_shellquote(
 
59
           ["'foo'bar'", "`$'EDITOR'`"])
 
60
        result.should(eql(
 
61
            '"\'foo\'bar\'" "\\`\\$\'EDITOR\'\\`"'))
 
62
    end
 
63
 
 
64
    it "should cope with grave accents (backquotes)" do
 
65
        result = @scope.function_shellquote(
 
66
           ['`echo *`', '`ls "$MAILPATH"`'])
 
67
        result.should(eql(
 
68
            "'`echo *`' '`ls \"$MAILPATH\"`'"))
 
69
    end
 
70
 
 
71
    it "should deal with both single and double quotes" do
 
72
        result = @scope.function_shellquote(
 
73
           ['\'foo"bar"xyzzy\'', '"foo\'bar\'xyzzy"'])
 
74
        result.should(eql(
 
75
            '"\'foo\\"bar\\"xyzzy\'" "\\"foo\'bar\'xyzzy\\""'))
 
76
    end
 
77
 
 
78
    it "should handle multiple quotes *and* dollars and backquotes" do
 
79
        result = @scope.function_shellquote(
 
80
           ['\'foo"$x`bar`"xyzzy\''])
 
81
        result.should(eql(
 
82
            '"\'foo\\"\\$x\\`bar\\`\\"xyzzy\'"'))
 
83
    end
 
84
 
 
85
    it "should handle linefeeds" do
 
86
        result = @scope.function_shellquote(
 
87
           ["foo \n bar"])
 
88
        result.should(eql(
 
89
            "\"foo \n bar\""))
 
90
    end
 
91
 
 
92
end