def test_safe_redirect():
    app, db, admin = setup()
    Model1, _ = create_models(db)

    view = CustomModelView(Model1, db.session)
    admin.add_view(view)

    client = app.test_client()

    rv = client.post('/admin/model1/new/?url=http://localhost/admin/model2view/',
                     data=dict(test1='test1large', test2='test2',
                               _continue_editing='Save and Continue Editing'))

    eq_(rv.status_code, 302)
    assert_true(rv.location.startswith('http://localhost/admin/model1/edit/'))
    assert_true('url=http%3A%2F%2Flocalhost%2Fadmin%2Fmodel2view%2F' in rv.location)
    assert_true('id=1' in rv.location)

    rv = client.post('/admin/model1/new/?url=http://google.com/evil/',
                     data=dict(test1='test1large', test2='test2',
                               _continue_editing='Save and Continue Editing'))

    eq_(rv.status_code, 302)
    assert_true(rv.location.startswith('http://localhost/admin/model1/edit/'))
    assert_true('url=%2Fadmin%2Fmodel1%2F' in rv.location)
    assert_true('id=2' in rv.location)
dataset/ETHPy150Open flask-admin/flask-admin/flask_admin/tests/sqla/test_basic.py/test_safe_redirect/original