def _log_in(self, client):
        """Emulates test client login in the store.

        Fill current session with `openid`, `macaroon_root` and
        `macaroon_discharge`.

        Return the expected `Authorization` header for further verification in
        API requests.
        """
        # Basic root/discharge macaroons pair.
        root = pymacaroons.Macaroon('test', 'testing', 'a_key')
        root.add_third_party_caveat('3rd', 'a_caveat-key', 'a_ident')
        discharge = pymacaroons.Macaroon('3rd', 'a_ident', 'a_caveat_key')

        with client.session_transaction() as s:
            s['openid'] = {
                'image': None,
                'nickname': 'Toto',
                'fullname': 'El Toto'
            }
            s['macaroon_root'] = root.serialize()
            s['macaroon_discharge'] = discharge.serialize()

        return get_authorization_header(root.serialize(),
                                        discharge.serialize())
Beispiel #2
0
def get_account(session):
    authorization = authentication.get_authorization_header(
        session['macaroon_root'], session['macaroon_discharge'])

    headers = {
        'X-Ubuntu-Series': '16',
        'X-Ubuntu-Architecture': 'amd64',
        'Authorization': authorization
    }

    response = cache.get(url=ACCOUNT_URL, method='GET', headers=headers)

    if authentication.is_macaroon_expired(response.headers):
        raise MacaroonRefreshRequired()

    return response.json()
Beispiel #3
0
def get_account():
    authorization = authentication.get_authorization_header(
        flask.session['macaroon_root'], flask.session['macaroon_discharge'])

    headers = {
        'X-Ubuntu-Series': '16',
        'X-Ubuntu-Architecture': 'amd64',
        'Authorization': authorization
    }

    response = cache.get(url=ACCOUNT_URL, method='GET', headers=headers)

    verified_response = verify_response(response, ACCOUNT_URL, '/account',
                                        '/login')

    if verified_response is not None:
        return {'redirect': verified_response}

    return response.json()
Beispiel #4
0
def get_authorization_header():
    authorization = authentication.get_authorization_header(
        flask.session['macaroon_root'], flask.session['macaroon_discharge'])

    return {'Authorization': authorization}