Merge branch 'master' into cronjobs

This commit is contained in:
Steffen 2016-04-05 15:23:03 +02:00
commit 7922ca8e84
8 changed files with 44 additions and 14 deletions

3
.rspec Normal file
View File

@ -0,0 +1,3 @@
--colour
--tty
--format documentation

View File

@ -5,7 +5,7 @@ ruby '2.1.7' if ENV.key?('DYNO')
gem 's3', github: 'travis-ci/s3' gem 's3', github: 'travis-ci/s3'
gem 'travis-core', github: 'travis-ci/travis-core', ref: 'sf-ar-te' gem 'travis-core', github: 'travis-ci/travis-core'
gem 'travis-support', github: 'travis-ci/travis-support' gem 'travis-support', github: 'travis-ci/travis-support'
gem 'travis-amqp', github: 'travis-ci/travis-amqp' gem 'travis-amqp', github: 'travis-ci/travis-amqp'
gem 'travis-config', '~> 0.1.0' gem 'travis-config', '~> 0.1.0'

View File

@ -48,8 +48,7 @@ GIT
GIT GIT
remote: git://github.com/travis-ci/travis-core.git remote: git://github.com/travis-ci/travis-core.git
revision: fdcd69981dc9ccb6f85452213d8bdc096f4308be revision: 9978518236afb520c8fff68bebe7beb62f8ad776
ref: sf-ar-te
specs: specs:
travis-core (0.0.1) travis-core (0.0.1)
actionmailer (~> 3.2.19) actionmailer (~> 3.2.19)

View File

@ -41,7 +41,6 @@ pg_dump -t logs travis_logs_test | psql -U postgres travis_test
popd popd
``` ```
### Run tests ### Run tests
$ rake spec $ rake spec

View File

@ -50,9 +50,9 @@ class Rack::Attack
# Ban time: 5 hours # Ban time: 5 hours
# Ban after: 10 POST requests within five minutes to /auth/github # Ban after: 10 POST requests within five minutes to /auth/github
blacklist('hammering /auth/github') do |request| blacklist('hammering /auth/github') do |request|
Rack::Attack::Allow2Ban.filter(request.identifier, maxretry: 2, findtime: 5.minutes, bantime: bantime(5.hours)) do Rack::Attack::Allow2Ban.filter(request.identifier, maxretry: 2, findtime: 5.minutes, bantime: bantime(5.hours)) do
request.post? and request.path == '/auth/github' request.post? and request.path == '/auth/github'
end end
end end
#### ####
@ -60,9 +60,9 @@ class Rack::Attack
# Ban time: 1 hour # Ban time: 1 hour
# Ban after: 10 POST requests within 30 seconds # Ban after: 10 POST requests within 30 seconds
blacklist('spamming with POST requests') do |request| blacklist('spamming with POST requests') do |request|
Rack::Attack::Allow2Ban.filter(request.identifier, maxretry: 10, findtime: 30.seconds, bantime: bantime(1.hour)) do Rack::Attack::Allow2Ban.filter(request.identifier, maxretry: 10, findtime: 30.seconds, bantime: bantime(1.hour)) do
request.post? and not POST_WHITELISTED.include? request.path request.post? and not POST_WHITELISTED.include? request.path
end end
end end

View File

@ -62,5 +62,9 @@ module Travis::API::V3
__send__(name, *args, &block) __send__(name, *args, &block)
end end
def settings
@settings ||= JSON.load(super)
end
end end
end end

View File

@ -22,14 +22,19 @@ module Travis::API::V3
accepted(remaining_requests: remaining, repository: repository, request: payload) accepted(remaining_requests: remaining, repository: repository, request: payload)
end end
def limit def limit(repository)
Travis.config.requests_create_api_limit || LIMIT if repository.settings.nil?
LIMIT
else
repository.settings["api_builds_rate_limit"] || Travis.config.requests_create_api_limit || LIMIT
end
end end
def remaining_requests(repository) def remaining_requests(repository)
return limit if access_control.full_access? api_builds_rate_limit = limit(repository)
return api_builds_rate_limit if access_control.full_access?
count = query(:requests).count(repository, TIME_FRAME) count = query(:requests).count(repository, TIME_FRAME)
count > limit ? 0 : limit - count count > api_builds_rate_limit ? 0 : api_builds_rate_limit - count
end end
end end
end end

View File

@ -239,6 +239,26 @@ describe Travis::API::V3::Services::Requests::Create do
} }
end end
describe "overrides default request limit if included in repository.settings" do
before { repo.update_attribute(:settings, { api_builds_rate_limit: 12 }.to_json) }
before { 10.times { repo.requests.create(event_type: 'api', result: 'accepted') } }
before { post("/v3/repo/#{repo.id}/requests", {}, headers) }
example { expect(last_response.status).to be == 202 }
example { expect(JSON.load(body).to_s).to include(
"@type",
"repository",
"remaining_requests",
"2",
"request",
"representation",
"minimal",
"slug",
"svenfuchs/minimal")
}
end
describe "passing the token in params" do describe "passing the token in params" do
let(:params) {{ request: { token: 'foo-bar' }}} let(:params) {{ request: { token: 'foo-bar' }}}
example { expect(sidekiq_params[:credentials]).to be == { example { expect(sidekiq_params[:credentials]).to be == {