This file is indexed.

/usr/share/pyshared/zope/password/tests/test_zpasswd.py is in python-zope.password 3.6.1-0ubuntu5.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
##############################################################################
#
# Copyright (c) 2004 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Tests for the zpasswd script.

$Id: test_zpasswd.py 112138 2010-05-07 15:23:02Z ulif $
"""

import os
import sys
import unittest, doctest
from StringIO import StringIO

from zope.password import password, zpasswd

class TestBase(unittest.TestCase):
    def setUp(self):
        # Create a minimal site.zcml file
        open('testsite.zcml', 'wb').write(
            '<configure xmlns="http://namespaces.zope.org/zope"/>\n'
            )
        self.stdout = StringIO()
        self.stderr = StringIO()
        self.old_stdout = sys.stdout
        self.old_stderr = sys.stderr
        sys.stdout = self.stdout
        sys.stderr = self.stderr

    def tearDown(self):
        sys.stdout = self.old_stdout
        sys.stderr = self.old_stderr
        # Clean up
        os.unlink('testsite.zcml')


class ArgumentParsingTestCase(TestBase):

    config = "testsite.zcml"

    def parse_args(self, args):
        argv = ["foo/bar.py"] + args
        options = zpasswd.parse_args(argv)
        self.assertEqual(options.program, "bar.py")
        self.assert_(options.version)
        return options

    def check_stdout_content(self, args):
        try:
            options = self.parse_args(args)
        except SystemExit, e:
            self.assertEqual(e.code, 0)
            self.assert_(self.stdout.getvalue())
            self.failIf(self.stderr.getvalue())
        else:
            self.fail("expected SystemExit")

    def test_no_arguments(self):
        options = self.parse_args([])
        self.assert_(options.managers)
        self.assert_(not options.destination)

    def test_version_long(self):
        self.check_stdout_content(["--version"])

    def test_help_long(self):
        self.check_stdout_content(["--help"])

    def test_help_short(self):
        self.check_stdout_content(["-h"])

    def test_destination_short(self):
        options = self.parse_args(["-o", "filename"])
        self.assertEqual(options.destination, "filename")

    def test_destination_long(self):
        options = self.parse_args(["--output", "filename"])
        self.assertEqual(options.destination, "filename")

    def test_config_short(self):
        options = self.parse_args(["-c", self.config])
        self.assert_(options.managers)

    def test_config_long(self):
        options = self.parse_args(["--config", self.config])
        self.assert_(options.managers)

class ControlledInputApplication(zpasswd.Application):

    def __init__(self, options, input_lines):
        super(ControlledInputApplication, self).__init__(options)
        self.__input = input_lines

    def read_input_line(self, prompt):
        return self.__input.pop(0)

    read_password = read_input_line

    def all_input_consumed(self):
        return not self.__input

class Options(object):

    config = None
    destination = None
    version = "[test-version]"
    program = "[test-program]"
    managers = password.managers

class InputCollectionTestCase(TestBase):

    def createOptions(self):
        return Options()

    def check_principal(self, expected):
        output = self.stdout.getvalue()
        self.failUnless(output)

        principal_lines = output.splitlines()[-(len(expected) + 1):-1]
        for line, expline in zip(principal_lines, expected):
            self.failUnlessEqual(line.strip(), expline)

    def test_principal_information(self):
        options = self.createOptions()
        app = ControlledInputApplication(options,
            ["id", "title", "login", "1", "passwd", "passwd", "description"])
        app.process()
        self.failUnless(not self.stderr.getvalue())
        self.failUnless(app.all_input_consumed())
        self.check_principal([
            '<principal',
            'id="id"',
            'title="title"',
            'login="login"',
            'password="passwd"',
            'description="description"',
            '/>'
            ])


def test_suite():
    suite = doctest.DocTestSuite('zope.password.zpasswd')
    suite.addTest(unittest.makeSuite(ArgumentParsingTestCase))
    suite.addTest(unittest.makeSuite(InputCollectionTestCase))
    return suite

if __name__ == '__main__':
    unittest.main(defaultTest='test_suite')