Exemplo n.º 1
0
def rename_device(name, new_name):
    click_link(get_element(tag='a', text_regex='Rename'))
    # find name textfield
    elem = get_element(tag='input', name='name', value=name)
    # and update it
    write_textfield(elem, new_name)
    # and submit the form
    click_button(get_element(tag='button', text='Rename'))
Exemplo n.º 2
0
def get_device_preferences_elements():
    go_to(urls.EDIT)
    always_radio = get_element(tag="input", name="twofactor_required",
                               value="True")
    as_needed_radio = get_element(tag="input", name="twofactor_required",
                                  value="False")
    warn_backup_checkbox = get_element(tag="input",
                                       name="warn_about_backup_device")
    return always_radio, as_needed_radio, warn_backup_checkbox
Exemplo n.º 3
0
def fill_user_form(user, version=None):
    monkey_patch_sst()

    keys = user.keys()
    # for 1.8 and possibly lower, country needs to be filled before region_id
    # is a dropdown
    keys.sort()

    for key in keys:
        (vtype, value) = user[key]
        print 'fill', key, vtype, value
        try:
            el = a.get_element(id=key)
        except AssertionError:
            continue

        # before 1.9 region was a text field
        #if version < (1, 9, 0, 0) and key == 'region_id':
        #    el = a.get_element(id='region')
        #    a.write_textfield(el, value)
        if vtype == 'text':
            a.write_textfield(el, value)
        elif vtype == 'password':
            a.write_textfield(el, value, check=False)
        elif vtype == 'option':
            a.wait_for(a.assert_displayed, el)
            a.set_dropdown_value(el, value)
Exemplo n.º 4
0
 def test_YUI3_unit_tests(self):
     # Load the page and then wait for #suite to contain
     # 'done'.  Read the results in '#test_results'.
     go_to(self.test_url)
     wait_for(assert_text, 'suite', 'done')
     results = json.loads(get_element(id='test_results').text)
     if results['failed'] != 0:
         message = '%d test(s) failed.\n\n%s' % (
             results['failed'], yui3.get_failed_tests_message(results))
         self.fail(message)
Exemplo n.º 5
0
def add_device(name='My device'):
    # Go to the authentication devices page
    go_to(urls.DEVICES)
    # Click on "Add a new authentication device" link
    click_add_new_device_link()
    # Choose "Generic HOTP device" and click add device
    set_radio_value('type_generic')
    click_add_device_button()

    # Add correctly generated OTP key
    aes_key = get_element(name='hex_key').get_attribute('value')
    valid_otp = hotp.hotp(aes_key, 0)
    write_textfield(get_element(tag='input', name='otp'), valid_otp)
    # Add a name
    write_textfield(get_element(tag='input', name='name'), name)
    # Click "Add device"
    click_add_device_button()
    store_device(name, aes_key)
    return aes_key
Exemplo n.º 6
0
 def test_YUI3_unit_tests(self):
     # Load the page and then wait for #suite to contain
     # 'done'.  Read the results in '#test_results'.
     go_to(self.test_url)
     wait_for(assert_text, 'suite', 'done')
     results = json.loads(get_element(id='test_results').text)
     if results['failed'] != 0:
         message = '%d test(s) failed.\n\n%s' % (
             results['failed'], yui3.get_failed_tests_message(results))
         self.fail(message)
Exemplo n.º 7
0
def _get_paper_device_codes(counter):
    url = get_current_url()
    restore = False
    if not re.match(r'.*/device-print/\d+$', url):
        assert_url('/device-list')
        click_link(get_element(tag='a', text='View Codes'))
        restore = True

    codes = [e.text for e in
             get_elements_by_css('ol.codelist li')][counter:]
    if restore:
        go_to('/device-list')
    return codes
Exemplo n.º 8
0
def authenticate(name=None):
    cache = _get_device_cache()
    if name is None:
        # Just pick the first device we find
        name = cache.keys()[0]
    device = cache[name]

    if device.codes is None:
        otp = hotp.hotp(device.aes_key, device.counter)
        device.counter += 1
    else:
        otp = device.codes.pop(0)

    write_textfield('id_oath_token', otp)
    click_button(get_element(type='submit'))
Exemplo n.º 9
0
def delete_device():
    go_to(urls.DEVICES)
    # Fetch the name of the device we will be deleting
    name = get_elements_by_css('#device-list td.name')[0].text
    # Click on the delete button
    click_delete_button()

    # if we need to 2F auth this action
    if exists_element(id='id_oath_token'):
        authenticate()

    # Click on ok
    click_button(get_element(tag='button', text='Delete this device'))
    remove_device(name)

    # Check we are back on the device-list page
    assert_url('/device-list')
    # Check that our device has been deleted
    fails(get_element, 'device-list')
Exemplo n.º 10
0
    def register(self):
        if self._version >= (1, 9, 0, 0):
            self._account_menu_1_9('Register')
        else:
            a.click_link(a.get_element(text='My Account'))
            button = a.get_element_by_xpath(
                "//button[@title='Create an Account']")
            a.click_button(button)


        # fill in data for mary and register
        fill_user_form(self._data, version=self._version)

        if self._version >= (1, 9, 0, 0):
            title = 'Register'
        else:
            title = 'Submit'
        button = a.get_element_by_xpath("//button[@title='%s']" % title)
        a.click_button(button)
Exemplo n.º 11
0
    def login(self):
        if self._version >= (1, 9, 0, 0):
            self._account_menu_1_9('Log In')
        else:
            a.click_link(a.get_element(text='Log In'))

        # fill in data on login screen
        data = {
            'email': self._data['email_address'],
            'pass': self._data['password'],
        }
        fill_user_form(data, version=self._version)

        button = a.get_element_by_xpath("//button[@title='Login']")
        a.click_button(button)

        e = a.get_element_by_xpath("//p[@class='welcome-msg']")
        assert e.text.upper() == u'WELCOME, MARY BERNARD!', \
            "Login failed: %r" % e.text
Exemplo n.º 12
0
def get_key_from_qrcode(email):
    img = get_element(tag='img', css_class='qrcode')
    src = img.get_attribute('src')

    # check the url is well formed
    url = urlparse(src)
    assert url.scheme == 'https', "incorrect google charts protocol"
    msg = "incorrect google charts domain"
    assert url.netloc == 'chart.googleapis.com', msg
    qs = parse_qs(url.query)['chl'][0]
    otpauth = urlparse(qs)
    assert email in otpauth.path
    # python2.7.3 on quantal has a backport from 2.7 trunk (presumably will be
    # 2.7.4) and now urlparse correctly handles query string on *all* url types
    if otpauth.query:
        # urlparse has handled query string
        query = otpauth.query
    else:
        # we need to handle query string parsing
        query = otpauth.path.split('?')[1]
    b32_key = parse_qs(query)['secret'][0]
    aes_key = b32decode(b32_key).encode('hex')
    return aes_key
Exemplo n.º 13
0
from u1testutils import mail
from u1testutils.sso import mail as sso_mail
from u1testutils.sst import config

from acceptance import helpers, urls


config.set_base_url_from_env()

go_to(urls.NEW_ACCOUNT)
assert_title('Create account')

email_address = mail.make_unique_test_email_address()
helpers.fill_registration_form(email_address)

click_button(get_element(name='continue'))

if 'allow_unverified' not in sst_config.flags:
    assert_title_contains('Account creation mail sent')
    assert_text_contains(
        get_element(id='content'),
        r'just emailed .* \(from .*\) to confirm your address\.',
        regex=True)

    vcode = sso_mail.get_verification_code_for_address(email_address)

    write_textfield(get_element(name='confirmation_code'), vcode)
    click_button(get_element(css_class='btn'))

# We know that the confirmation code worked if we are now looking at the
# logged-in details page for the user.
Exemplo n.º 14
0
from u1testutils.sso import mail as sso_mail
from u1testutils.sst import config

from acceptance import helpers, urls


if 'allow_unverified' in sst_config.flags:
    skip("allow_unverified makes this test irrelevant")

config.set_base_url_from_env()
go_to(urls.NEW_ACCOUNT)
assert_title('Create account')

email_address = mail.make_unique_test_email_address()
helpers.fill_registration_form(email_address)
click_button(get_element(name='continue'))

assert_title_contains('Account creation mail sent')
assert_text_contains(get_element(id='content'),
                     r'just emailed .* \(from .*\) to confirm your address\.',
                     regex=True)

vcode = sso_mail.get_verification_code_for_address(email_address)


# regression check for #920105
# check we cannot submit an empty code
click_button(get_element(css_class='btn'))
# we should not have moved pages
assert_title_contains('Account creation mail sent')
Exemplo n.º 15
0
from u1testutils import mail
from u1testutils.sst import config

from acceptance import helpers, urls


config.set_base_url_from_env()

# Create an account with multiple emails.
email_address = helpers.register_account(displayname="Fred Jones", verify=True)
other_email_address = mail.make_unique_test_email_address()
helpers.add_email(other_email_address, verify=True)
edit_account_anchor = {'data-qa-id': 'edit_account'}

# Verify the current preferred email and change it.
go_to(urls.EDIT)
assert_element(**edit_account_anchor)
assert_dropdown_value('id_preferred_email', email_address)
set_dropdown_value('id_preferred_email', other_email_address)
click_button(get_element(name='update'))

# Verify that it was changed (we re-load the page to be sure it's not
# some unexpected validation error):
go_to(urls.EDIT)
assert_element(**edit_account_anchor)
assert_dropdown_value('id_preferred_email', other_email_address)

# XXX Julien would also like this test to trigger an email being sent so
# we can verify that the email is actually sent to the preferred
# address.
Exemplo n.º 16
0
# confirm device renamed
assert_device('rename_device_new')
assert_no_device(name)

# sad paths

# rename escapes content
name = '<script>alert("rename_device");</script>'
rename_device('rename_device_new', name)
assert_device(name)
assert_no_device('rename_device_new')

# try to rename to empty string
rename_device(name, '')
# rename should have failed
assert_url_contains('/device-rename/\d+', regex=True)
# check error message
assert_text('name-error', 'This field is required.')
# cancel and go back
click_link(get_element(tag='a', text_regex='[cC]ancel'))

# spaces get trimmed
rename_device(name, ' ')
# rename should have failed
assert_url_contains('/device-rename/\d+', regex=True)
# check error message
wait_for(assert_text, 'name-error',
         'The name must contain at least one non-whitespace character.')
# cancel and go back
click_link(get_element(tag='a', text_regex='[cC]ancel'))
Exemplo n.º 17
0
def click_add_device_button():
    click_button(get_element(tag='button', text_regex='Add device'))
Exemplo n.º 18
0
# XXX: skip if staging until the test can be made to reliably pass
if is_staging():
    skip()

toggled_elements = ast.literal_eval(toggled_elements)
disabled_elements = ast.literal_eval(disabled_elements)
returned_sreg = ast.literal_eval(returned_sreg)

go_to(urls.CONSUMER)
wait_for(assert_title, 'Django OpenID Example Consumer')
toggle_checkbox('id_sreg')
set_radio_value(radio_nickname)
set_radio_value(radio_fullname)
set_radio_value(radio_email)
set_radio_value(radio_language)
click_button(get_element(value='Begin'))

wait_for(assert_title, 'Log in')
write_textfield('id_email', settings.SSO_TEST_ACCOUNT_EMAIL)
write_textfield('id_password', settings.SSO_TEST_ACCOUNT_PASSWORD)
click_button(get_element_by_css('*[data-qa-id="ubuntu_login_button"]'))

wait_for(assert_title_contains, 'Authenticate to')
# Check the elements specified in the .csv list
if toggled_elements is not None:
    for optional_sreg_element in toggled_elements:
        toggle_checkbox(optional_sreg_element)
if disabled_elements is not None:
    for required_sreg_element in disabled_elements:
        assert_element(id=required_sreg_element, disabled="disabled")
click_button(get_element(name='yes'))
Exemplo n.º 19
0
from u1testutils.sst import config

from acceptance import helpers, urls

from identityprovider.utils import get_current_brand


if get_current_brand() == 'ubuntuone':
    skip(
        'The ubuntuone brand does client side validation'
    )

config.set_base_url_from_env()

# Create and verify account A
helpers.register_account()

# Add and verify 2nd email
go_to(urls.EMAILS)
wait_for(assert_title_contains, "'s email addresses")
write_textfield('id_newemail', address)
click_button(get_element(name='continue'))

# Check the outcome
if valid:
    wait_for(assert_title, 'Validate your email address')
    mail.delete_msgs_sent_to(address)
else:
    wait_for(assert_title, 'Add an email')
    assert_text_contains(get_element(name='newemailform'), 'Invalid email.')
Exemplo n.º 20
0
 def logout(self):
     a.click_link(a.get_element(text='Log Out'))
Exemplo n.º 21
0
def _set_twofactor(required):
    go_to(urls.EDIT)
    set_radio_value(get_element(tag="input", name="twofactor_required",
                                value=required))
    click_button(get_update_preferences_button())
Exemplo n.º 22
0
config.set_base_url_from_env()

helpers.skip_unless_staging_or_production()

# We use the base URL to switch the LP version of SSO here
#   Will work for Staging/Production/VPS etc
base_url = get_base_url()
lp_base_url = base_url.replace('ubuntu.com', 'launchpad.net')
set_base_url(lp_base_url)

# Goes to LP skinned version of SSO to login then,
#   uses the logout button to logout
go_to(urls.HOME)
write_textfield('id_email', settings.SSO_TEST_ACCOUNT_EMAIL)
write_textfield('id_password', settings.SSO_TEST_ACCOUNT_PASSWORD)
click_button(get_element(name='continue'))
click_button(get_element(name='logout'))
assert_element(href="/+login")
go_to(urls.HOME)
assert_title('Log in')

# Goes to LP skinned version of SSO to login then,
#   uses the /+logout URL to logout
write_textfield('id_email', settings.SSO_TEST_ACCOUNT_EMAIL)
write_textfield('id_password', settings.SSO_TEST_ACCOUNT_PASSWORD)
click_button(get_element(name='continue'))
go_to(urls.LOGOUT)
assert_element(href="/+login")
go_to(urls.HOME)
assert_title('Log in')
Exemplo n.º 23
0
def enter_otp(otp):
    write_textfield('id_oath_token', otp)
    click_button(get_element(type='submit'))
Exemplo n.º 24
0
email_address = mail.make_unique_test_email_address()
account_password = '******'

go_to(urls.NEW_ACCOUNT)
assert_title('Create account')
helpers.register_account(email_address, password=account_password)

wait_for(assert_element, **{'data-qa-id': 'edit_account'})

# Depending whether we're on Production or Staging different tests
if get_base_url() == 'https://login.ubuntu.com':   # Production
    # shop
    go_to('http://shop.canonical.com')
    wait_for(assert_title, 'Canonical Store')
    click_link(get_element(href="https://shop.canonical.com/login.php"))
    wait_for(get_element, id='id_email')
    write_textfield('id_email', email_address)
    write_textfield('id_password', account_password)
    click_button(get_element(name='continue'))
    click_button(get_element(name='yes'))
    wait_for(get_element, name='email_address')
    assert_element(value=email_address)

    # launchpad
    go_to('https://launchpad.net/~canonical-isd-hackers/+archive/internal-qa/'
          '+index')
    click_button(get_element(name='yes'))
    assert_element(tag='h1', text='Not allowed here')

    # wiki
Exemplo n.º 25
0
def get_warn_about_backup_device_checkbox():
    return get_element(tag='input', type='checkbox',
                       name='warn_about_backup_device')
Exemplo n.º 26
0
)
from u1testutils.sst import config

from acceptance.helpers import logout, production_only

config.set_base_url_from_env()

# Some external sites have extraordinary wait times
set_wait_timeout(20)

# Check whether we're on Production or not
production_only()

# Ubuntu One
go_to('http://ubuntuone.com')
click_link(get_element(text="Log in or Sign up"))
write_textfield('id_email', settings.SSO_TEST_ACCOUNT_EMAIL)
write_textfield('id_password', settings.SSO_TEST_ACCOUNT_PASSWORD)
click_button(get_element(name='continue'))
assert_element(tag='span', text='Welcome ISD Test')
logout()

# Payment system
go_to('https://pay.ubuntu.com/')
click_link(get_element(text="Log in or Register"))
wait_for(assert_title, 'Log in')
write_textfield('id_email', settings.SSO_TEST_ACCOUNT_EMAIL)
write_textfield('id_password', settings.SSO_TEST_ACCOUNT_PASSWORD)
click_button(get_element(name='continue'))
assert_element(tag='h1', text='Your payment history')
logout()
Exemplo n.º 27
0
    get_element,
    go_to,
)
from u1testutils import mail
from u1testutils.sst import config

from acceptance import helpers, urls

from identityprovider.utils import get_current_brand


EMAIL = mail.make_unique_test_email_address()
NAME = 'Some Name'

config.set_base_url_from_env()
go_to(urls.NEW_ACCOUNT)
assert_title('Create account')
helpers.fill_registration_form(EMAIL, displayname=NAME, password=password)
click_button(get_element(name='continue'))

assert_url(urls.NEW_ACCOUNT)
assert_text('id_displayname', NAME)
assert_text('id_email', EMAIL)

if get_current_brand() == 'ubuntuone':
    msg = 'Password with at least 8 characters'
    assert_attribute('id_password', 'placeholder', msg)
else:
    msg = 'Password must be at least 8 characters long.'
    assert_text(get_element(css_class='formHelp'), msg)
Exemplo n.º 28
0
 def logout(self):
     if self._version >= (1, 9, 0, 0):
         self._account_menu_1_9('Log Out')
     else:
         a.click_link(a.get_element(text='Log Out'))
Exemplo n.º 29
0
)
from u1testutils import mail
from u1testutils.sso import mail as sso_mail
from u1testutils.sst import config

from acceptance import helpers, urls


config.set_base_url_from_env()

go_to(urls.NEW_ACCOUNT)
assert_title('Create account')

email_address = mail.make_unique_test_email_address()
helpers.fill_registration_form(email_address)
click_button(get_element(name='continue'))

if 'allow_unverified' not in sst_config.flags:
    assert_title_contains('Account creation mail sent')
    assert_text_contains(
        get_element(id='content'),
        r'just emailed .* \(from .*\) to confirm your address\.',
        regex=True)

    link = sso_mail.get_verification_link_for_address(email_address)

    go_to(link)
    assert_title('Complete creating your account')
    click_button(get_element(css_class='btn'))
wait_for(assert_element, **{'data-qa-id': 'edit_account'})
Exemplo n.º 30
0
def get_update_preferences_button():
    return get_element(name="update", css_class="btn")
Exemplo n.º 31
0
def click_add_new_device_link():
    click_link(
        get_element(tag='a', text_regex='^Add a new authentication device'))