wix-apps 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.rvmrc +52 -0
- data/.travis.yml +12 -0
- data/Gemfile +11 -0
- data/Guardfile +5 -0
- data/LICENSE +22 -0
- data/README.md +30 -0
- data/Rakefile +9 -0
- data/lib/wix-apps.rb +9 -0
- data/lib/wix-apps/signed_instance.rb +65 -0
- data/lib/wix-apps/signed_instance_middleware.rb +65 -0
- data/lib/wix-apps/version.rb +5 -0
- data/spec/lib/wix-apps/signed_instance_middleware_spec.rb +108 -0
- data/spec/lib/wix-apps/signed_instance_spec.rb +104 -0
- data/spec/spec_helper.rb +6 -0
- data/spec/support/config.rb +3 -0
- data/wix-apps.gemspec +25 -0
- metadata +153 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
# This is an RVM Project .rvmrc file, used to automatically load the ruby
|
4
|
+
# development environment upon cd'ing into the directory
|
5
|
+
|
6
|
+
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
|
7
|
+
# Only full ruby name is supported here, for short names use:
|
8
|
+
# echo "rvm use 1.9.3" > .rvmrc
|
9
|
+
environment_id="ruby-1.9.3-p194@wix-apps"
|
10
|
+
|
11
|
+
# Uncomment the following lines if you want to verify rvm version per project
|
12
|
+
# rvmrc_rvm_version="1.13.4 (master)" # 1.10.1 seams as a safe start
|
13
|
+
# eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
|
14
|
+
# echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
|
15
|
+
# return 1
|
16
|
+
# }
|
17
|
+
|
18
|
+
# First we attempt to load the desired environment directly from the environment
|
19
|
+
# file. This is very fast and efficient compared to running through the entire
|
20
|
+
# CLI and selector. If you want feedback on which environment was used then
|
21
|
+
# insert the word 'use' after --create as this triggers verbose mode.
|
22
|
+
if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
|
23
|
+
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
|
24
|
+
then
|
25
|
+
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
|
26
|
+
[[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
|
27
|
+
\. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
|
28
|
+
if [[ $- == *i* ]] # check for interactive shells
|
29
|
+
then echo "Using: $(tput setaf 2)$GEM_HOME$(tput sgr0)" # show the user the ruby and gemset they are using in green
|
30
|
+
else echo "Using: $GEM_HOME" # don't use colors in non-interactive shells
|
31
|
+
fi
|
32
|
+
else
|
33
|
+
# If the environment file has not yet been created, use the RVM CLI to select.
|
34
|
+
rvm --create use "$environment_id" || {
|
35
|
+
echo "Failed to create RVM environment '${environment_id}'."
|
36
|
+
return 1
|
37
|
+
}
|
38
|
+
fi
|
39
|
+
|
40
|
+
# If you use bundler, this might be useful to you:
|
41
|
+
# if [[ -s Gemfile ]] && {
|
42
|
+
# ! builtin command -v bundle >/dev/null ||
|
43
|
+
# builtin command -v bundle | GREP_OPTIONS= \grep $rvm_path/bin/bundle >/dev/null
|
44
|
+
# }
|
45
|
+
# then
|
46
|
+
# printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
|
47
|
+
# gem install bundler
|
48
|
+
# fi
|
49
|
+
# if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
|
50
|
+
# then
|
51
|
+
# bundle install | GREP_OPTIONS= \grep -vE '^Using|Your bundle is complete'
|
52
|
+
# fi
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Gregory Man
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# Wix::Apps
|
2
|
+
[![Build Status](https://secure.travis-ci.org/wix/wix-apps-ruby.png?branch=master)](http://travis-ci.org/wix/wix-apps-ruby)
|
3
|
+
|
4
|
+
TODO: Write a gem description
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'wix-apps'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install wix-apps
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
TODO: Write usage instructions here
|
23
|
+
|
24
|
+
## Contributing
|
25
|
+
|
26
|
+
1. Fork it
|
27
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
28
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
29
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
30
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/wix-apps.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'base64'
|
2
|
+
require 'multi_json'
|
3
|
+
require 'openssl'
|
4
|
+
|
5
|
+
module Wix
|
6
|
+
module Apps
|
7
|
+
class SignedInstanceParseError < Exception;end
|
8
|
+
class SignedInstanceNoSecretKey < Exception;end
|
9
|
+
# This class deal with Wix Signed Instance
|
10
|
+
# (http://dev.wix.com/display/wixdevelopersapi/The+Signed+Instance)
|
11
|
+
#
|
12
|
+
# Example:
|
13
|
+
# si = SignedInstance.new('vrinSv2HB9tqbnJ....')
|
14
|
+
class SignedInstance
|
15
|
+
attr_reader :raw_signed_instance, :instance_id, :sign_date, :uid,
|
16
|
+
:permissions
|
17
|
+
|
18
|
+
def initialize(raw_signed_instance, options = {})
|
19
|
+
@raw_signed_instance = raw_signed_instance
|
20
|
+
@secret = options[:secret]
|
21
|
+
|
22
|
+
parse_signed_instance_data
|
23
|
+
end
|
24
|
+
|
25
|
+
# validates signature
|
26
|
+
def valid?
|
27
|
+
raise SignedInstanceNoSecretKey.new('Please provide secret key') if @secret.nil?
|
28
|
+
digest = OpenSSL::Digest::Digest.new('sha256')
|
29
|
+
hmac_digest = OpenSSL::HMAC.digest(digest, @secret, @encoded_json)
|
30
|
+
my_signature = Base64.urlsafe_encode64(hmac_digest).gsub('=','')
|
31
|
+
|
32
|
+
return my_signature == @signature
|
33
|
+
end
|
34
|
+
|
35
|
+
#Owner mode on?
|
36
|
+
def owner?
|
37
|
+
permissions == 'OWNER'
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
def parse_signed_instance_data
|
42
|
+
@signature, @encoded_json = raw_signed_instance.split('.', 2)
|
43
|
+
raise SignedInstanceParseError if @signature.nil? || @encoded_json.nil?
|
44
|
+
|
45
|
+
# Need to add Base64 padding.
|
46
|
+
# (http://stackoverflow.com/questions/4987772/decoding-facebooks-signed-request-in-ruby-sinatra)
|
47
|
+
padded_json = @encoded_json + ('=' * (4 - @encoded_json.length % 4))
|
48
|
+
|
49
|
+
begin
|
50
|
+
@json = Base64.urlsafe_decode64(padded_json)
|
51
|
+
signed_instance = MultiJson.load(@json)
|
52
|
+
rescue ArgumentError, MultiJson::DecodeError => e
|
53
|
+
raise SignedInstanceParseError.new(e.message)
|
54
|
+
end
|
55
|
+
|
56
|
+
@instance_id = signed_instance['instanceId']
|
57
|
+
@sign_date = DateTime.parse(signed_instance['signDate'])
|
58
|
+
raise SignedInstanceParseError if @instance_id.nil? || @sign_date.nil?
|
59
|
+
|
60
|
+
@uid = signed_instance['uid']
|
61
|
+
@permissions = signed_instance['permissions']
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module Wix
|
2
|
+
module Apps
|
3
|
+
class SignedInstanceMiddleware < Struct.new :app, :options
|
4
|
+
def initialize(app, options={})
|
5
|
+
@app = app
|
6
|
+
initialize_options options
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
@env = env
|
11
|
+
|
12
|
+
if secured_path?
|
13
|
+
@request = Rack::Request.new(env)
|
14
|
+
if have_instance?
|
15
|
+
begin
|
16
|
+
@instance = Wix::Apps::SignedInstance.new(@request.params['instance'],
|
17
|
+
secret: options[:secret_key])
|
18
|
+
rescue Wix::Apps::SignedInstanceParseError => e
|
19
|
+
return [403, {}, ['Invalid wix instance']]
|
20
|
+
end
|
21
|
+
|
22
|
+
if @instance.valid?
|
23
|
+
parse_instance!
|
24
|
+
@app.call(env)
|
25
|
+
else
|
26
|
+
[403, {}, ['Invalid wix instance']]
|
27
|
+
end
|
28
|
+
else
|
29
|
+
[401, {}, ['Unauthorized']]
|
30
|
+
end
|
31
|
+
else
|
32
|
+
@app.call(env)
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
def initialize_options(options={})
|
39
|
+
self.options = {
|
40
|
+
:secret_key => nil,
|
41
|
+
:secured_paths => []
|
42
|
+
}.merge(options)
|
43
|
+
end
|
44
|
+
|
45
|
+
def secured_path?
|
46
|
+
options[:secured_paths].include? @env['PATH_INFO']
|
47
|
+
end
|
48
|
+
|
49
|
+
def have_instance?
|
50
|
+
@request.params.keys.include? 'instance'
|
51
|
+
end
|
52
|
+
|
53
|
+
def parse_instance!
|
54
|
+
parsed_instance = {
|
55
|
+
'instance_id' => @instance.instance_id,
|
56
|
+
'sign_date' => @instance.sign_date,
|
57
|
+
'user_id' => @instance.uid,
|
58
|
+
'permissions' => @instance.permissions
|
59
|
+
}
|
60
|
+
@request.GET['instance'] = parsed_instance
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Wix::Apps::SignedInstanceMiddleware do
|
4
|
+
include Rack::Test::Methods
|
5
|
+
|
6
|
+
let(:app) { lambda { |env| [200, {}, []] } }
|
7
|
+
let(:secret) { 'd245bbf8-57eb-49d6-aeff-beff6d82cd39' }
|
8
|
+
|
9
|
+
let(:middleware) { Wix::Apps::SignedInstanceMiddleware.new(app, secured_paths: ['/wix'],
|
10
|
+
secret_key: secret) }
|
11
|
+
let(:mock_request) { Rack::MockRequest.new(middleware) }
|
12
|
+
|
13
|
+
let(:instance) { 'HottEZ2jPjqsqS8sFWwngJDZAc5L6BBv5j5N9WAN0Go.eyJpbnN0YW5jZUlkIjoiYjgxNDBlNGQtNDc1ZC00OGVkLTgxOWYtYmFkMGRlNDQ3MDY5Iiwic2lnbkRhdGUiOiIyMDEyLTA4LTExVDEzOjU2OjQ0LjYzNVoiLCJ1aWQiOm51bGwsInBlcm1pc3Npb25zIjpudWxsfQ' }
|
14
|
+
let(:response) { mock_request.get('/wix', params: { 'instance' => instance }) }
|
15
|
+
|
16
|
+
describe "Unsecured paths" do
|
17
|
+
let(:response) { mock_request.get('/') }
|
18
|
+
it("returns a 200") { response.status.should == 200 }
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "Secured Paths" do
|
22
|
+
describe "without instanse" do
|
23
|
+
let(:response) { mock_request.get('/wix') }
|
24
|
+
it("returns a 401") { response.status.should == 401 }
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "with invalid instanse" do
|
28
|
+
let(:instance) { 'invalid.instance' }
|
29
|
+
it("returns a 403") { response.status.should == 403 }
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "with valid instalnse" do
|
33
|
+
it("returns a 200") { response.status.should == 200 }
|
34
|
+
|
35
|
+
describe "instance parsing" do
|
36
|
+
it "have instance_id" do
|
37
|
+
app.should_receive(:call) do |arg|
|
38
|
+
arg['rack.request.query_hash']['instance']['instance_id']
|
39
|
+
.should eq('b8140e4d-475d-48ed-819f-bad0de447069')
|
40
|
+
|
41
|
+
[200, {}, []]
|
42
|
+
end
|
43
|
+
|
44
|
+
response
|
45
|
+
end
|
46
|
+
|
47
|
+
it "have sign_date" do
|
48
|
+
app.should_receive(:call) do |arg|
|
49
|
+
arg['rack.request.query_hash']['instance']['sign_date']
|
50
|
+
.should eq(DateTime.parse("2012-08-11T13:56:44.635Z"))
|
51
|
+
[200, {}, []]
|
52
|
+
end
|
53
|
+
|
54
|
+
response
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "logined user" do
|
59
|
+
let(:instance) { '0jepzq2Gi8zFxLdS_LhTuXIkmFR41H1QOstEtn1v4w0.eyJpbnN0YW5jZUlkIjoiOWY5YzVjMTYtNTljOC00NzA4LThjMjUtODU1NTA1ZGFhOTU0Iiwic2lnbkRhdGUiOiIyMDEyLTA4LTEyVDEwOjA0OjE3Ljg1MloiLCJ1aWQiOiIyOWQ4MjA0YS0zYjgyLTRhOTgtOGQ4Ni0yNDY0YTZiODM2ZGEiLCJwZXJtaXNzaW9ucyI6bnVsbH0' }
|
60
|
+
|
61
|
+
it "have user_id" do
|
62
|
+
app.should_receive(:call) do |arg|
|
63
|
+
arg['rack.request.query_hash']['instance']['user_id']
|
64
|
+
.should eq('29d8204a-3b82-4a98-8d86-2464a6b836da')
|
65
|
+
[200, {}, []]
|
66
|
+
end
|
67
|
+
|
68
|
+
response
|
69
|
+
end
|
70
|
+
|
71
|
+
it "don't have permissions" do
|
72
|
+
app.should_receive(:call) do |arg|
|
73
|
+
arg['rack.request.query_hash']['instance']['permissions']
|
74
|
+
.should be_nil
|
75
|
+
[200, {}, []]
|
76
|
+
end
|
77
|
+
|
78
|
+
response
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
describe "owner" do
|
84
|
+
let(:instance) { 'zPsXLAaMznRbzXUiBo51bNzjKhVRo-GU5U4wSqyxzIg.eyJpbnN0YW5jZUlkIjoiOWY5YzVjMTYtNTljOC00NzA4LThjMjUtODU1NTA1ZGFhOTU0Iiwic2lnbkRhdGUiOiIyMDEyLTA4LTEyVDEwOjExOjIyLjkzNFoiLCJ1aWQiOiIyOWQ4MjA0YS0zYjgyLTRhOTgtOGQ4Ni0yNDY0YTZiODM2ZGEiLCJwZXJtaXNzaW9ucyI6Ik9XTkVSIn0' }
|
85
|
+
|
86
|
+
it "it have user_id" do
|
87
|
+
app.should_receive(:call) do |arg|
|
88
|
+
arg['rack.request.query_hash']['instance']['user_id']
|
89
|
+
.should eq('29d8204a-3b82-4a98-8d86-2464a6b836da')
|
90
|
+
[200, {}, []]
|
91
|
+
end
|
92
|
+
|
93
|
+
response
|
94
|
+
end
|
95
|
+
|
96
|
+
it "have permissions" do
|
97
|
+
app.should_receive(:call) do |arg|
|
98
|
+
arg['rack.request.query_hash']['instance']['permissions']
|
99
|
+
.should eq('OWNER')
|
100
|
+
[200, {}, []]
|
101
|
+
end
|
102
|
+
|
103
|
+
response
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
|
4
|
+
describe Wix::Apps::SignedInstance do
|
5
|
+
let(:raw_signed_instance) { 'naQKltLRVJwLVN90qQYpmmyzkVqFIH0hpvETYuivA1U.eyJpbnN0YW5jZUlkIjoiOWY5YzVjMTYtNTljOC00NzA4LThjMjUtODU1NTA1ZGFhOTU0Iiwic2lnbkRhdGUiOiIyMDEyLTA4LTA4VDE5OjQ3OjMxLjYyNFoiLCJ1aWQiOm51bGwsInBlcm1pc3Npb25zIjpudWxsfQ' }
|
6
|
+
let(:invalid_raw_signed_instance) {'Incorect Raw Signed Instance'}
|
7
|
+
let(:raw_signed_instance_with_user_id) { 'K78r2uwAQbvA68u-bXxn2cdIUFMZIp8v9XfA_hd-iyo.eyJpbnN0YW5jZUlkIjoiOWY5YzVjMTYtNTljOC00NzA4LThjMjUtODU1NTA1ZGFhOTU0Iiwic2lnbkRhdGUiOiIyMDEyLTA4LTA4VDIyOjEwOjU2Ljg3NVoiLCJ1aWQiOiIyOWQ4MjA0YS0zYjgyLTRhOTgtOGQ4Ni0yNDY0YTZiODM2ZGEiLCJwZXJtaXNzaW9ucyI6bnVsbH0' }
|
8
|
+
let(:raw_signed_in_owner_mode) { 'AjQ3BniGXfSOjKw4ej_V0kh4-WF5eB2IRnbvsak9kwc.eyJpbnN0YW5jZUlkIjoiOWY5YzVjMTYtNTljOC00NzA4LThjMjUtODU1NTA1ZGFhOTU0Iiwic2lnbkRhdGUiOiIyMDEyLTA4LTA4VDIyOjEyOjE2LjU4OVoiLCJ1aWQiOiIyOWQ4MjA0YS0zYjgyLTRhOTgtOGQ4Ni0yNDY0YTZiODM2ZGEiLCJwZXJtaXNzaW9ucyI6Ik9XTkVSIn0' }
|
9
|
+
|
10
|
+
subject { Wix::Apps::SignedInstance.new(raw_signed_instance, :secret => SECRET_KEY) }
|
11
|
+
|
12
|
+
describe "Initialization" do
|
13
|
+
describe "invalid format" do
|
14
|
+
subject { Wix::Apps::SignedInstance.new(invalid_raw_signed_instance, :secret => SECRET_KEY) }
|
15
|
+
|
16
|
+
it "raise SignedInstance::ParseError" do
|
17
|
+
expect { subject }.to raise_error Wix::Apps::SignedInstanceParseError
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
it "parse instance_id" do
|
22
|
+
subject.instance_id.should == '9f9c5c16-59c8-4708-8c25-855505daa954'
|
23
|
+
end
|
24
|
+
|
25
|
+
it "parse sign_date as Date" do
|
26
|
+
subject.sign_date.should be_kind_of(DateTime)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "parse sign_date" do
|
30
|
+
subject.sign_date.should == DateTime.rfc3339('2012-08-08T19:47:31.624Z')
|
31
|
+
end
|
32
|
+
|
33
|
+
it "return nil as user id" do
|
34
|
+
subject.uid.should be_nil
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "With user id" do
|
38
|
+
subject { Wix::Apps::SignedInstance.new(raw_signed_instance_with_user_id, :secret => SECRET_KEY) }
|
39
|
+
|
40
|
+
it "parse user id" do
|
41
|
+
subject.uid.should == '29d8204a-3b82-4a98-8d86-2464a6b836da'
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "Owner Mode" do
|
47
|
+
subject { Wix::Apps::SignedInstance.new(raw_signed_in_owner_mode, :secret => SECRET_KEY) }
|
48
|
+
it "parse user id" do
|
49
|
+
subject.uid.should == '29d8204a-3b82-4a98-8d86-2464a6b836da'
|
50
|
+
end
|
51
|
+
|
52
|
+
it "parse permissions" do
|
53
|
+
subject.permissions == 'OWNER'
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "signature validation" do
|
59
|
+
|
60
|
+
describe "secret is nil" do
|
61
|
+
subject { Wix::Apps::SignedInstance.new(raw_signed_instance) }
|
62
|
+
|
63
|
+
it "raise SignedInstanceNoSecretKey" do
|
64
|
+
expect { subject.valid? }.to raise_error Wix::Apps::SignedInstanceNoSecretKey
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "incorect signature" do
|
69
|
+
subject { Wix::Apps::SignedInstance.new(raw_signed_instance, :secret => 'another-secret') }
|
70
|
+
|
71
|
+
it "return false on valid?" do
|
72
|
+
subject.valid?.should be_false
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe "valid signature" do
|
77
|
+
it "return true on valid?" do
|
78
|
+
subject.valid?.should be_true
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe "owner?" do
|
84
|
+
describe "without user id" do
|
85
|
+
it "return false" do
|
86
|
+
subject.owner?.should be_false
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe "with user id" do
|
91
|
+
subject { Wix::Apps::SignedInstance.new(raw_signed_instance_with_user_id, :secret => SECRET_KEY) }
|
92
|
+
it "return false" do
|
93
|
+
subject.owner?.should be_false
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe "in owner mode" do
|
98
|
+
subject { Wix::Apps::SignedInstance.new(raw_signed_in_owner_mode, :secret => SECRET_KEY) }
|
99
|
+
it "return true" do
|
100
|
+
subject.owner?.should be_true
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
data/spec/spec_helper.rb
ADDED
data/wix-apps.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/wix-apps/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Gregory Man"]
|
6
|
+
gem.email = ["man.gregory@gmail.com"]
|
7
|
+
gem.description = %q{ Rack middleware for WixApps }
|
8
|
+
gem.summary = %q{ Rack middleware for WixApps parameters parsing and validation }
|
9
|
+
gem.homepage = "https://github.com/wix/wix-apps-ruby"
|
10
|
+
|
11
|
+
gem.add_dependency 'multi_json'
|
12
|
+
gem.add_dependency 'rack'
|
13
|
+
gem.add_dependency 'jruby-openssl' if RUBY_PLATFORM == 'java'
|
14
|
+
|
15
|
+
gem.add_development_dependency 'rake'
|
16
|
+
gem.add_development_dependency "rspec"
|
17
|
+
gem.add_development_dependency 'rack-test'
|
18
|
+
|
19
|
+
gem.files = `git ls-files`.split($\)
|
20
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
21
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
22
|
+
gem.name = "wix-apps"
|
23
|
+
gem.require_paths = ["lib"]
|
24
|
+
gem.version = Wix::Apps::VERSION
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,153 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wix-apps
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Gregory Man
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-08-12 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: multi_json
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rack
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rspec
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: rack-test
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
description: ! ' Rack middleware for WixApps '
|
95
|
+
email:
|
96
|
+
- man.gregory@gmail.com
|
97
|
+
executables: []
|
98
|
+
extensions: []
|
99
|
+
extra_rdoc_files: []
|
100
|
+
files:
|
101
|
+
- .gitignore
|
102
|
+
- .rspec
|
103
|
+
- .rvmrc
|
104
|
+
- .travis.yml
|
105
|
+
- Gemfile
|
106
|
+
- Guardfile
|
107
|
+
- LICENSE
|
108
|
+
- README.md
|
109
|
+
- Rakefile
|
110
|
+
- lib/wix-apps.rb
|
111
|
+
- lib/wix-apps/signed_instance.rb
|
112
|
+
- lib/wix-apps/signed_instance_middleware.rb
|
113
|
+
- lib/wix-apps/version.rb
|
114
|
+
- spec/lib/wix-apps/signed_instance_middleware_spec.rb
|
115
|
+
- spec/lib/wix-apps/signed_instance_spec.rb
|
116
|
+
- spec/spec_helper.rb
|
117
|
+
- spec/support/config.rb
|
118
|
+
- wix-apps.gemspec
|
119
|
+
homepage: https://github.com/wix/wix-apps-ruby
|
120
|
+
licenses: []
|
121
|
+
post_install_message:
|
122
|
+
rdoc_options: []
|
123
|
+
require_paths:
|
124
|
+
- lib
|
125
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
126
|
+
none: false
|
127
|
+
requirements:
|
128
|
+
- - ! '>='
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
segments:
|
132
|
+
- 0
|
133
|
+
hash: -3069908053347572673
|
134
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
|
+
none: false
|
136
|
+
requirements:
|
137
|
+
- - ! '>='
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
segments:
|
141
|
+
- 0
|
142
|
+
hash: -3069908053347572673
|
143
|
+
requirements: []
|
144
|
+
rubyforge_project:
|
145
|
+
rubygems_version: 1.8.24
|
146
|
+
signing_key:
|
147
|
+
specification_version: 3
|
148
|
+
summary: Rack middleware for WixApps parameters parsing and validation
|
149
|
+
test_files:
|
150
|
+
- spec/lib/wix-apps/signed_instance_middleware_spec.rb
|
151
|
+
- spec/lib/wix-apps/signed_instance_spec.rb
|
152
|
+
- spec/spec_helper.rb
|
153
|
+
- spec/support/config.rb
|