mirror of
https://github.com/mastodon/mastodon.git
synced 2025-02-03 07:51:43 +01:00
Use expect
for api/v1 and api/web push subs controllers (#33682)
This commit is contained in:
parent
b18caff5b6
commit
607f65a0a5
@ -56,12 +56,12 @@ class Api::V1::Push::SubscriptionsController < Api::BaseController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def subscription_params
|
def subscription_params
|
||||||
params.require(:subscription).permit(:endpoint, :standard, keys: [:auth, :p256dh])
|
params.expect(subscription: [:endpoint, :standard, keys: [:auth, :p256dh]])
|
||||||
end
|
end
|
||||||
|
|
||||||
def data_params
|
def data_params
|
||||||
return {} if params[:data].blank?
|
return {} if params[:data].blank?
|
||||||
|
|
||||||
params.require(:data).permit(:policy, alerts: Notification::TYPES)
|
params.expect(data: [:policy, alerts: Notification::TYPES])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -66,7 +66,7 @@ class Api::Web::PushSubscriptionsController < Api::Web::BaseController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def subscription_params
|
def subscription_params
|
||||||
@subscription_params ||= params.require(:subscription).permit(:standard, :endpoint, keys: [:auth, :p256dh])
|
@subscription_params ||= params.expect(subscription: [:standard, :endpoint, keys: [:auth, :p256dh]])
|
||||||
end
|
end
|
||||||
|
|
||||||
def web_push_subscription_params
|
def web_push_subscription_params
|
||||||
@ -82,6 +82,6 @@ class Api::Web::PushSubscriptionsController < Api::Web::BaseController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def data_params
|
def data_params
|
||||||
@data_params ||= params.require(:data).permit(:policy, alerts: Notification::TYPES)
|
@data_params ||= params.expect(data: [:policy, alerts: Notification::TYPES])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -107,6 +107,13 @@ RSpec.describe 'API V1 Push Subscriptions' do
|
|||||||
|
|
||||||
it_behaves_like 'validation error'
|
it_behaves_like 'validation error'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'gracefully handles invalid nested params' do
|
||||||
|
post api_v1_push_subscription_path, params: { subscription: 'invalid' }, headers: headers
|
||||||
|
|
||||||
|
expect(response)
|
||||||
|
.to have_http_status(400)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'PUT /api/v1/push/subscription' do
|
describe 'PUT /api/v1/push/subscription' do
|
||||||
@ -133,6 +140,13 @@ RSpec.describe 'API V1 Push Subscriptions' do
|
|||||||
policy: alerts_payload[:data][:policy]
|
policy: alerts_payload[:data][:policy]
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'gracefully handles invalid nested params' do
|
||||||
|
put api_v1_push_subscription_path(endpoint_push_subscription), params: { data: 'invalid' }, headers: headers
|
||||||
|
|
||||||
|
expect(response)
|
||||||
|
.to have_http_status(400)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'GET /api/v1/push/subscription' do
|
describe 'GET /api/v1/push/subscription' do
|
||||||
|
@ -52,4 +52,28 @@ RSpec.describe 'API Web Push Subscriptions' do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'POST /api/web/push_subscriptions' do
|
||||||
|
before { sign_in Fabricate :user }
|
||||||
|
|
||||||
|
it 'gracefully handles invalid nested params' do
|
||||||
|
post api_web_push_subscriptions_path, params: { subscription: 'invalid' }
|
||||||
|
|
||||||
|
expect(response)
|
||||||
|
.to have_http_status(400)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'PUT /api/web/push_subscriptions' do
|
||||||
|
before { sign_in Fabricate :user }
|
||||||
|
|
||||||
|
let(:subscription) { Fabricate :web_push_subscription }
|
||||||
|
|
||||||
|
it 'gracefully handles invalid nested params' do
|
||||||
|
put api_web_push_subscription_path(subscription), params: { data: 'invalid' }
|
||||||
|
|
||||||
|
expect(response)
|
||||||
|
.to have_http_status(400)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user