faye-authentication 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,124 @@
1
+ # src_files
2
+ #
3
+ # Return an array of filepaths relative to src_dir to include before jasmine specs.
4
+ # Default: []
5
+ #
6
+ # EXAMPLE:
7
+ #
8
+ # src_files:
9
+ # - lib/source1.js
10
+ # - lib/source2.js
11
+ # - dist/**/*.js
12
+ #
13
+ src_files:
14
+ - app/assets/javascripts/*.js
15
+ - spec/utils/javascripts/*.js
16
+
17
+ # stylesheets
18
+ #
19
+ # Return an array of stylesheet filepaths relative to src_dir to include before jasmine specs.
20
+ # Default: []
21
+ #
22
+ # EXAMPLE:
23
+ #
24
+ # stylesheets:
25
+ # - css/style.css
26
+ # - stylesheets/*.css
27
+ #
28
+ stylesheets:
29
+ - stylesheets/**/*.css
30
+
31
+ # helpers
32
+ #
33
+ # Return an array of filepaths relative to spec_dir to include before jasmine specs.
34
+ # Default: ["helpers/**/*.js"]
35
+ #
36
+ # EXAMPLE:
37
+ #
38
+ # helpers:
39
+ # - helpers/**/*.js
40
+ #
41
+ helpers:
42
+ - 'helpers/**/*.js'
43
+
44
+ # spec_files
45
+ #
46
+ # Return an array of filepaths relative to spec_dir to include.
47
+ # Default: ["**/*[sS]pec.js"]
48
+ #
49
+ # EXAMPLE:
50
+ #
51
+ # spec_files:
52
+ # - **/*[sS]pec.js
53
+ #
54
+ spec_files:
55
+ - '**/*[sS]pec.js'
56
+
57
+ # src_dir
58
+ #
59
+ # Source directory path. Your src_files must be returned relative to this path. Will use root if left blank.
60
+ # Default: project root
61
+ #
62
+ # EXAMPLE:
63
+ #
64
+ # src_dir: public
65
+ #
66
+ src_dir:
67
+
68
+ # spec_dir
69
+ #
70
+ # Spec directory path. Your spec_files must be returned relative to this path.
71
+ # Default: spec/javascripts
72
+ #
73
+ # EXAMPLE:
74
+ #
75
+ # spec_dir: spec/javascripts
76
+ #
77
+ spec_dir:
78
+
79
+ # spec_helper
80
+ #
81
+ # Ruby file that Jasmine server will require before starting.
82
+ # Returned relative to your root path
83
+ # Default spec/javascripts/support/jasmine_helper.rb
84
+ #
85
+ # EXAMPLE:
86
+ #
87
+ # spec_helper: spec/javascripts/support/jasmine_helper.rb
88
+ #
89
+ spec_helper: spec/javascripts/support/jasmine_helper.rb
90
+
91
+ # boot_dir
92
+ #
93
+ # Boot directory path. Your boot_files must be returned relative to this path.
94
+ # Default: Built in boot file
95
+ #
96
+ # EXAMPLE:
97
+ #
98
+ # boot_dir: spec/javascripts/support/boot
99
+ #
100
+ boot_dir:
101
+
102
+ # boot_files
103
+ #
104
+ # Return an array of filepaths relative to boot_dir to include in order to boot Jasmine
105
+ # Default: Built in boot file
106
+ #
107
+ # EXAMPLE
108
+ #
109
+ # boot_files:
110
+ # - '**/*.js'
111
+ #
112
+ boot_files:
113
+
114
+ # rack_options
115
+ #
116
+ # Extra options to be passed to the rack server
117
+ # by default, Port and AccessLog are passed.
118
+ #
119
+ # This is an advanced options, and left empty by default
120
+ #
121
+ # EXAMPLE
122
+ #
123
+ # rack_options:
124
+ # server: 'thin'
@@ -0,0 +1,29 @@
1
+ #Use this file to set/override Jasmine configuration options
2
+ #You can remove it if you don't need it.
3
+ #This file is loaded *after* jasmine.yml is interpreted.
4
+ #
5
+ #Example: using a different boot file.
6
+ #Jasmine.configure do |config|
7
+ # config.boot_dir = '/absolute/path/to/boot_dir'
8
+ # config.boot_files = lambda { ['/absolute/path/to/boot_dir/file.js'] }
9
+ #end
10
+ #
11
+
12
+ require 'faye'
13
+ require 'faye/authentication'
14
+ require 'rack'
15
+
16
+ FAYE_SECRET_KEY = 'macaroni'
17
+
18
+ # Start faye web server.
19
+ fork do
20
+ Faye::WebSocket.load_adapter('thin')
21
+ faye = Faye::RackAdapter.new(:mount => '/faye')
22
+ faye.add_extension Faye::Authentication::Extension.new(FAYE_SECRET_KEY)
23
+ Rack::Handler::Thin.run faye, :Port => 9296
24
+ end.tap do |id|
25
+ parent = $$
26
+ at_exit {
27
+ Process.kill("KILL", id) if $$ == parent # Only if the parent process exits
28
+ }
29
+ end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+ require 'faye/authentication/extension'
3
+
4
+ describe Faye::Authentication::Extension do
5
+
6
+ let(:secret) { 'macaroni' }
7
+ let(:extension) { Faye::Authentication::Extension.new(secret) }
8
+
9
+ it 'does not add an eror if the message is correctly signed' do
10
+ message = {'channel' => '/foo/bar', 'clientId' => '42', 'text' => 'whatever'}
11
+ signature = Faye::Authentication.sign(message, secret)
12
+ message['signature'] = signature
13
+
14
+ result = nil
15
+
16
+ extension.incoming(message, ->(m) { result = m });
17
+
18
+ expect(result).to_not have_key('error')
19
+ end
20
+
21
+ it 'adds an eror if the message is not signed' do
22
+ message = {'channel' => '/foo/bar', 'clientId' => '42', 'text' => 'whatever'}
23
+ result = nil
24
+ extension.incoming(message, ->(m) { result = m });
25
+
26
+ expect(result).to have_key('error')
27
+ end
28
+
29
+ it 'adds an error if the signature is incorrect' do
30
+ message = {'channel' => '/foo/bar', 'clientId' => '42', 'text' => 'whatever', 'signature' => 'hello'}
31
+ result = nil
32
+ extension.incoming(message, ->(m) { result = m });
33
+
34
+ expect(result).to have_key('error')
35
+ end
36
+
37
+ ['/meta/handshake', '/meta/connect', '/meta/unsubscribe', '/meta/disconnect'].each do |channel|
38
+ it "does not check the signature for #{channel}" do
39
+ message = {'channel' => channel, 'clientId' => '42', 'text' => 'whatever', 'signature' => 'hello'}
40
+ expect(Faye::Authentication).to_not receive(:valid?)
41
+ extension.incoming(message, ->(_) {});
42
+ end
43
+ end
44
+
45
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+ require 'faye/authentication'
3
+
4
+ describe Faye::Authentication::HTTPClient do
5
+
6
+ describe '.publish' do
7
+
8
+ it 'should publish a HTTP request with correct params' do
9
+ message = {'channel' => '/foo/bar', 'data' => 'hello', 'clientId' => 'http'}
10
+ message['signature'] = Faye::Authentication.sign(message, 'my private key')
11
+ request = stub_request(:post, "http://www.example.com").with(:body => {:message => JSON.dump(message)}).to_return(:status => 200, :body => "", :headers => {})
12
+ Faye::Authentication::HTTPClient.publish('http://www.example.com', '/foo/bar', "hello", 'my private key')
13
+ expect(request).to have_been_made
14
+ end
15
+
16
+ end
17
+
18
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+ require 'faye/authentication'
3
+
4
+ describe Faye::Authentication do
5
+
6
+ let(:secret) { 'helloworld' }
7
+
8
+ describe '#valid?' do
9
+ it 'returns true if the message is correctly signed' do
10
+ message = {'channel' => '/foo/bar', 'clientId' => '42', 'text' => 'whatever'}
11
+ signature = Faye::Authentication.sign(message, secret)
12
+ message['signature'] = signature
13
+ expect(Faye::Authentication.valid?(message, secret)).to be(true)
14
+ end
15
+
16
+ it 'returns false if the message if keys differ' do
17
+ message = {'channel' => '/foo/bar', 'clientId' => '42', 'text' => 'whatever'}
18
+ signature = Faye::Authentication.sign(message, secret)
19
+ message['signature'] = signature
20
+ expect(Faye::Authentication.valid?(message, secret + 'foo')).to be(false)
21
+ end
22
+ end
23
+
24
+ end
@@ -0,0 +1,86 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
4
+ # file to always be loaded, without a need to explicitly require it in any files.
5
+ #
6
+ # Given that it is always loaded, you are encouraged to keep this file as
7
+ # light-weight as possible. Requiring heavyweight dependencies from this file
8
+ # will add to the boot time of your test suite on EVERY test run, even for an
9
+ # individual file that may not need all of that loaded. Instead, make a
10
+ # separate helper file that requires this one and then use it only in the specs
11
+ # that actually need it.
12
+ #
13
+ # The `.rspec` file also contains a few flags that are not defaults but that
14
+ # users commonly want.
15
+ #
16
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
17
+
18
+ require 'webmock/rspec'
19
+
20
+ RSpec.configure do |config|
21
+ # The settings below are suggested to provide a good initial experience
22
+ # with RSpec, but feel free to customize to your heart's content.
23
+ =begin
24
+ # These two settings work together to allow you to limit a spec run
25
+ # to individual examples or groups you care about by tagging them with
26
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
27
+ # get run.
28
+ config.filter_run :focus
29
+ config.run_all_when_everything_filtered = true
30
+
31
+ # Many RSpec users commonly either run the entire suite or an individual
32
+ # file, and it's useful to allow more verbose output when running an
33
+ # individual spec file.
34
+ if config.files_to_run.one?
35
+ # RSpec filters the backtrace by default so as not to be so noisy.
36
+ # This causes the full backtrace to be printed when running a single
37
+ # spec file (e.g. to troubleshoot a particular spec failure).
38
+ config.full_backtrace = true
39
+
40
+ # Use the documentation formatter for detailed output,
41
+ # unless a formatter has already been configured
42
+ # (e.g. via a command-line flag).
43
+ config.default_formatter = 'doc'
44
+ end
45
+
46
+ # Print the 10 slowest examples and example groups at the
47
+ # end of the spec run, to help surface which specs are running
48
+ # particularly slow.
49
+ config.profile_examples = 10
50
+
51
+ # Run specs in random order to surface order dependencies. If you find an
52
+ # order dependency and want to debug it, you can fix the order by providing
53
+ # the seed, which is printed after each run.
54
+ # --seed 1234
55
+ config.order = :random
56
+
57
+ # Seed global randomization in this process using the `--seed` CLI option.
58
+ # Setting this allows you to use `--seed` to deterministically reproduce
59
+ # test failures related to randomization by passing the same `--seed` value
60
+ # as the one that triggered the failure.
61
+ Kernel.srand config.seed
62
+
63
+ # rspec-expectations config goes here. You can use an alternate
64
+ # assertion/expectation library such as wrong or the stdlib/minitest
65
+ # assertions if you prefer.
66
+ config.expect_with :rspec do |expectations|
67
+ # Enable only the newer, non-monkey-patching expect syntax.
68
+ # For more details, see:
69
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
70
+ expectations.syntax = :expect
71
+ end
72
+
73
+ # rspec-mocks config goes here. You can use an alternate test double
74
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
75
+ config.mock_with :rspec do |mocks|
76
+ # Enable only the newer, non-monkey-patching expect syntax.
77
+ # For more details, see:
78
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
79
+ mocks.syntax = :expect
80
+
81
+ # Prevents you from mocking or stubbing a method that does not exist on
82
+ # a real object. This is generally recommended.
83
+ mocks.verify_partial_doubles = true
84
+ end
85
+ =end
86
+ end