Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise Webpush::Unauthorized on HTTP 403 #59

Merged
merged 1 commit into from
Jan 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/webpush/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def perform
raise ExpiredSubscription.new(resp, uri.host)
elsif resp.is_a?(Net::HTTPNotFound) # 404
raise InvalidSubscription.new(resp, uri.host)
elsif resp.is_a?(Net::HTTPUnauthorized) || # 401, Mozilla autopush
elsif resp.is_a?(Net::HTTPUnauthorized) || resp.is_a?(Net::HTTPForbidden) || # 401, 403
resp.is_a?(Net::HTTPBadRequest) && resp.message == "UnauthorizedRegistration" # 400, Google FCM
raise Unauthorized.new(resp, uri.host)
elsif resp.is_a?(Net::HTTPRequestEntityTooLarge) # 413
Expand Down
6 changes: 5 additions & 1 deletion spec/webpush_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@
expect { subject }.to raise_error(Webpush::ExpiredSubscription)
end

it 'raises Unauthorized if the API returns a 401 Error or 400 with specific message' do
it 'raises Unauthorized if the API returns a 401 Error, a 403 Error or 400 with specific message' do
stub_request(:post, expected_endpoint).
to_return(status: 401, body: "", headers: {})
expect { subject }.to raise_error(Webpush::Unauthorized)

stub_request(:post, expected_endpoint).
to_return(status: 403, body: "", headers: {})
expect { subject }.to raise_error(Webpush::Unauthorized)

stub_request(:post, expected_endpoint).
to_return(status: [400, "UnauthorizedRegistration"], body: "", headers: {})
expect { subject }.to raise_error(Webpush::Unauthorized)
Expand Down