spec/integrations/webhook_spec.rb in onfido-0.4.0 vs spec/integrations/webhook_spec.rb in onfido-0.5.0
- old
+ new
@@ -44,6 +44,48 @@
response = webhook.all
expect(response["webhooks"][0]["id"]).to_not be_nil
expect(response["webhooks"][1]["id"]).to_not be_nil
end
end
+
+ describe ".valid?" do
+ subject(:valid?) do
+ described_class.valid?(request_body, request_signature, token)
+ end
+
+ let(:request_body) { '{"foo":"bar"}' }
+ let(:request_signature) { 'fdab9db604d33297741b43b9fc9536028d09dca3' }
+ let(:token) { 'very_secret_token' }
+
+ it { is_expected.to be(true) }
+
+ context "with an invalid signature" do
+ let(:request_signature) { '2f3d7727ff9a32a7c87072ce514df1f6d3228bec' }
+ it { is_expected.to be(false) }
+ end
+
+ context "with a nil request signature" do
+ let(:request_signature) { nil }
+ specify { expect { valid? }.to raise_error(ArgumentError) }
+ end
+
+ context "with a token other than the one used to sign the request" do
+ let(:token) { "quite_secret_token" }
+ it { is_expected.to be(false) }
+ end
+
+ context "with a nil token" do
+ let(:token) { nil }
+ specify { expect { valid? }.to raise_error(ArgumentError) }
+ end
+
+ context "with a modified request body" do
+ let(:request_body) { '{"bar":"baz"}' }
+ it { is_expected.to be(false) }
+ end
+
+ context "with a nil request body" do
+ let(:request_body) { nil }
+ specify { expect { valid? }.to raise_error(ArgumentError) }
+ end
+ end
end