當前位置: 首頁>>代碼示例>>Python>>正文


Python GenericAuthHandler.verify_account方法代碼示例

本文整理匯總了Python中inbox.auth.generic.GenericAuthHandler.verify_account方法的典型用法代碼示例。如果您正苦於以下問題:Python GenericAuthHandler.verify_account方法的具體用法?Python GenericAuthHandler.verify_account怎麽用?Python GenericAuthHandler.verify_account使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在inbox.auth.generic.GenericAuthHandler的用法示例。


在下文中一共展示了GenericAuthHandler.verify_account方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_auth

# 需要導入模塊: from inbox.auth.generic import GenericAuthHandler [as 別名]
# 或者: from inbox.auth.generic.GenericAuthHandler import verify_account [as 別名]
def test_auth(creds):
    handler = GenericAuthHandler(creds['provider'])
    email = creds['settings']['email']
    account = handler.create_account(email, creds['settings'])

    # Test that the account was successfully created by the handler.
    if 'smtp_password' in creds['settings']:
        assert account.imap_password == creds['settings']['imap_password']
        assert account.smtp_password == creds['settings']['smtp_password']
    else:
        assert account.imap_password == creds['settings']['password']
        assert account.smtp_password == creds['settings']['password']

    # Test that the account is valid.
    assert handler.verify_account(account) is True

    # Test that the password can be updated...
    bad_creds = {'email': creds['settings']['email'],
                 'smtp_password': 'bad_password',
                 'imap_server_host': creds['settings'].get('imap_server_host'),
                 'imap_server_port': 993,
                 'smtp_server_host': creds['settings'].get('smtp_server_host'),
                 'smtp_server_port': 587
                 }
    handler.update_account(account, bad_creds)
    assert account.smtp_password == 'bad_password'
    # ...but logging in again won't work.
    with pytest.raises(UserRecoverableConfigError):
        handler.verify_account(account)
開發者ID:marslabtron,項目名稱:sync-engine,代碼行數:31,代碼來源:test_imap_smtp_auth.py

示例2: test_successful_reauth_resets_sync_state

# 需要導入模塊: from inbox.auth.generic import GenericAuthHandler [as 別名]
# 或者: from inbox.auth.generic.GenericAuthHandler import verify_account [as 別名]
def test_successful_reauth_resets_sync_state(db):
    settings = {
        'provider': 'yahoo',
        'settings': {
            'name': 'Y.Y!',
            'locale': 'fr',
            'email': '[email protected]',
            'password': 'EverybodyLovesIMAPv4'}
    }
    email = settings['settings']['email']
    handler = GenericAuthHandler(settings['provider'])

    account = handler.create_account(email, settings['settings'])
    assert handler.verify_account(account) is True
    # Brand new accounts have `sync_state`=None.
    assert account.sync_state is None
    db.session.add(account)
    db.session.commit()

    # Pretend account sync starts, and subsequently the password changes,
    # causing the account to be in `sync_state`='invalid'.
    account.mark_invalid()
    db.session.commit()
    assert account.sync_state == 'invalid'

    # Verify the `sync_state` is reset to 'running' on a successful "re-auth".
    account = handler.update_account(account, settings['settings'])
    assert handler.verify_account(account) is True
    assert account.sync_state == 'running'
    db.session.add(account)
    db.session.commit()
開發者ID:rjmcguire,項目名稱:sync-engine,代碼行數:33,代碼來源:test_generic_auth.py

示例3: test_double_auth

# 需要導入模塊: from inbox.auth.generic import GenericAuthHandler [as 別名]
# 或者: from inbox.auth.generic.GenericAuthHandler import verify_account [as 別名]
def test_double_auth(db, mock_auth_imapclient):
    settings = {
        'provider': 'yahoo',
        'settings': {
            'name': 'Y.Y!',
            'locale': 'fr',
            'email': '[email protected]',
            'password': 'EverybodyLovesIMAPv4'}
    }
    email = settings['settings']['email']
    password = settings['settings']['password']
    mock_auth_imapclient._add_login(email, password)

    handler = GenericAuthHandler(settings['provider'])

    # First authentication, using a valid password, succeeds.
    valid_settings = copy.deepcopy(settings)

    account = handler.create_account(email, valid_settings['settings'])
    assert handler.verify_account(account) is True

    db.session.add(account)
    db.session.commit()
    id_ = account.id
    account = db.session.query(Account).get(id_)
    assert account.email_address == email
    assert account.imap_username == email
    assert account.smtp_username == email
    assert account.password == password
    assert account.imap_password == password
    assert account.smtp_password == password

    # Second auth using an invalid password should fail.
    invalid_settings = copy.deepcopy(settings)
    invalid_settings['settings']['password'] = 'invalid_password'
    with pytest.raises(ValidationError):
        account = handler.update_account(account, invalid_settings['settings'])
        handler.verify_account(account)

    db.session.expire(account)

    # Ensure original account is unaffected
    account = db.session.query(Account).get(id_)
    assert account.email_address == email
    assert account.imap_username == email
    assert account.smtp_username == email
    assert account.password == password
    assert account.imap_password == password
    assert account.smtp_password == password
開發者ID:brandoncc,項目名稱:sync-engine,代碼行數:51,代碼來源:test_generic_auth.py

示例4: test_imap_not_fully_enabled

# 需要導入模塊: from inbox.auth.generic import GenericAuthHandler [as 別名]
# 或者: from inbox.auth.generic.GenericAuthHandler import verify_account [as 別名]
def test_imap_not_fully_enabled(monkeypatch):

    def folder_list_fail(conn):
        raise Exception("LIST failed: '[ALERT] full IMAP support "
                        "is NOT enabled for this account'")

    monkeypatch.setattr('imapclient.IMAPClient.list_folders',
                        folder_list_fail)

    def fake_connect(account):
        return MockIMAPClient()

    response = {
        'email': '[email protected]',
        'password': 'test123',
        'imap_server_host': '0.0.0.0',
        'imap_server_port': 22,
        'smtp_server_host': '0.0.0.0',
        'smtp_server_port': 23
    }

    handler = GenericAuthHandler('custom')
    acct = handler.create_account(
        '[email protected]',
        response)
    handler.connect_account = fake_connect
    handler._supports_condstore = lambda x: True
    with pytest.raises(UserRecoverableConfigError):
        verified = handler.verify_account(acct)
        assert verified is not True
開發者ID:DrMoriarty,項目名稱:sync-engine,代碼行數:32,代碼來源:test_full_imap_enabled.py

示例5: test_auth

# 需要導入模塊: from inbox.auth.generic import GenericAuthHandler [as 別名]
# 或者: from inbox.auth.generic.GenericAuthHandler import verify_account [as 別名]
def test_auth(creds, mock_imapclient):
    imap_username = creds['settings'].get('imap_username')
    if imap_username is None:
        imap_username = creds['settings']['email']
    imap_password = creds['settings'].get('imap_password')
    if imap_password is None:
        imap_password = creds['settings']['password']
    mock_imapclient._add_login(imap_username, imap_password)

    handler = GenericAuthHandler(creds['provider'])
    email = creds['settings']['email']
    account = handler.create_account(email, creds['settings'])

    # Test that the account was successfully created by the handler.
    assert account.imap_password == imap_password
    if 'smtp_password' in creds['settings']:
        assert account.smtp_password == creds['settings']['smtp_password']
    else:
        assert account.imap_password == creds['settings']['password']
        assert account.smtp_password == creds['settings']['password']

    # Test that the account is valid.
    assert handler.verify_account(account) is True

    # Test that the password can be updated...
    bad_creds = {'email': creds['settings']['email'],
                 'imap_password': 'bad_password',
                 'imap_server_host': creds['settings'].get('imap_server_host'),
                 'imap_server_port': 993,
                 'smtp_server_host': creds['settings'].get('smtp_server_host'),
                 'smtp_server_port': 587
                 }
    handler.update_account(account, bad_creds)
    assert account.imap_password == 'bad_password'
    # ...but logging in again won't work.
    with pytest.raises(ValidationError):
        handler.verify_account(account)
開發者ID:aabde,項目名稱:sync-engine,代碼行數:39,代碼來源:test_imap_smtp_auth.py

示例6: test_auth

# 需要導入模塊: from inbox.auth.generic import GenericAuthHandler [as 別名]
# 或者: from inbox.auth.generic.GenericAuthHandler import verify_account [as 別名]
def test_auth(settings):
    handler = GenericAuthHandler(settings['provider'])

    has_starttls = ('aol' in settings['settings']['imap_server_host'])
    if has_starttls:
        account = _create_account(settings, ssl=True)
        handler.verify_account(account)
    else:
        account = _create_account(settings, ssl=True)
        with pytest.raises(Exception):
            handler.verify_account(account)
        account = _create_account(settings, ssl=False)
        handler.verify_account(account)
開發者ID:aabde,項目名稱:sync-engine,代碼行數:15,代碼來源:test_ssl_auth.py


注:本文中的inbox.auth.generic.GenericAuthHandler.verify_account方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。