Exemplo n.º 1
0
def test_get_email_of_user_http_err(running_app, auth0id, requests_mock,
                                    token_set):
    requests_mock.register_uri(
        'GET',
        re.compile(running_app.config['AUTH0_BASE_URL'] + '/.*'),
        status_code=401)
    out = auth0_info.get_email_of_user(auth0id)
    assert out == 'Unable to retrieve'
Exemplo n.º 2
0
def test_get_email_of_user(running_app, auth0id, email, requests_mock,
                           token_set):
    requests_mock.register_uri(
        'GET',
        re.compile(running_app.config['AUTH0_BASE_URL'] + '/.*'),
        content=f'{{"email": "{email}"}}'.encode())
    out = auth0_info.get_email_of_user(auth0id)
    assert out == email
    r = auth0_info.token_redis_connection()
    assert r.get(auth0id) == email
    assert 90000 > r.ttl(auth0id) > 80000
Exemplo n.º 3
0
 def get(self):
     """
     ---
     summary: Get current user metadata.
     tags:
       - Users
     responses:
       200:
         description: User successully retrieved.
         content:
           application/json:
             schema:
               $ref: '#/components/schemas/UserSchema'
       401:
         $ref: '#/components/responses/401-Unauthorized'
       404:
         $ref: '#/components/responses/404-NotFound'
     """
     storage = get_storage()
     user_info = storage.get_current_user_info()
     user_info['email'] = get_email_of_user(user_info['auth0_id'])
     return jsonify(UserSchema().dump(user_info))
Exemplo n.º 4
0
 def get(self, user_id):
     """
     ---
     summary: Get user email from user id.
     tags:
       - Users
     responses:
       200:
         description: The user's email.
         content:
           text/plain:
             schema:
               type: string
               example: [email protected]
       401:
         $ref: '#/components/responses/401-Unauthorized'
       404:
         $ref: '#/components/responses/404-NotFound'
     """
     storage = get_storage()
     auth0_id = storage.read_auth0id(user_id)
     email = get_email_of_user(auth0_id)
     return email
Exemplo n.º 5
0
 def get(self, user_id):
     """
     ---
     summary: Get User Metadata.
     parameters:
     - user_id
     tags:
       - Users
     responses:
       200:
         description: User successully retrieved.
         content:
           application/json:
             schema:
               $ref: '#/components/schemas/UserSchema'
       401:
         $ref: '#/components/responses/401-Unauthorized'
       404:
         $ref: '#/components/responses/404-NotFound'
     """
     storage = get_storage()
     user = storage.read_user(user_id)
     user['email'] = get_email_of_user(user['auth0_id'])
     return jsonify(UserSchema().dump(user))
Exemplo n.º 6
0
 def get(self):
     """
     ---
     summary: List Users.
     description: List all Users that current User has access to.
     tags:
       - Users
     responses:
       200:
         description: A list of Users
         content:
           application/json:
             schema:
               type: array
               items:
                 $ref: '#/components/schemas/UserSchema'
       401:
         $ref: '#/components/responses/401-Unauthorized'
     """
     storage = get_storage()
     users = storage.list_users()
     for u in users:
         u['email'] = get_email_of_user(u['auth0_id'])
     return jsonify(UserSchema(many=True).dump(users))
Exemplo n.º 7
0
def test_get_email_of_user_bad_id(running_app):
    with pytest.raises(ValueError):
        auth0_info.get_email_of_user('badid')
Exemplo n.º 8
0
def test_get_email_of_user_in_redis(running_app, auth0id, email,
                                    email_in_redis, token_set):
    assert auth0_info.get_email_of_user(auth0id) == email