Skip to content

Commit

Permalink
revert to SignalwireWebhookAuthentication
Browse files Browse the repository at this point in the history
  • Loading branch information
jpsantosbh committed Oct 26, 2023
1 parent 9927d0f commit f00c9a9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

module Rack

class SwWebhookAuthentication
class SignalwireWebhookAuthentication

FORM_URLENCODED_MEDIA_TYPE = Rack::MediaType.type('application/x-www-form-urlencoded')

Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
require 'spec_helper'
require 'rack/mock'
require 'rack/sw_webhook_authentication'
require 'rack/signalwire_webhook_authentication'

describe Rack::SwWebhookAuthentication do
describe Rack::SignalwireWebhookAuthentication do
before do
@app = ->(_env) { [200, { 'Content-Type' => 'text/plain' }, ['Hello']] }
end

describe 'new' do
it 'should initialize with an app, auth token and a path' do
expect do
Rack::SwWebhookAuthentication.new(@app, 'ABC', /\/voice/)
Rack::SignalwireWebhookAuthentication.new(@app, 'ABC', /\/voice/)
end.not_to raise_error
end

it 'should initialize with an app, auth token and paths' do
expect do
Rack::SwWebhookAuthentication.new(@app, 'ABC', /\/voice/, /\/sms/)
Rack::SignalwireWebhookAuthentication.new(@app, 'ABC', /\/voice/, /\/sms/)
end.not_to raise_error
end

it 'should initialize with an app, dynamic token and paths' do
expect do
Rack::SwWebhookAuthentication.new(@app, nil, /\/voice/, /\/sms/)
Rack::SignalwireWebhookAuthentication.new(@app, nil, /\/voice/, /\/sms/)
end.not_to raise_error
end
end
Expand All @@ -34,7 +34,7 @@
expect_any_instance_of(Rack::Request).to receive(:post?).and_return(true)
expect_any_instance_of(Rack::Request).to receive(:media_type).and_return(Rack::MediaType.type('application/x-www-form-urlencoded'))
expect_any_instance_of(Rack::Request).to receive(:POST).and_return({ 'AccountSid' => account_sid })
@middleware = Rack::SwWebhookAuthentication.new(@app, nil, /\/voice/) { |asid| auth_token }
@middleware = Rack::SignalwireWebhookAuthentication.new(@app, nil, /\/voice/) { |asid| auth_token }
request_validator = double('RequestValidator')
expect(Twilio::Security::RequestValidator).to receive(:new).with(auth_token).and_return(request_validator)
expect(request_validator).to receive(:validate).and_return(true)
Expand All @@ -46,7 +46,7 @@

describe 'calling against one path' do
before do
@middleware = Rack::SwWebhookAuthentication.new(@app, 'ABC', /\/voice/)
@middleware = Rack::SignalwireWebhookAuthentication.new(@app, 'ABC', /\/voice/)
end

it 'should not intercept when the path doesn\'t match' do
Expand Down Expand Up @@ -77,7 +77,7 @@

describe 'calling against many paths' do
before do
@middleware = Rack::SwWebhookAuthentication.new(@app, 'ABC', /\/voice/, /\/sms/)
@middleware = Rack::SignalwireWebhookAuthentication.new(@app, 'ABC', /\/voice/, /\/sms/)
end

it 'should not intercept when the path doesn\'t match' do
Expand Down Expand Up @@ -108,7 +108,7 @@

describe 'validating non-form-data POST payloads' do
it 'should fail if the body does not validate' do
middleware = Rack::SwWebhookAuthentication.new(@app, 'qwerty', /\/test/)
middleware = Rack::SignalwireWebhookAuthentication.new(@app, 'qwerty', /\/test/)
input = StringIO.new('{"message": "a post body that does not match the bodySHA256"}')

request = Rack::MockRequest.env_for(
Expand All @@ -125,7 +125,7 @@
end

it 'should validate if the body signature is correct' do
middleware = Rack::SwWebhookAuthentication.new(@app, 'qwerty', /\/test/)
middleware = Rack::SignalwireWebhookAuthentication.new(@app, 'qwerty', /\/test/)
input = StringIO.new('{"message": "a post body"}')

request = Rack::MockRequest.env_for(
Expand All @@ -142,7 +142,7 @@
end

it 'should validate even if a previous middleware read the body first' do
middleware = Rack::SwWebhookAuthentication.new(@app, 'qwerty', /\/test/)
middleware = Rack::SignalwireWebhookAuthentication.new(@app, 'qwerty', /\/test/)
input = StringIO.new('{"message": "a post body"}')

request = Rack::MockRequest.env_for(
Expand All @@ -162,7 +162,7 @@

describe 'validating application/x-www-form-urlencoded POST payloads' do
it 'should fail if the body does not validate' do
middleware = Rack::SwWebhookAuthentication.new(@app, 'qwerty', /\/test/)
middleware = Rack::SignalwireWebhookAuthentication.new(@app, 'qwerty', /\/test/)

request = Rack::MockRequest.env_for(
'https://example.com/test',
Expand All @@ -178,7 +178,7 @@
end

it 'should validate if the body signature is correct' do
middleware = Rack::SwWebhookAuthentication.new(@app, 'qwerty', /\/test/)
middleware = Rack::SignalwireWebhookAuthentication.new(@app, 'qwerty', /\/test/)

request = Rack::MockRequest.env_for(
'https://example.com/test',
Expand Down

0 comments on commit f00c9a9

Please sign in to comment.