wix 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/wix.rb +4 -0
- data/lib/wix/errors/wix_error.rb +13 -0
- data/lib/wix/instance.rb +15 -3
- data/lib/wix/version.rb +1 -1
- data/spec/wix/instance_spec.rb +29 -0
- metadata +6 -3
data/lib/wix.rb
CHANGED
data/lib/wix/instance.rb
CHANGED
@@ -1,15 +1,27 @@
|
|
1
1
|
module Wix
|
2
2
|
class Instance
|
3
|
+
MISSING_WIX_SIGNED_INSTANCE = "You must pass a wix_signed_instance value to parse"
|
4
|
+
INVALID_WIX_SIGNED_INSTANCE = "The wix_signed_instance you passed is invalid"
|
5
|
+
INVALID_WIX_SIGNATURE = "The signature from the wix_signed_instance you passed does not match your signature"
|
6
|
+
|
3
7
|
def self.parse(wix_signed_instance)
|
4
|
-
|
5
|
-
|
6
|
-
|
8
|
+
wix_signed_instance = wix_signed_instance.to_s.strip
|
9
|
+
raise WixError.new(MISSING_WIX_SIGNED_INSTANCE) if wix_signed_instance.empty?
|
10
|
+
|
11
|
+
split_wix_signed_instance = wix_signed_instance.split('.')
|
12
|
+
raise WixError.new(INVALID_WIX_SIGNED_INSTANCE) if split_wix_signed_instance.length != 2
|
13
|
+
|
14
|
+
signature = split_wix_signed_instance[0]
|
15
|
+
encoded_json = split_wix_signed_instance[1]
|
16
|
+
raise WixError.new(INVALID_WIX_SIGNATURE) if !valid_signature(signature, encoded_json)
|
7
17
|
|
8
18
|
encoded_json_hack = encoded_json + ('=' * (4 - encoded_json.length.modulo(4)))
|
9
19
|
json_string = Base64.urlsafe_decode64(encoded_json_hack)
|
10
20
|
hash = JSON.parse(json_string)
|
11
21
|
|
12
22
|
RecursiveOpenStruct.new(hash, :recurse_over_arrays => true)
|
23
|
+
rescue => error
|
24
|
+
raise WixError.new(error.message)
|
13
25
|
end
|
14
26
|
|
15
27
|
def self.valid_signature(signature, encoded_json)
|
data/lib/wix/version.rb
CHANGED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Wix::Instance do
|
4
|
+
let(:instance) { Wix::Instance.parse(wix_signed_instance) }
|
5
|
+
|
6
|
+
context "nil for wix_signed_instance" do
|
7
|
+
let(:wix_signed_instance) { nil }
|
8
|
+
|
9
|
+
it { lambda { instance }.should raise_error(StandardError, Wix::Instance::MISSING_WIX_SIGNED_INSTANCE) }
|
10
|
+
end
|
11
|
+
|
12
|
+
context "empty string for wix_signed_instance" do
|
13
|
+
let(:wix_signed_instance) { "" }
|
14
|
+
|
15
|
+
it { lambda { instance }.should raise_error(StandardError, Wix::Instance::MISSING_WIX_SIGNED_INSTANCE) }
|
16
|
+
end
|
17
|
+
|
18
|
+
context "empty string with spaces for wix_signed_instance" do
|
19
|
+
let(:wix_signed_instance) { " " }
|
20
|
+
|
21
|
+
it { lambda { instance }.should raise_error(StandardError, Wix::Instance::MISSING_WIX_SIGNED_INSTANCE) }
|
22
|
+
end
|
23
|
+
|
24
|
+
context "string without a . delimiter" do
|
25
|
+
let(:wix_signed_instance) { "string-no-dot-delimiter" }
|
26
|
+
|
27
|
+
it { lambda { instance }.should raise_error(StandardError, Wix::Instance::INVALID_WIX_SIGNED_INSTANCE) }
|
28
|
+
end
|
29
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wix
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -105,9 +105,11 @@ files:
|
|
105
105
|
- README.md
|
106
106
|
- Rakefile
|
107
107
|
- lib/wix.rb
|
108
|
+
- lib/wix/errors/wix_error.rb
|
108
109
|
- lib/wix/instance.rb
|
109
110
|
- lib/wix/version.rb
|
110
111
|
- spec/spec_helper.rb
|
112
|
+
- spec/wix/instance_spec.rb
|
111
113
|
- spec/wix_spec.rb
|
112
114
|
- wix.gemspec
|
113
115
|
homepage: http://github.com/scottmotte/wix
|
@@ -124,7 +126,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
124
126
|
version: '0'
|
125
127
|
segments:
|
126
128
|
- 0
|
127
|
-
hash:
|
129
|
+
hash: 3518911956414316239
|
128
130
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
131
|
none: false
|
130
132
|
requirements:
|
@@ -133,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
133
135
|
version: '0'
|
134
136
|
segments:
|
135
137
|
- 0
|
136
|
-
hash:
|
138
|
+
hash: 3518911956414316239
|
137
139
|
requirements: []
|
138
140
|
rubyforge_project:
|
139
141
|
rubygems_version: 1.8.23
|
@@ -142,4 +144,5 @@ specification_version: 3
|
|
142
144
|
summary: Rubygem to interact with Wix's add-on marketplace API.
|
143
145
|
test_files:
|
144
146
|
- spec/spec_helper.rb
|
147
|
+
- spec/wix/instance_spec.rb
|
145
148
|
- spec/wix_spec.rb
|