コード例 #1
0
def test_right_credentials_login_post(client, john_snow):

    response = client.simulate_post('/auth/login', body=json.dumps({
        'username':john_snow.username,
        'password':'******'
    }))
    assert response.status == falcon.HTTP_200
コード例 #2
0
def test_right_logout_logged_post(client, token):
    response = client.simulate_post(
        '/auth/logout',
        headers={
            'authorization': 'jwt %s' % token
        }
    )
    assert response.status == falcon.HTTP_200
コード例 #3
0
def test_right_refresh_token_post(client, login):
    response = client.simulate_post(
        '/auth/refresh_token',
        headers={
            'authorization': 'jwt %s' % login['token']
        },
        body=json.dumps({
            'refresh_token':login['refresh_token']
        })
    )
    assert response.status == falcon.HTTP_200
コード例 #4
0
def test_incorrectly_filled_refresh_token_post(client, token):
    response = client.simulate_post(
        '/auth/refresh_token',
        headers={
            'authorization': 'jwt %s' % token
        },
        body=json.dumps({
            'refresh_token':'xxx'
        })
    )
    assert response.status == falcon.HTTP_400
コード例 #5
0
def test_right_expired_refresh_token_post(client, john_snow):
    auth_backend = JWTAuthBackend(get_authenticated_user, settings.SECRET_KEY, expiration_delta=0)
    uid = john_snow.id
    with scoped_session() as session:
        refresh_token = session.query(RefreshToken).filter(RefreshToken.user_id == uid).first().token
        token = auth_backend.get_auth_token(TokenPayloadSchema().dump(john_snow).data)
    decoded = jwt.decode(token, key=settings.SECRET_KEY, algorithms='HS256')

    assert decoded is not None and 'exp' in decoded
    time.sleep(1)
    assert decoded['exp'] < int(time.time())

    response = client.simulate_post(
        '/auth/refresh_token',
        headers={
            'authorization': 'jwt %s' % token
        },
        body=json.dumps({
            'refresh_token': refresh_token
        })
    )
    assert response.status == falcon.HTTP_200
    assert response.json['token'] != token
コード例 #6
0
def test_empty_refresh_token_post(client):
    response = client.simulate_post('/auth/refresh_token')
    assert response.status == falcon.HTTP_401
コード例 #7
0
def test_empty_logout_unlogged_post(client):
    response = client.simulate_post('/auth/logout')
    assert response.status == falcon.HTTP_401
コード例 #8
0
def test_wrong_credentials_login_post(client):
    response = client.simulate_post('/auth/login', params={
        'username':'******',
        'password':'******'
    })
    assert response.status == falcon.HTTP_400
コード例 #9
0
def test_incorrectly_filled_login_post(client):
    response = client.simulate_post('/auth/login', params={'foo':'bar'})
    assert response.status == falcon.HTTP_400
コード例 #10
0
def test_empty_login_post(client):
    response = client.simulate_post('/auth/login')
    assert response.status == falcon.HTTP_400