This file is indexed.

/usr/share/pyshared/apache_openid/tests/authenticators.py is in python-apache-openid 2.0.1-0ubuntu3.

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) 2009, 2010 Canonical Ltd
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import os
from unittest import TestCase

from apache_openid import get_action_path
from apache_openid.handlers.openid.authenticator import Authenticator
from apache_openid.handlers.openidteams.authenticator import TeamsAuthenticator
from apache_openid.utils.mock import ApacheMockRequest, Options, Session
from apache_openid.request import Request

__all__ = ['AuthenticatorTest', 'TeamsAuthenticatorTest']


class AuthenticatorTestCase(TestCase):

    def setUp(self):
        self.apache_request = ApacheMockRequest()
        self.overrides = {
            'authorized-teams': "canonical-isd-hackers bzr-core",
            'action-path': "/openid",
        }
        self.options = Options(self.overrides)
        self.action_path = get_action_path(self.options, self.apache_request)
        self.session = Session()
        self.request = Request(
            self.apache_request, self.action_path, self.session)


class AuthenticatorTest(AuthenticatorTestCase):

    def setUp(self):
        super(AuthenticatorTest, self).setUp()
        self.authenticator = Authenticator(self.request, self.options)

    def test_authenticate(self):
        self.assertEqual(self.authenticator.authenticate(None), False)
        self.assertEqual(
            self.authenticator.authenticate('https://login.launchpad.net/+id/1234567'),
            False)
        self.overrides['authorized-users'] = "https://login.launchpad.net/+id/1234567\n"
        self.options = Options(self.overrides)
        self.authenticator = Authenticator(self.request, self.options)
        self.assertEqual(
            self.authenticator.authenticate('https://login.launchpad.net/+id/1234567'),
            True)

    def test_authorized_urls(self):
        self.overrides['authorized-users'] = "https://login.launchpad.net/+id/abcdefg "\
            "https://login.launchpad.net/+id/gfedcba"
        self.overrides['authorized-users-list-url'] = "file://%s" % os.path.abspath(os.path.join(os.path.dirname(__file__), 'authorized-users.txt'))
        self.options = Options(self.overrides)
        self.authenticator = Authenticator(self.request, self.options)
        self.assertEqual(
            self.authenticator.authorized_urls,
            [
                'https://login.launchpad.net/+id/abcdefg',
                'https://login.launchpad.net/+id/gfedcba',
                'https://login.launchpad.net/+id/1234567',
                'https://login.launchpad.net/+id/7654321',
            ])

    def test_get_authorized_urls_from_options(self):
        self.overrides['authorized-users'] = "https://login.launchpad.net/+id/1234567 "\
            "https://login.launchpad.net/+id/7654321"
        self.options = Options(self.overrides)
        self.authenticator = Authenticator(self.request, self.options)
        self.assertEqual(
            self.authenticator.get_authorized_urls_from_options(),
            [
                'https://login.launchpad.net/+id/1234567',
                'https://login.launchpad.net/+id/7654321',
            ])

    def test_get_authorized_urls_from_url(self):
        url = "file://%s" % os.path.abspath(os.path.join(os.path.dirname(__file__), 'authorized-users.txt'))
        self.assertEqual(
            self.authenticator.get_authorized_urls_from_url(url),
            [
                'https://login.launchpad.net/+id/1234567',
                'https://login.launchpad.net/+id/7654321',
            ])

    def test_get_authorized_urls_from_url_error(self):
        url = 'http://www.non-existing-host.com/this/page/doesnt/exist/'
        self.assertEqual(
            self.authenticator.get_authorized_urls_from_url(url),
            [])

    def test_parse_authorized_urls(self):
        data = """https://login.launchpad.net/+id/1234567
#https://login.launchpad.net/+id/7654321
https://login.launchpad.net/+id/abcdefg
"""
        self.assertEqual(
            self.authenticator.parse_authorized_urls(data),
            [
                'https://login.launchpad.net/+id/1234567',
                'https://login.launchpad.net/+id/abcdefg',
            ])


class TeamsAuthenticatorTest(AuthenticatorTestCase):

    def setUp(self):
        super(TeamsAuthenticatorTest, self).setUp()
        self.session = Session()
        self.authenticator = TeamsAuthenticator(
            self.request, self.options, self.session)

    def test_check_team_entitlement(self):
        self.assertEqual(
            self.authenticator.check_team_entitlement([], []),
            False)
        self.assertEqual(
            self.authenticator.check_team_entitlement(
                ['test-team'],
                ['another-team']),
            False)
        self.assertEqual(
            self.authenticator.check_team_entitlement(
                ['test-team', 'another-team'],
                ['another-team']),
            True)

    def test_authenticate(self):
        self.assertEqual(self.authenticator.authenticate(None), False)
        self.authenticator.cookied_teams = ['ubuntumembers']
        self.assertEqual(
            self.authenticator.authenticate(
                'https://login.launchpad.net/+id/1234567'),
            False)
        self.authenticator.cookied_teams = ['bzr-core', 'motu']
        self.assertEqual(
            self.authenticator.authenticate(
                'https://login.launchpad.net/+id/1234567'),
            True)
        self.options = Options({})
        self.authenticator = TeamsAuthenticator(
            self.request, self.options, self.session)
        self.assertEqual(
            self.authenticator.authenticate(
                'https://login.launchpad.net/+id/1234567'),
            False)