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 +4 -4
- data/.gitignore +3 -0
- data/.rspec +3 -0
- data/.rvmrc +1 -0
- data/.travis.yml +5 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +30 -0
- data/LICENSE +20 -0
- data/README.md +93 -0
- data/Rakefile +5 -0
- data/rainforest_auth.gemspec +15 -0
- data/spec/rainforest_auth_spec.rb +102 -0
- data/spec/spec_helper.rb +10 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be5c19d4c8f4d0e01ba5d94261ff763089488870
|
4
|
+
data.tar.gz: 91b7aba39ce35a2e527cca72511783f67a7f379e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9553dd2fd085cae0cf93dd03e0f83df97c6c19217165b85f1473900e2bdb0164504c3ca65163ffccd06b1268ec9fd341a8f65e984503dda8e616c724feb0eab4
|
7
|
+
data.tar.gz: c91ba2329d9d06ba4a91ba02245978d9cc9e11d6c2122c2ac44a731c87e69e64f4b741dda394978018ba2dd835360a786393efc699f44b15663088673f1bb013
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use 2.1.1@rainforest-auth --create
|
data/Gemfile
ADDED
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,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
|
data/spec/spec_helper.rb
ADDED
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.
|
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
|