This file is indexed.

/usr/lib/python2.7/dist-packages/ubuntuone_credentials/test_new_account.py is in ubuntuone-credentials-autopilot 14.04+14.04.20140415.

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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
#
# Copyright (C) 2013-2014 Canonical Ltd.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3, as published
# by the Free Software Foundation.
#
# 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 autopilot.matchers import Eventually
from testtools.matchers import Equals, Not
from ubuntuuitoolkit import emulators as toolkit_emulators

from ubuntuone_credentials import (
    emulators,
    TestCaseWithQMLWrapper
)


class NewUbuntuOneOnlineAccountTestCase(TestCaseWithQMLWrapper):

    test_qml_wrapper_file_name = 'TestWrapperNew.qml'

    def setUp(self):
        super(NewUbuntuOneOnlineAccountTestCase, self).setUp()
        self.new_account = self.main_view.select_single(emulators.NewAccount)

    def test_loading_overlay_starts_invisible(self):
        overlay = self.main_view.select_single(objectName='loadingOverlay')
        self.assertThat(overlay.visible, Eventually(Equals(False)))

    def test_email_field_visible_focused(self):
        email_text_field = self.main_view.select_single(
            objectName='emailTextField')
        self.assertThat(email_text_field.visible, Eventually(Equals(True)))
        self.assertThat(email_text_field.focus, Eventually(Equals(True)))

    def test_login_initial_state(self):
        password_text_field = self.main_view.select_single(
            objectName='loginFormPasswordTextField')
        self.assertThat(password_text_field.visible, Eventually(Equals(True)))
        two_factor_text_field = self.main_view.select_single(
            objectName='twoFactorTextField')
        self.assertThat(
            two_factor_text_field.visible, Eventually(Equals(False)))

    def test_switch_to_new_user(self):
        new_user_switch = self.main_view.select_single(
            toolkit_emulators.CheckBox, objectName='newUserToggleSwitch')
        new_user_switch.check()

        password_text_field = self.main_view.select_single(
            objectName='loginFormPasswordTextField')
        self.assertThat(password_text_field.visible, Eventually(Equals(False)))

        name_text_field = self.main_view.select_single(
            objectName='nameTextField')
        self.assertThat(name_text_field.visible, Eventually(Equals(True)))

    def test_error_label_starts_invisible(self):
        self.assertThat(
            self.new_account.is_error_label_visible(),
            Eventually(Equals(False)))


class SimpleLogInTestCase(TestCaseWithQMLWrapper):

    test_qml_wrapper_file_name = 'TestWrapperNew.qml'

    scenarios = [
        ('success',
         dict(email='ok@te.st', password='password', success=True)),
        ('failure',
         dict(email='not-ok@te.st', password='password', success=False))]

    def setUp(self):
        # Start the fake server before launching the application.
        if (os.environ.get('SSO_AUTH_BASE_URL') == 'fake' and
                os.environ.get('SSO_UONE_BASE_URL') == 'fake'):
            self.use_fake_servers()
        super(SimpleLogInTestCase, self).setUp()

    def test_simple_login(self):
        """Test that success pops the NewAccount main page, and
        failure shows the error label.
        """
        new_account = self.main_view.select_single(emulators.NewAccount)
        new_account.log_in(email=self.email, password=self.password)
        dummyPage = self.main_view.select_single(objectName="dummyPage")
        self.assertThat(dummyPage.visible, Eventually(Equals(self.success)))
        self.assertThat(new_account.is_error_label_visible(),
                        Eventually(Equals(not self.success)))


class TwoFactorLogInTestCase(TestCaseWithQMLWrapper):

    test_qml_wrapper_file_name = 'TestWrapperNew.qml'

    scenarios = [
        ('success',
         dict(email='2fa@te.st', password='password',
              twoFactorCode='123456', success=True)),
        ('failure',
         dict(email='2fa@te.st', password='password',
              twoFactorCode='bad', success=False))
        ]

    def setUp(self):
        # Start the fake server before launching the application.
        if (os.environ.get('SSO_AUTH_BASE_URL') == 'fake' and
                os.environ.get('SSO_UONE_BASE_URL') == 'fake'):
            self.use_fake_servers()
        super(TwoFactorLogInTestCase, self).setUp()

    def test_twofactor_login(self):
        "Test that success pops the NewAccount main page."

        # Layout change workaround: Here we have to save the initial
        # globalRect of the twoFactorTextField because we know it will
        # move, but not necessarily before we are notified that the
        # visible flag is set - so we need to be able to wait for it
        # to move so that the call to enter_twofactor_code() below
        # clicks on the right text field. If we don't do this,
        # depending on the timing of those update signals,
        # enter_twofactor_code() may end up writing the code into the
        # password field, which is always at the location that the
        # hidden two-factor field starts out at.
        tfn = 'twoFactorTextField'
        two_factor_field = self.main_view.select_single(emulators.TextField,
                                                        objectName=tfn)
        saved_rect = two_factor_field.globalRect

        new_account = self.main_view.select_single(emulators.NewAccount)
        new_account.log_in(email=self.email, password=self.password)

        # Here we wait for both visible and focus, to ensure that the
        # field is ready for input, then we also wait for the rect to
        # change, so we know that autopilot will have the right
        # coordinates to click on it.
        self.assertThat(two_factor_field.visible, Eventually(Equals(True)))
        self.assertThat(two_factor_field.focus, Eventually(Equals(True)))
        self.assertThat(two_factor_field.globalRect,
                        Eventually(Not(Equals(saved_rect))))

        new_account.enter_twofactor_code(self.twoFactorCode)

        dummyPage = self.main_view.select_single(objectName="dummyPage")
        self.assertThat(dummyPage.visible, Eventually(Equals(self.success)))
        self.assertThat(new_account.is_error_label_visible(),
                        Eventually(Equals(not self.success)))


VALID_NEW_ACCOUNT = dict(email='new@te.st', name='test name',
                         password='password',
                         password_confirmation='password',
                         agree_to_terms=True,
                         success=True)


class RegisterNewU1AccountTestCase(TestCaseWithQMLWrapper):

    test_qml_wrapper_file_name = 'TestWrapperNew.qml'

    scenarios = [
        ('success', VALID_NEW_ACCOUNT),
        ('bad request', dict(VALID_NEW_ACCOUNT, email='bad-new@te.st',
                             success=False))
        ]

    def setUp(self):
        # Start the fake server before launching the application.
        if (os.environ.get('SSO_AUTH_BASE_URL') == 'fake' and
                os.environ.get('SSO_UONE_BASE_URL') == 'fake'):
            self.use_fake_servers()
        super(RegisterNewU1AccountTestCase, self).setUp()

    def test_register_new_account(self):
        "Test that registering a new account pops the main page."

        new_account = self.main_view.select_single(emulators.NewAccount)
        new_account.register_new_account(self.email, self.name, self.password,
                                         self.password_confirmation,
                                         self.agree_to_terms)

        dummyPage = self.main_view.select_single(objectName="dummyPage")
        self.assertThat(dummyPage.visible, Eventually(Equals(self.success)))
        self.assertThat(new_account.is_error_label_visible(),
                        Eventually(Equals(not self.success)))