|
@@ -2,12 +2,7 @@
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
|
-RSpec.describe 'Form', type: :request, searchindex: true do
|
|
|
-
|
|
|
- before do
|
|
|
- configure_elasticsearch
|
|
|
- rebuild_searchindex
|
|
|
- end
|
|
|
+RSpec.describe 'Form', type: :request do
|
|
|
|
|
|
describe 'request handling' do
|
|
|
|
|
@@ -139,8 +134,6 @@ RSpec.describe 'Form', type: :request, searchindex: true do
|
|
|
end
|
|
|
|
|
|
it 'does limits' do
|
|
|
- skip('No ES configured') if !SearchIndexBackend.enabled?
|
|
|
-
|
|
|
Setting.set('form_ticket_create', true)
|
|
|
fingerprint = SecureRandom.hex(40)
|
|
|
post '/api/v1/form_config', params: { fingerprint: fingerprint }, as: :json
|
|
@@ -160,15 +153,10 @@ RSpec.describe 'Form', type: :request, searchindex: true do
|
|
|
expect(json_response['errors']).to be_falsey
|
|
|
expect(json_response['ticket']).to be_truthy
|
|
|
expect(json_response['ticket']['id']).to be_truthy
|
|
|
- Scheduler.worker(true)
|
|
|
end
|
|
|
|
|
|
- sleep 10 # wait until elasticsearch is index
|
|
|
-
|
|
|
post '/api/v1/form_submit', params: { fingerprint: fingerprint, token: token, name: 'Bob Smith', email: 'discard@znuny.com', title: 'test-last', body: 'hello' }, as: :json
|
|
|
- expect(response).to have_http_status(:forbidden)
|
|
|
- expect(json_response).to be_a_kind_of(Hash)
|
|
|
- expect(json_response['error']).to be_truthy
|
|
|
+ expect(response).to have_http_status(:too_many_requests)
|
|
|
|
|
|
@headers = { 'ACCEPT' => 'application/json', 'CONTENT_TYPE' => 'application/json', 'REMOTE_ADDR' => '1.2.3.5' }
|
|
|
|
|
@@ -180,15 +168,10 @@ RSpec.describe 'Form', type: :request, searchindex: true do
|
|
|
expect(json_response['errors']).to be_falsey
|
|
|
expect(json_response['ticket']).to be_truthy
|
|
|
expect(json_response['ticket']['id']).to be_truthy
|
|
|
- Scheduler.worker(true)
|
|
|
end
|
|
|
|
|
|
- sleep 10 # wait until elasticsearch is index
|
|
|
-
|
|
|
post '/api/v1/form_submit', params: { fingerprint: fingerprint, token: token, name: 'Bob Smith', email: 'discard@znuny.com', title: 'test-2-last', body: 'hello' }, as: :json
|
|
|
- expect(response).to have_http_status(:forbidden)
|
|
|
- expect(json_response).to be_a_kind_of(Hash)
|
|
|
- expect(json_response['error']).to be_truthy
|
|
|
+ expect(response).to have_http_status(:too_many_requests)
|
|
|
|
|
|
@headers = { 'ACCEPT' => 'application/json', 'CONTENT_TYPE' => 'application/json', 'REMOTE_ADDR' => '::1' }
|
|
|
|
|
@@ -200,15 +183,10 @@ RSpec.describe 'Form', type: :request, searchindex: true do
|
|
|
expect(json_response['errors']).to be_falsey
|
|
|
expect(json_response['ticket']).to be_truthy
|
|
|
expect(json_response['ticket']['id']).to be_truthy
|
|
|
- Scheduler.worker(true)
|
|
|
end
|
|
|
|
|
|
- sleep 10 # wait until elasticsearch is index
|
|
|
-
|
|
|
post '/api/v1/form_submit', params: { fingerprint: fingerprint, token: token, name: 'Bob Smith', email: 'discard@znuny.com', title: 'test-2-last', body: 'hello' }, as: :json
|
|
|
- expect(response).to have_http_status(:forbidden)
|
|
|
- expect(json_response).to be_a_kind_of(Hash)
|
|
|
- expect(json_response['error']).to be_truthy
|
|
|
+ expect(response).to have_http_status(:too_many_requests)
|
|
|
end
|
|
|
|
|
|
it 'does customer_ticket_create false disables form' do
|