Merge remote-tracking branch 'travis/master' into readme_update
Conflicts: README.md
This commit is contained in:
commit
c6d9e5ad7d
2
Gemfile
2
Gemfile
|
@ -5,7 +5,7 @@ ruby '2.1.7' if ENV.key?('DYNO')
|
|||
|
||||
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-amqp', github: 'travis-ci/travis-amqp'
|
||||
gem 'travis-config', '~> 0.1.0'
|
||||
|
|
|
@ -48,8 +48,7 @@ GIT
|
|||
|
||||
GIT
|
||||
remote: git://github.com/travis-ci/travis-core.git
|
||||
revision: fdcd69981dc9ccb6f85452213d8bdc096f4308be
|
||||
ref: sf-ar-te
|
||||
revision: a66c345d44fd9c28884d694acfff3b1a0fbc5232
|
||||
specs:
|
||||
travis-core (0.0.1)
|
||||
actionmailer (~> 3.2.19)
|
||||
|
@ -391,4 +390,4 @@ DEPENDENCIES
|
|||
yard-sinatra!
|
||||
|
||||
BUNDLED WITH
|
||||
1.12.0.pre.1
|
||||
1.11.2
|
||||
|
|
|
@ -65,6 +65,8 @@ $ bundle exec rspec
|
|||
```sh-session
|
||||
$ bundle exec script/server
|
||||
```
|
||||
If you have problems with Nginx because the websocket is already in use, try restarting your computer.
|
||||
|
||||
## Contributing
|
||||
|
||||
1. Fork it
|
||||
|
|
|
@ -50,9 +50,9 @@ class Rack::Attack
|
|||
# Ban time: 5 hours
|
||||
# Ban after: 10 POST requests within five minutes to /auth/github
|
||||
blacklist('hammering /auth/github') do |request|
|
||||
Rack::Attack::Allow2Ban.filter(request.identifier, maxretry: 2, findtime: 5.minutes, bantime: bantime(5.hours)) do
|
||||
request.post? and request.path == '/auth/github'
|
||||
end
|
||||
Rack::Attack::Allow2Ban.filter(request.identifier, maxretry: 2, findtime: 5.minutes, bantime: bantime(5.hours)) do
|
||||
request.post? and request.path == '/auth/github'
|
||||
end
|
||||
end
|
||||
|
||||
####
|
||||
|
@ -60,9 +60,9 @@ class Rack::Attack
|
|||
# Ban time: 1 hour
|
||||
# Ban after: 10 POST requests within 30 seconds
|
||||
blacklist('spamming with POST requests') do |request|
|
||||
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
|
||||
end
|
||||
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
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
|
|
@ -62,5 +62,9 @@ module Travis::API::V3
|
|||
|
||||
__send__(name, *args, &block)
|
||||
end
|
||||
|
||||
def settings
|
||||
@settings ||= JSON.load(super)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
module Travis::API::V3
|
||||
class Services::Requests::Create < Service
|
||||
TIME_FRAME = 1.hour
|
||||
LIMIT = 10
|
||||
LIMIT = 10
|
||||
private_constant :TIME_FRAME, :LIMIT
|
||||
|
||||
result_type :request
|
||||
|
@ -22,14 +22,19 @@ module Travis::API::V3
|
|||
accepted(remaining_requests: remaining, repository: repository, request: payload)
|
||||
end
|
||||
|
||||
def limit
|
||||
Travis.config.requests_create_api_limit || LIMIT
|
||||
def limit(repository)
|
||||
if repository.settings.nil?
|
||||
Travis.config.requests_create_api_limit || LIMIT
|
||||
else
|
||||
repository.settings["api_builds_rate_limit"] || Travis.config.requests_create_api_limit || LIMIT
|
||||
end
|
||||
end
|
||||
|
||||
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 > limit ? 0 : limit - count
|
||||
count > api_builds_rate_limit ? 0 : api_builds_rate_limit - count
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -239,6 +239,26 @@ describe Travis::API::V3::Services::Requests::Create do
|
|||
}
|
||||
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
|
||||
let(:params) {{ request: { token: 'foo-bar' }}}
|
||||
example { expect(sidekiq_params[:credentials]).to be == {
|
||||
|
|
Loading…
Reference in New Issue
Block a user