mirror of
https://github.com/mastodon/mastodon.git
synced 2025-03-12 08:55:22 +00:00

Some checks failed
Check i18n / check-i18n (push) Waiting to run
CodeQL / Analyze (javascript) (push) Waiting to run
CodeQL / Analyze (ruby) (push) Waiting to run
Crowdin / Upload translations / upload-translations (push) Waiting to run
Check formatting / lint (push) Waiting to run
CSS Linting / lint (push) Waiting to run
JavaScript Linting / lint (push) Waiting to run
Ruby Linting / lint (push) Waiting to run
JavaScript Testing / test (push) Waiting to run
Historical data migration test / test (14-alpine) (push) Waiting to run
Historical data migration test / test (15-alpine) (push) Waiting to run
Historical data migration test / test (16-alpine) (push) Waiting to run
Historical data migration test / test (17-alpine) (push) Waiting to run
Ruby Testing / build (production) (push) Waiting to run
Ruby Testing / build (test) (push) Waiting to run
Ruby Testing / test (.ruby-version) (push) Blocked by required conditions
Ruby Testing / test (3.2) (push) Blocked by required conditions
Ruby Testing / Libvips tests (.ruby-version) (push) Blocked by required conditions
Ruby Testing / Libvips tests (3.2) (push) Blocked by required conditions
Ruby Testing / End to End testing (.ruby-version) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:8.10.2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, opensearchproject/opensearch:2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (3.2, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
Bundler Audit / security (push) Has been cancelled
Haml Linting / lint (push) Has been cancelled
57 lines
1.5 KiB
Ruby
57 lines
1.5 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'rails_helper'
|
|
|
|
RSpec.describe Api::RateLimitHeaders do
|
|
controller(ApplicationController) do
|
|
include Api::RateLimitHeaders # rubocop:disable RSpec/DescribedClass
|
|
|
|
def show
|
|
head 200
|
|
end
|
|
end
|
|
|
|
before do
|
|
routes.draw { get 'show' => 'anonymous#show' }
|
|
end
|
|
|
|
describe 'rate limiting' do
|
|
context 'when throttling is off' do
|
|
before do
|
|
request.env['rack.attack.throttle_data'] = nil
|
|
end
|
|
|
|
it 'does not apply rate limiting' do
|
|
get 'show'
|
|
|
|
expect(response.headers['X-RateLimit-Limit']).to be_nil
|
|
expect(response.headers['X-RateLimit-Remaining']).to be_nil
|
|
expect(response.headers['X-RateLimit-Reset']).to be_nil
|
|
end
|
|
end
|
|
|
|
context 'when throttling is on' do
|
|
let(:start_time) { DateTime.new(2017, 1, 1, 12, 0, 0).utc }
|
|
|
|
before do
|
|
request.env['rack.attack.throttle_data'] = { 'throttle_authenticated_api' => { limit: 100, count: 20, period: 10 } }
|
|
travel_to start_time do
|
|
get 'show'
|
|
end
|
|
end
|
|
|
|
it 'applies rate limiting limit header' do
|
|
expect(response.headers['X-RateLimit-Limit']).to eq '100'
|
|
end
|
|
|
|
it 'applies rate limiting remaining header' do
|
|
expect(response.headers['X-RateLimit-Remaining']).to eq '80'
|
|
end
|
|
|
|
it 'applies rate limiting reset header' do
|
|
expect(response.headers['X-RateLimit-Reset']).to eq (start_time + 10.seconds).iso8601(6)
|
|
end
|
|
end
|
|
end
|
|
end
|