Exemplo n.º 1
0
class TestSecretTemplateArgs(unittest.TestCase):

    def setUp(self):
        self.ps = String()
        self.ps.add_secret('hello')

        class DummyResource:
            template_args = {}

        self.args = DummyResource.template_args
        self.provider = files.File(DummyResource)

    def test_no_secret(self):
        self.args['level1'] = dict(foo=1, bar=[1,2,3], baz=dict())
        self.failUnless(not self.provider.has_protected_strings())

    def test_secret_in_dict(self):
        self.args['level1'] = dict(foo=self.ps, bar=1)
        self.failUnless(self.provider.has_protected_strings())

    def test_secret_in_list(self):
        self.args['level1'] = [self.ps, 1, 2]
        self.failUnless(self.provider.has_protected_strings())

    def test_secret_in_dict_in_list(self):
        self.args['level1'] = [dict(foo=self.ps, bar=1)]
        self.failUnless(self.provider.has_protected_strings())
Exemplo n.º 2
0
    def test_normal_string(self):
        a = String(["Just a normal string"])

        self.failUnlessEqual(unicode(a), "Just a normal string")
        self.failUnlessEqual(a.unprotected, "Just a normal string")

        self.failUnlessEqual(a.as_list(secret=True), ["Just a normal string"])
        self.failUnlessEqual(a.as_list(secret=False), ["Just a normal string"])
Exemplo n.º 3
0
    def test_normal_string(self):
        a = String(["Just a normal string"])

        self.failUnlessEqual(unicode(a), "Just a normal string")
        self.failUnlessEqual(a.unprotected, "Just a normal string")

        self.failUnlessEqual(a.as_list(secret=True), ["Just a normal string"])
        self.failUnlessEqual(a.as_list(secret=False), ["Just a normal string"])
Exemplo n.º 4
0
    def resolve(self):
        r = self.value.resolve()

        if not isinstance(r, basestring):
           self.error("Only simple strings can be marked with .secret at this time. Perhaps you want to look in to .yay.gpg files?")

        p = String()
        p.add_secret(r)
        return p
Exemplo n.º 5
0
    def resolve(self):
        r = self.value.resolve()

        if not isinstance(r, basestring):
            self.error(
                "Only simple strings can be marked with .secret at this time. Perhaps you want to look in to .yay.gpg files?"
            )

        p = String()
        p.add_secret(r)
        return p
Exemplo n.º 6
0
    def setUp(self):
        self.ps = String()
        self.ps.add_secret('hello')

        class DummyResource:
            template_args = {}

        self.args = DummyResource.template_args
        self.provider = files.File(DummyResource)
Exemplo n.º 7
0
    def resolve(self):
        """
        If any of the nodes that are being concatenated are protected (because
        Yay knows they were loaded from .yay.gpg) then this will return an
        :py:class:`~yay.String` object.

        If none of the nodes  are then it will return a string.
        """
        resolved = [x.resolve() for x in self.args]

        protected = False
        for x in resolved:
            if isinstance(x, String):
                protected = True

        if protected:
            p = String()
            for x in resolved:
                p.add(x)
            return p

        return "".join(str(x) for x in resolved)
Exemplo n.º 8
0
    def resolve(self):
        """
        If any of the nodes that are being concatenated are protected (because
        Yay knows they were loaded from .yay.gpg) then this will return an
        :py:class:`~yay.String` object.

        If none of the nodes  are then it will return a string.
        """
        resolved = [x.resolve() for x in self.args]

        protected = False
        for x in resolved:
            if isinstance(x, String):
                protected = True

        if protected:
            p = String()
            for x in resolved:
                p.add(x)
            return p

        return "".join(str(x) for x in resolved)
Exemplo n.º 9
0
    def resolve(self):
        """
        Boxed will do some simple and automatic processing of data when it
        resolves.

          * If it isn't a subclass of basestring it will be returned as is
          * `yes`, `true` and `on` will become python True
          * `no`, `false` and `off` will become python False
          * If it can be cast to an ``int`` it will be.
          * If it can be represented in ascii it will be
          * Otherwise a unicode string is returned
        """
        value = self.value

        if not isinstance(value, basestring):
            return value

        if self.secret:
            p = String()
            p.add_secret(value)
            return p

        if value.lower() in ("yes", "true", "on"):
            return True
        if value.lower() in ("no", "false", "off"):
            return False

        try:
            return int(value)
        except ValueError:
            pass

        #FIXME: could still be a float or a timestamp

        try:
            return value.encode('ascii')
        except UnicodeEncodeError:
            return value
Exemplo n.º 10
0
Arquivo: boxed.py Projeto: marchon/yay
    def resolve(self):
        """
        Boxed will do some simple and automatic processing of data when it
        resolves.

          * If it isn't a subclass of basestring it will be returned as is
          * `yes`, `true` and `on` will become python True
          * `no`, `false` and `off` will become python False
          * If it can be cast to an ``int`` it will be.
          * If it can be represented in ascii it will be
          * Otherwise a unicode string is returned
        """
        value = self.value

        if not isinstance(value, basestring):
            return value

        if self.secret:
            p = String()
            p.add_secret(value)
            return p

        if value.lower() in ("yes", "true", "on"):
            return True
        if value.lower() in ("no", "false", "off"):
            return False

        try:
            return int(value)
        except ValueError:
            pass

        #FIXME: could still be a float or a timestamp

        try:
            return value.encode('ascii')
        except UnicodeEncodeError:
            return value
Exemplo n.º 11
0
    def test_partially_secret(self):
        a = "adduser -u fred -p "
        b = String()
        b.add_secret("password")
        c = " -h /home/fred"
        d = String([a, b, c])

        self.failUnlessEqual(unicode(d),
                             "adduser -u fred -p ***** -h /home/fred")
        self.failUnlessEqual(d.unprotected,
                             "adduser -u fred -p password -h /home/fred")

        self.failUnlessEqual(
            d.as_list(secret=True),
            ["adduser -u fred -p ", "*****", " -h /home/fred"])
        self.failUnlessEqual(
            d.as_list(secret=False),
            ["adduser -u fred -p ", "password", " -h /home/fred"])
Exemplo n.º 12
0
    def test_partially_secret(self):
        a = "adduser -u fred -p "
        b = String()
        b.add_secret("password")
        c = " -h /home/fred"
        d = String([a,b,c])

        self.failUnlessEqual(unicode(d), "adduser -u fred -p ***** -h /home/fred")
        self.failUnlessEqual(d.unprotected, "adduser -u fred -p password -h /home/fred")

        self.failUnlessEqual(d.as_list(secret=True), ["adduser -u fred -p ", "*****", " -h /home/fred"])
        self.failUnlessEqual(d.as_list(secret=False), ["adduser -u fred -p ", "password", " -h /home/fred"])