spec/lib/faye/authentication/server_extension_spec.rb in faye-authentication-0.4.0 vs spec/lib/faye/authentication/server_extension_spec.rb in faye-authentication-1.6.0
- old
+ new
@@ -1,12 +1,13 @@
require 'spec_helper'
-require 'faye/authentication/server_extension'
+require 'faye/authentication'
describe Faye::Authentication::ServerExtension do
let(:secret) { 'macaroni' }
let(:extension) { Faye::Authentication::ServerExtension.new(secret) }
+ let(:channel) { '/channel' }
describe '#incoming' do
shared_examples 'signature_has_error' do
it 'adds an error' do
subject
@@ -20,35 +21,24 @@
expect(@result).to_not have_key('error')
end
end
shared_examples 'authentication_actions' do
- context 'not signed' do
- context '/public' do
- context 'no globbing' do
- let(:channel) { '/public/foo' }
- it_should_behave_like 'signature_has_no_error'
- end
+ context 'does not require signature' do
+ before { expect(Faye::Authentication).to receive(:authentication_required?).with(message, {}).and_return(false) }
+ it_should_behave_like 'signature_has_no_error'
+ end
- context 'globbing' do
- let(:channel) { '/public/foo/*'}
- it_should_behave_like 'signature_has_error'
- end
+ context 'requires signature' do
+ before { expect(Faye::Authentication).to receive(:authentication_required?).with(message, {}).and_return(true) }
+ context 'with signature' do
+ before { message['signature'] = Faye::Authentication.sign(message.merge({'channel' => channel}), secret) }
+ it_should_behave_like 'signature_has_no_error'
end
- context 'not public' do
- context 'not signed' do
- let(:channel) { '/whatever' }
- it_should_behave_like 'signature_has_error'
- end
-
- context 'signed' do
- let(:channel) { '/foo/bar' }
- before { message['signature'] = Faye::Authentication.sign(message.merge({'channel' => channel}), secret) }
- it_should_behave_like 'signature_has_no_error'
- end
-
+ context 'without signature' do
+ it_should_behave_like 'signature_has_error'
end
end
end
let(:message) { {'channel' => channel, 'clientId' => '42', 'text' => 'whatever'} }
@@ -68,10 +58,10 @@
end
['/meta/handshake', '/meta/connect', '/meta/unsubscribe', '/meta/disconnect'].each do |channel|
it "does not check the signature for #{channel}" do
message = {'channel' => channel, 'clientId' => '42', 'text' => 'whatever', 'signature' => 'hello'}
- expect(Faye::Authentication).to_not receive(:valid?)
+ expect(Faye::Authentication).to_not receive(:validate)
extension.incoming(message, ->(_) {});
end
end
end