omniauth-shopify 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +5 -0
- data/lib/omniauth-shopify/version.rb +2 -2
- data/omniauth-shopify.gemspec +5 -1
- data/spec/omniauth/strategies/shopify_spec.rb +86 -0
- metadata +27 -4
data/Rakefile
CHANGED
data/omniauth-shopify.gemspec
CHANGED
@@ -4,7 +4,7 @@ require "omniauth-shopify/version"
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = "omniauth-shopify"
|
7
|
-
s.version =
|
7
|
+
s.version = OmniAuth::Shopify::VERSION
|
8
8
|
s.authors = ["Yevgeniy A. Viktorov"]
|
9
9
|
s.email = ["craftsman@yevgenko.me"]
|
10
10
|
s.homepage = ""
|
@@ -19,4 +19,8 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.require_paths = ["lib"]
|
20
20
|
|
21
21
|
s.add_runtime_dependency 'omniauth', '~> 1.0'
|
22
|
+
|
23
|
+
s.add_development_dependency 'minitest' if RUBY_VERSION < '1.9.2'
|
24
|
+
s.add_development_dependency 'rack-test'
|
25
|
+
s.add_development_dependency 'rake'
|
22
26
|
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
ENV['RACK_ENV'] = 'test'
|
2
|
+
require 'minitest/autorun'
|
3
|
+
require 'rack/test'
|
4
|
+
|
5
|
+
require 'omniauth-shopify'
|
6
|
+
require 'digest/md5'
|
7
|
+
|
8
|
+
include Rack::Test::Methods
|
9
|
+
|
10
|
+
describe OmniAuth::Strategies::Shopify do
|
11
|
+
def app
|
12
|
+
Rack::Builder.new {
|
13
|
+
use Rack::Session::Cookie
|
14
|
+
use OmniAuth::Strategies::Shopify, 'apikey', 'hush'
|
15
|
+
run lambda {|env| [404, {'Content-Type' => 'text/plain'}, [nil || env.key?('omniauth.auth').to_s]] }
|
16
|
+
}.to_app
|
17
|
+
end
|
18
|
+
|
19
|
+
def query_parameters
|
20
|
+
{
|
21
|
+
"shop" => "some-shop.myshopify.com",
|
22
|
+
"t" => "a94a110d86d2452eb3e2af4cfb8a3828"
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
def query_string
|
27
|
+
query_parameters.collect { |k, v| "#{k}=#{v}" }.join '&'
|
28
|
+
end
|
29
|
+
|
30
|
+
def timestamp
|
31
|
+
Time.now.utc.to_i
|
32
|
+
end
|
33
|
+
|
34
|
+
def bad_timestamp
|
35
|
+
(Time.now - 25 * 3600).utc.to_i
|
36
|
+
end
|
37
|
+
|
38
|
+
def signature timestamp
|
39
|
+
calculated_signature = query_parameters.collect { |k, v| "#{k}=#{v}" }
|
40
|
+
calculated_signature.push "timestamp=#{timestamp}"
|
41
|
+
Digest::MD5.hexdigest('hush' + calculated_signature.sort.join)
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '#request_phase' do
|
45
|
+
it 'must prompt for a shop url' do
|
46
|
+
get '/auth/shopify'
|
47
|
+
last_response.body.must_match %r{<input[^>]*shop}
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'must redirect to authentication url' do
|
51
|
+
post '/auth/shopify', :shop => 'some-shop'
|
52
|
+
assert last_response.redirect?
|
53
|
+
last_response.headers['Location'].must_equal 'http://some-shop.myshopify.com/admin/api/auth?api_key=apikey'
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe '#callback phase' do
|
58
|
+
before(:each) do
|
59
|
+
get "/auth/shopify/callback?#{query_string}×tamp=#{timestamp}&signature=#{signature(timestamp)}"
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'must have auth hash' do
|
63
|
+
last_request.env['omniauth.auth'].must_be_kind_of Hash
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'must have proper uid' do
|
67
|
+
last_request.env['omniauth.auth']['uid'].must_equal query_parameters['shop']
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'must have token' do
|
71
|
+
last_request.env['omniauth.auth']['credentials']['token'].must_equal query_parameters['t']
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe 'invalid response' do
|
76
|
+
it 'must fail when bad signature' do
|
77
|
+
get "/auth/shopify/callback?#{query_string}×tamp=#{timestamp}&signature=some_bad_signature"
|
78
|
+
last_response.headers['Location'].must_match %r{invalid_response}
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'must fail when timestamps above 24 hours' do
|
82
|
+
get "/auth/shopify/callback?#{query_string}×tamp=#{bad_timestamp}&signature=#{signature(bad_timestamp)}"
|
83
|
+
last_response.headers['Location'].must_match %r{invalid_response}
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omniauth-shopify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-02-
|
12
|
+
date: 2012-02-13 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: omniauth
|
16
|
-
requirement: &
|
16
|
+
requirement: &17205819720 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,7 +21,29 @@ dependencies:
|
|
21
21
|
version: '1.0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *17205819720
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rack-test
|
27
|
+
requirement: &17205819280 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *17205819280
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rake
|
38
|
+
requirement: &17205818820 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *17205818820
|
25
47
|
description: Strategy for authenticating to Shopify API with OmniAuth.
|
26
48
|
email:
|
27
49
|
- craftsman@yevgenko.me
|
@@ -38,6 +60,7 @@ files:
|
|
38
60
|
- lib/omniauth-shopify/version.rb
|
39
61
|
- lib/omniauth/strategies/shopify.rb
|
40
62
|
- omniauth-shopify.gemspec
|
63
|
+
- spec/omniauth/strategies/shopify_spec.rb
|
41
64
|
homepage: ''
|
42
65
|
licenses: []
|
43
66
|
post_install_message:
|