rainforest_auth 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 59e89bf38dee455ed6290f109d81693b0bd6fa47
4
- data.tar.gz: a72007dd71e10ec92f00ebd690e829a46517b856
3
+ metadata.gz: be5c19d4c8f4d0e01ba5d94261ff763089488870
4
+ data.tar.gz: 91b7aba39ce35a2e527cca72511783f67a7f379e
5
5
  SHA512:
6
- metadata.gz: 2011c1660738e280e539d28aafb4522718e0aa6a4fec84a19baf6e8bab03f58c2b673cbaaaaf7a2a39fce6c0ad483d9c432c67f0cdbea779b78a7c33b21577cf
7
- data.tar.gz: 700a154486f9722a64a53ec802136aeb9e8dace2842f950f7aa137b106797a7401c739d15fbe76a07392986d7f25c8fc004694788d0df7af6c40a030974c42f0
6
+ metadata.gz: 9553dd2fd085cae0cf93dd03e0f83df97c6c19217165b85f1473900e2bdb0164504c3ca65163ffccd06b1268ec9fd341a8f65e984503dda8e616c724feb0eab4
7
+ data.tar.gz: c91ba2329d9d06ba4a91ba02245978d9cc9e11d6c2122c2ac44a731c87e69e64f4b741dda394978018ba2dd835360a786393efc699f44b15663088673f1bb013
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ .idea
2
+ coverage
3
+ rainforest_auth-*.gem
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format=nested
3
+ --require spec_helper
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use 2.1.1@rainforest-auth --create
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ rvm:
2
+ - 2.1.1
3
+ - 2.1.0
4
+ - 2.0.0
5
+ - 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ group :development, :test do
6
+ gem "rake", ">= 0.8.7"
7
+ end
8
+
9
+ group :test do
10
+ gem "jruby-openssl", :platform => :jruby
11
+ gem "bundler"
12
+ gem "rspec", ">= 2.0"
13
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,30 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rainforest_auth (0.0.10)
5
+ json
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ diff-lcs (1.2.5)
11
+ json (1.8.1)
12
+ rake (10.1.1)
13
+ rspec (2.14.1)
14
+ rspec-core (~> 2.14.0)
15
+ rspec-expectations (~> 2.14.0)
16
+ rspec-mocks (~> 2.14.0)
17
+ rspec-core (2.14.8)
18
+ rspec-expectations (2.14.5)
19
+ diff-lcs (>= 1.1.3, < 2.0)
20
+ rspec-mocks (2.14.6)
21
+
22
+ PLATFORMS
23
+ ruby
24
+
25
+ DEPENDENCIES
26
+ bundler
27
+ jruby-openssl
28
+ rainforest_auth!
29
+ rake (>= 0.8.7)
30
+ rspec (>= 2.0)
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Michael Bleigh and Intridea, Inc.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,93 @@
1
+ [![Gem Version](https://badge.fury.io/rb/rainforest_auth.png)](http://badge.fury.io/rb/rainforest_auth)
2
+ [![Build Status](https://travis-ci.org/rainforestapp/auth.png?branch=master)](https://travis-ci.org/rainforestapp/auth)
3
+ [![Dependency Status](https://gemnasium.com/rainforestapp/auth.png)](https://gemnasium.com/rainforestapp/auth)
4
+
5
+ # Rainforest Auth
6
+
7
+ Allows verification of [Rainforest](https://www.rainforestqa.com/) webhook messages using your private API key.
8
+
9
+ ## Installation
10
+
11
+ Rainforest Auth is available as a gem, to install it just install the gem:
12
+
13
+ gem install rainforest_auth
14
+
15
+ If you're using Bundler, add the gem to Gemfile.
16
+
17
+ gem 'rainforest_auth'
18
+
19
+ Then run bundle install.
20
+
21
+ ## Where can I find my API key?
22
+
23
+ You can find your API key for Rainforest under the [Accounts setting page](https://app.rainforestqa.com/settings/account). If you get stuck finding this, please [reach out](mailto:5h9w4xa0@incoming.intercom.io)!
24
+
25
+ ## Examples
26
+
27
+ The following example recieves a 'before_run' notification from Rainforest, authenticates it, does a task for you and then notifies Rainforest to continue.
28
+
29
+ ```ruby
30
+ require "rainforest/auth"
31
+ require "httparty"
32
+
33
+ class RainforestCallbacksController < ApplicationController
34
+ def create
35
+ # Check the callback is valid
36
+ rainforest_auther.run_if_valid(params[:digest], params[:callback_type], params[:options]) do
37
+
38
+ # Work out what to do
39
+ case params[:callback_type]
40
+ when 'before_run'
41
+ # Reset the database?
42
+ when 'after_run'
43
+ # Trigger deploy!
44
+ end
45
+
46
+ # Get the callback url for this run
47
+ callback_url = rainforest_auther.get_run_callback(params[:options]['run_id'], params[:callback_type])
48
+
49
+ # Notify Rainforest you are ready for a run to start
50
+ HTTParty.post callback_url
51
+ end
52
+ end
53
+
54
+ private
55
+ def rainforest_auther
56
+ @rainforest_auther ||= RainforestAuth.new 'YOUR_KEY_HERE'
57
+ end
58
+ end
59
+ ```
60
+
61
+ Checking if the signature is valid;
62
+
63
+ ```ruby
64
+ require "rainforest/auth"
65
+
66
+ r_auth = RainforestAuth.new('YOUR_KEY_HERE')
67
+
68
+ # Check the digest is correct
69
+ if r_auth.verify digest, callback_type, options
70
+ puts "The digest was valid."
71
+ else
72
+ puts "The digest was invalid!"
73
+ end
74
+ ```
75
+
76
+ Running a block if the signature is valid;
77
+
78
+ ```ruby
79
+ require "rainforest/auth"
80
+
81
+ r_auth = RainforestAuth.new('YOUR_KEY_HERE')
82
+
83
+ # Run a block if it works
84
+ r_auth.run_if_valid(digest, callback_type, options) {
85
+ puts "The digest was valid."
86
+ }
87
+ ```
88
+
89
+ ## License
90
+ MIT License. See [LICENSE](/rainforestapp/auth/blob/master/LICENSE) for details.
91
+
92
+ ## Copyright
93
+ Copyright (c) 2014 CLDRDR, Inc.
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require 'rspec/core/rake_task'
2
+
3
+ RSpec::Core::RakeTask.new(:spec)
4
+
5
+ task :default => :spec
@@ -0,0 +1,15 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "rainforest_auth"
3
+ s.version = "0.0.10"
4
+ s.date = "2014-02-13"
5
+ s.summary = "Authentication of messages for Rainforest webhooks"
6
+ s.description = "Signs / Authenticates messages"
7
+ s.authors = ["Russell Smith"]
8
+ s.email = ["russ@rainforestqa.com"]
9
+ s.files = ["lib/rainforest/auth.rb"]
10
+ s.homepage = "https://www.rainforestqa.com/"
11
+ s.require_paths = ["lib"]
12
+ s.files = `git ls-files`.split("\n")
13
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ s.add_dependency('json')
15
+ end
@@ -0,0 +1,102 @@
1
+ describe RainforestAuth do
2
+ context "#new" do
3
+ it "stores the key" do
4
+ auth = RainforestAuth.new('key')
5
+ auth.key.should == 'key'
6
+ end
7
+
8
+ it "returns itself" do
9
+ RainforestAuth.new('key').should be_an_instance_of RainforestAuth
10
+ end
11
+ end
12
+
13
+ context ".get_run_callback" do
14
+ before :all do
15
+ @run_id = '123456'
16
+ @auth = RainforestAuth.new('key')
17
+
18
+ @url = @auth.get_run_callback(@run_id, 'before_run')
19
+ @url_split = @url.split '/'
20
+ end
21
+
22
+ it "returns a url" do
23
+ @url[0..4].should == 'https'
24
+ end
25
+
26
+ it "has the correct run_id" do
27
+ @url_split[7].should == @run_id
28
+ end
29
+
30
+ it "has the correct action" do
31
+ @url_split[8].should == 'before_run'
32
+ end
33
+
34
+ it "has the correct digest" do
35
+ digest = @url_split[9]
36
+ @auth.verify(digest, 'before_run', {:run_id => @run_id}).should be_true
37
+ end
38
+ end
39
+
40
+ context ".sign" do
41
+ before :all do
42
+ @auth = RainforestAuth.new('key')
43
+ end
44
+
45
+ it "returns the expected signature" do
46
+ @auth.sign('test', {:option => 1}).should == '5957ba2707a51852d32309d16184e8adce9c4d8e'
47
+ end
48
+
49
+ it "changes the signature with different data" do
50
+ @auth.sign('test', {:option => 2}).should_not == '5957ba2707a51852d32309d16184e8adce9c4d8e'
51
+ end
52
+
53
+ it "works with no options parameter" do
54
+ @auth.sign('test').should == '0a41bdf26fac08a89573a7f5efe0a5145f2730df'
55
+ end
56
+ end
57
+
58
+ context ".verify" do
59
+ before :all do
60
+ @auth = RainforestAuth.new('key')
61
+ @digest = '5957ba2707a51852d32309d16184e8adce9c4d8e'
62
+ end
63
+
64
+ it "returns true for a valid signature" do
65
+ @auth.verify(@digest, 'test', {:option => 1}).should be_true
66
+ end
67
+
68
+ it "returns false for a bad signature" do
69
+ @auth.verify(@digest, 'test', {:option => 2}).should be_false
70
+ end
71
+
72
+ it "works with no options parameter" do
73
+ @auth.verify('0a41bdf26fac08a89573a7f5efe0a5145f2730df', 'test').should be_true
74
+ end
75
+ end
76
+
77
+ context ".run_if_valid" do
78
+ before :all do
79
+ @auth = RainforestAuth.new('key')
80
+ @object = "test"
81
+ @object.stub(:some_method) { 3 }
82
+
83
+ @digest = '5957ba2707a51852d32309d16184e8adce9c4d8e'
84
+ end
85
+
86
+ it "executes the block if there is a valid signature" do
87
+ @object.should_receive :some_method
88
+
89
+ @auth.run_if_valid(@digest, 'test', {:option => 1}) {
90
+ @object.some_method
91
+ }
92
+ end
93
+
94
+ it "does not execute the block for invalid signatures" do
95
+ @object.should_not_receive :some_method
96
+
97
+ @auth.run_if_valid(@digest, 'test', {:option => 2}) {
98
+ @object.some_method
99
+ }
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,10 @@
1
+ require 'rspec'
2
+
3
+ ENV["RACK_ENV"] ||= 'test'
4
+
5
+ require File.expand_path('../lib/rainforest/auth', File.dirname(__FILE__))
6
+
7
+ # Configure rspec
8
+ RSpec.configure do |config|
9
+ config.mock_with :rspec
10
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rainforest_auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Russell Smith
@@ -31,7 +31,19 @@ executables: []
31
31
  extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
+ - ".gitignore"
35
+ - ".rspec"
36
+ - ".rvmrc"
37
+ - ".travis.yml"
38
+ - Gemfile
39
+ - Gemfile.lock
40
+ - LICENSE
41
+ - README.md
42
+ - Rakefile
34
43
  - lib/rainforest/auth.rb
44
+ - rainforest_auth.gemspec
45
+ - spec/rainforest_auth_spec.rb
46
+ - spec/spec_helper.rb
35
47
  homepage: https://www.rainforestqa.com/
36
48
  licenses: []
37
49
  metadata: {}
@@ -55,4 +67,6 @@ rubygems_version: 2.2.2
55
67
  signing_key:
56
68
  specification_version: 4
57
69
  summary: Authentication of messages for Rainforest webhooks
58
- test_files: []
70
+ test_files:
71
+ - spec/rainforest_auth_spec.rb
72
+ - spec/spec_helper.rb