Example #1
0
def test_lookup_userfile(app, client):
  uuid = 'deadbeef-dead-beef-dead-beefdeadbeef'
  bad_uuid = 'deadduck-dead-duck-dead-duckdeadduck'
  upper_uuid = 'DEADBEEF-DEAD-BEEF-DEAD-BEEFDEADBEEF'

  def _stream_read_file(locations, path):
    if path.find(uuid) > 0 or path.find(upper_uuid) > 0:
      return BytesIO("hello world")

    raise IOError('Not found!')

  storage_mock = Mock()
  storage_mock.stream_read_file = _stream_read_file

  app.config['USERFILES_PATH'] = 'foo'
  Userfiles(app, distributed_storage=storage_mock, path='mockuserfiles',
            handler_name='mockuserfiles')

  rv = client.open('/mockuserfiles/' + uuid, method='GET')
  assert rv.status_code == 200

  rv = client.open('/mockuserfiles/' + upper_uuid, method='GET')
  assert rv.status_code == 200

  rv = client.open('/mockuserfiles/' + bad_uuid, method='GET')
  assert rv.status_code == 404

  rv = client.open('/mockuserfiles/foo/bar/baz', method='GET')
  assert rv.status_code == 404
Example #2
0
def test_lookup_userfile(app, client):
    uuid = "deadbeef-dead-beef-dead-beefdeadbeef"
    bad_uuid = "deadduck-dead-duck-dead-duckdeadduck"
    upper_uuid = "DEADBEEF-DEAD-BEEF-DEAD-BEEFDEADBEEF"

    def _stream_read_file(locations, path):
        if path.find(uuid) > 0 or path.find(upper_uuid) > 0:
            return BytesIO(b"hello world")

        raise IOError("Not found!")

    storage_mock = Mock()
    storage_mock.stream_read_file = _stream_read_file

    app.config["USERFILES_PATH"] = "foo"
    Userfiles(app,
              distributed_storage=storage_mock,
              path="mockuserfiles",
              handler_name="mockuserfiles")

    rv = client.open("/mockuserfiles/" + uuid, method="GET")
    assert rv.status_code == 200

    rv = client.open("/mockuserfiles/" + upper_uuid, method="GET")
    assert rv.status_code == 200

    rv = client.open("/mockuserfiles/" + bad_uuid, method="GET")
    assert rv.status_code == 404

    rv = client.open("/mockuserfiles/foo/bar/baz", method="GET")
    assert rv.status_code == 404
Example #3
0
def app(appconfig, initialized_db):
    """
    Used by pytest-flask plugin to inject a custom app instance for testing.
    """
    app = Flask(__name__)
    login_manager = LoginManager(app)

    @app.errorhandler(model.DataModelException)
    def handle_dme(ex):
        response = jsonify({"message": str(ex)})
        response.status_code = 400
        return response

    @login_manager.user_loader
    def load_user(user_uuid):
        return LoginWrappedDBUser(user_uuid)

    @identity_loaded.connect_via(app)
    def on_identity_loaded_for_test(sender, identity):
        on_identity_loaded(sender, identity)

    Principal(app, use_sessions=False)

    app.url_map.converters["regex"] = RegexConverter
    app.url_map.converters["apirepopath"] = APIRepositoryPathConverter
    app.url_map.converters["repopath"] = RepositoryPathConverter
    app.url_map.converters[
        "repopathredirect"] = RepositoryPathRedirectConverter
    app.url_map.converters[
        "v1createrepopath"] = V1CreateRepositoryPathConverter

    app.register_blueprint(api_bp, url_prefix="/api")
    app.register_blueprint(appr_bp, url_prefix="/cnr")
    app.register_blueprint(web, url_prefix="/")
    app.register_blueprint(v1_bp, url_prefix="/v1")
    app.register_blueprint(v2_bp, url_prefix="/v2")
    app.register_blueprint(webhooks, url_prefix="/webhooks")

    app.config.update(appconfig)

    Userfiles(app)
    Mail(app)

    return app
Example #4
0
def test_lookup_userfile_with_nested_path(app, client):
    uuid = "deadbeef-dead-beef-dead-beefdeadbeef"
    bad_uuid = "deadduck-dead-duck-dead-duckdeadduck"
    upper_uuid = "DEADBEEF-DEAD-BEEF-DEAD-BEEFDEADBEEF"

    def _stream_read_file(locations, path):
        if path.find(uuid) > 0 or path.find(upper_uuid) > 0:
            return BytesIO(b"hello world")

        raise IOError("Not found!")

    storage_mock = Mock()
    storage_mock.stream_read_file = _stream_read_file

    Userfiles(
        app,
        distributed_storage=storage_mock,
        path="mockuserfiles/foo/bar",
        handler_name="mockuserfiles2",
    )

    rv = client.open("/mockuserfiles/foo/bar/" + uuid, method="GET")
    assert rv.status_code == 200

    rv = client.open("/mockuserfiles/foo/bar/" + upper_uuid, method="GET")
    assert rv.status_code == 200

    rv = client.open("/mockuserfiles/foo/bar/" + bad_uuid, method="GET")
    assert rv.status_code == 404

    rv = client.open("/mockuserfiles/foo/bar/baz", method="GET")
    assert rv.status_code == 404

    # The follwing path should conflict with the reponame regex
    rv = client.open("/mockuserfiles/" + uuid, method="GET")
    assert rv.status_code == 308

    rv = client.open("/mockuserfiles/" + upper_uuid, method="GET")
    assert rv.status_code == 308

    rv = client.open("/mockuserfiles/" + bad_uuid, method="GET")
    assert rv.status_code == 308
Example #5
0
def test_lookup_userfile(app, client):
    uuid = "deadbeef-dead-beef-dead-beefdeadbeef"
    bad_uuid = "deadduck-dead-duck-dead-duckdeadduck"
    upper_uuid = "DEADBEEF-DEAD-BEEF-DEAD-BEEFDEADBEEF"

    def _stream_read_file(locations, path):
        if path.find(uuid) > 0 or path.find(upper_uuid) > 0:
            return BytesIO(b"hello world")

        raise IOError("Not found!")

    storage_mock = Mock()
    storage_mock.stream_read_file = _stream_read_file

    app.config["USERFILES_PATH"] = "foo"
    Userfiles(
        app, distributed_storage=storage_mock, path="mockuserfiles", handler_name="mockuserfiles"
    )

    rv = client.open("/mockuserfiles/" + uuid, method="GET")
    assert rv.status_code == 200

    rv = client.open("/mockuserfiles/" + upper_uuid, method="GET")
    assert rv.status_code == 200

    rv = client.open("/mockuserfiles/" + bad_uuid, method="GET")
    assert rv.status_code == 404

    # NOTE: With the changes to the path converter for the extended repository names regex,
    # this route conflicts with one of the route using the <reponame> regex.
    # i.e /mockuserfiles/foo/bar/baz would match another url route.
    # In order to 404 on this path, The Userfiles' path would need the full
    # /mockuserfiles/foo/bar as a path for the Flask url_rule.
    rv = client.open("/mockuserfiles/foo/bar/baz", method="GET")
    # assert rv.status_code == 404
    assert rv.status_code == 308
Example #6
0
app.url_map.converters["apirepopath"] = APIRepositoryPathConverter

Principal(app, use_sessions=False)

tf = app.config["DB_TRANSACTION_FACTORY"]

model_cache = get_model_cache(app.config)
avatar = Avatar(app)
login_manager = LoginManager(app)
mail = Mail(app)
prometheus = PrometheusPlugin(app)
chunk_cleanup_queue = WorkQueue(app.config["CHUNK_CLEANUP_QUEUE_NAME"], tf)
instance_keys = InstanceKeys(app)
ip_resolver = IPResolver(app)
storage = Storage(app, chunk_cleanup_queue, instance_keys, config_provider, ip_resolver)
userfiles = Userfiles(app, storage)
log_archive = LogArchive(app, storage)
analytics = Analytics(app)
user_analytics = UserAnalytics(app)
billing = Billing(app)
sentry = Sentry(app)
build_logs = BuildLogs(app)
authentication = UserAuthentication(app, config_provider, OVERRIDE_CONFIG_DIRECTORY)
userevents = UserEventsBuilderModule(app)
superusers = SuperUserManager(app)
signer = Signer(app, config_provider)
instance_keys = InstanceKeys(app)
label_validator = LabelValidator(app)
build_canceller = BuildCanceller(app)

github_trigger = GithubOAuthService(app.config, "GITHUB_TRIGGER_CONFIG")