spark_api 1.4.29 → 1.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +1 -1
- data/VERSION +1 -1
- data/lib/spark_api/authentication/api_auth.rb +1 -1
- data/lib/spark_api/authentication/oauth2.rb +1 -1
- data/lib/spark_api/authentication/oauth2_impl/grant_type_base.rb +1 -1
- data/lib/spark_api/client.rb +2 -2
- data/lib/spark_api/models.rb +2 -0
- data/lib/spark_api/models/floplan.rb +24 -0
- data/lib/spark_api/models/listing.rb +11 -1
- data/lib/spark_api/models/media.rb +30 -0
- data/lib/spark_api/models/subresource.rb +2 -2
- data/lib/spark_api/models/video.rb +108 -0
- data/lib/spark_api/models/virtual_tour.rb +16 -0
- data/lib/spark_api/request.rb +2 -2
- data/script/reso_middleware_example.rb +70 -0
- data/spec/fixtures/listings/floplans_index.json +15 -0
- data/spec/spec_helper.rb +9 -4
- data/spec/unit/spark_api/authentication/api_auth_spec.rb +21 -22
- data/spec/unit/spark_api/authentication/base_auth_spec.rb +3 -3
- data/spec/unit/spark_api/authentication/oauth2_impl/faraday_middleware_spec.rb +1 -1
- data/spec/unit/spark_api/authentication/oauth2_impl/grant_type_base_spec.rb +1 -1
- data/spec/unit/spark_api/authentication/oauth2_impl/single_session_provider_spec.rb +2 -2
- data/spec/unit/spark_api/authentication/oauth2_spec.rb +40 -40
- data/spec/unit/spark_api/authentication_spec.rb +2 -2
- data/spec/unit/spark_api/configuration/yaml_spec.rb +44 -44
- data/spec/unit/spark_api/configuration_spec.rb +56 -57
- data/spec/unit/spark_api/faraday_middleware_spec.rb +12 -12
- data/spec/unit/spark_api/models/account_spec.rb +20 -20
- data/spec/unit/spark_api/models/activity_spec.rb +5 -5
- data/spec/unit/spark_api/models/base_spec.rb +32 -32
- data/spec/unit/spark_api/models/concerns/destroyable_spec.rb +2 -2
- data/spec/unit/spark_api/models/concerns/savable_spec.rb +19 -19
- data/spec/unit/spark_api/models/connect_prefs_spec.rb +1 -1
- data/spec/unit/spark_api/models/constraint_spec.rb +1 -1
- data/spec/unit/spark_api/models/contact_spec.rb +50 -50
- data/spec/unit/spark_api/models/dirty_spec.rb +12 -12
- data/spec/unit/spark_api/models/document_spec.rb +3 -3
- data/spec/unit/spark_api/models/fields_spec.rb +17 -17
- data/spec/unit/spark_api/models/finders_spec.rb +7 -7
- data/spec/unit/spark_api/models/floplan_spec.rb +24 -0
- data/spec/unit/spark_api/models/listing_cart_spec.rb +46 -46
- data/spec/unit/spark_api/models/listing_meta_translations_spec.rb +6 -6
- data/spec/unit/spark_api/models/listing_spec.rb +91 -91
- data/spec/unit/spark_api/models/message_spec.rb +10 -10
- data/spec/unit/spark_api/models/note_spec.rb +10 -10
- data/spec/unit/spark_api/models/notification_spec.rb +6 -6
- data/spec/unit/spark_api/models/open_house_spec.rb +4 -4
- data/spec/unit/spark_api/models/photo_spec.rb +8 -8
- data/spec/unit/spark_api/models/portal_spec.rb +4 -4
- data/spec/unit/spark_api/models/property_types_spec.rb +5 -5
- data/spec/unit/spark_api/models/rental_calendar_spec.rb +13 -11
- data/spec/unit/spark_api/models/rule_spec.rb +2 -2
- data/spec/unit/spark_api/models/saved_search_spec.rb +33 -33
- data/spec/unit/spark_api/models/search_template/quick_search_spec.rb +5 -5
- data/spec/unit/spark_api/models/shared_listing_spec.rb +12 -12
- data/spec/unit/spark_api/models/sort_spec.rb +3 -3
- data/spec/unit/spark_api/models/standard_fields_spec.rb +12 -12
- data/spec/unit/spark_api/models/subresource_spec.rb +33 -15
- data/spec/unit/spark_api/models/system_info_spec.rb +7 -7
- data/spec/unit/spark_api/models/tour_of_home_spec.rb +3 -3
- data/spec/unit/spark_api/models/video_spec.rb +9 -9
- data/spec/unit/spark_api/models/virtual_tour_spec.rb +7 -7
- data/spec/unit/spark_api/models/vow_account_spec.rb +8 -8
- data/spec/unit/spark_api/multi_client_spec.rb +14 -14
- data/spec/unit/spark_api/options_hash_spec.rb +4 -4
- data/spec/unit/spark_api/paginate_spec.rb +71 -71
- data/spec/unit/spark_api/primary_array_spec.rb +5 -5
- data/spec/unit/spark_api/request_spec.rb +65 -59
- data/spec/unit/spark_api_spec.rb +6 -6
- metadata +184 -248
data/spec/spec_helper.rb
CHANGED
@@ -11,7 +11,6 @@ end
|
|
11
11
|
|
12
12
|
require "rubygems"
|
13
13
|
require "rspec"
|
14
|
-
require 'rspec/autorun'
|
15
14
|
require 'webmock/rspec'
|
16
15
|
require "json"
|
17
16
|
require 'multi_json'
|
@@ -22,6 +21,13 @@ require path + '/spark_api'
|
|
22
21
|
|
23
22
|
require 'spark_api'
|
24
23
|
|
24
|
+
if ENV['COVERAGE'] == "on"
|
25
|
+
require 'simplecov'
|
26
|
+
require 'simplecov-rcov'
|
27
|
+
SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter
|
28
|
+
SimpleCov.start { add_filter %w(/vendor /spec /test) }
|
29
|
+
end
|
30
|
+
|
25
31
|
FileUtils.mkdir 'log' unless File.exists? 'log'
|
26
32
|
|
27
33
|
module SparkApi
|
@@ -48,17 +54,16 @@ end
|
|
48
54
|
Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each {|f| require f}
|
49
55
|
|
50
56
|
RSpec.configure do |config|
|
51
|
-
|
57
|
+
|
52
58
|
config.include WebMock::API
|
53
59
|
config.include StubApiRequests
|
54
60
|
|
55
|
-
config.treat_symbols_as_metadata_keys_with_true_values = true
|
56
61
|
config.alias_example_to :on_get_it, :method => 'GET'
|
57
62
|
config.alias_example_to :on_put_it, :method => 'PUT'
|
58
63
|
config.alias_example_to :on_post_it, :method => 'POST'
|
59
64
|
config.alias_example_to :on_delete_it, :method => 'DELETE'
|
60
65
|
config.before(:all) { reset_config }
|
61
|
-
config.
|
66
|
+
config.color = true
|
62
67
|
end
|
63
68
|
|
64
69
|
def jruby?
|
@@ -4,15 +4,14 @@ describe SparkApi::Authentication::ApiAuth do
|
|
4
4
|
subject {SparkApi::Authentication::ApiAuth.new(nil) }
|
5
5
|
describe "build_param_hash" do
|
6
6
|
it "should return a blank string when passed nil" do
|
7
|
-
subject.build_param_string(nil).
|
7
|
+
expect(subject.build_param_string(nil)).to be_empty
|
8
8
|
end
|
9
9
|
it "should return a correct param string for one item" do
|
10
|
-
subject.build_param_string({:foo => "bar"}).
|
10
|
+
expect(subject.build_param_string({:foo => "bar"})).to match("foobar")
|
11
11
|
end
|
12
12
|
it "should alphabatize the param names by key first, then by value" do
|
13
|
-
subject.build_param_string({:zoo => "zar", :ooo => "car"}).
|
14
|
-
subject.build_param_string({:Akey => "aValue", :aNotherkey => "AnotherValue"}).
|
15
|
-
match "AkeyaValueaNotherkeyAnotherValue"
|
13
|
+
expect(subject.build_param_string({:zoo => "zar", :ooo => "car"})).to match("ooocarzoozar")
|
14
|
+
expect(subject.build_param_string({:Akey => "aValue", :aNotherkey => "AnotherValue"})).to match("AkeyaValueaNotherkeyAnotherValue")
|
16
15
|
end
|
17
16
|
end
|
18
17
|
|
@@ -33,7 +32,7 @@ describe SparkApi::Authentication::ApiAuth do
|
|
33
32
|
stub_request(:post, "https://api.sparkapi.com/#{SparkApi.version}/session").
|
34
33
|
with(:query => {:ApiKey => "my_key", :ApiSig => "c731cf2455fbc7a4ef937b2301108d7a"}).
|
35
34
|
to_return(:body => fixture("authentication_failure.json"), :status=>401)
|
36
|
-
expect {subject.authenticate()}.to raise_error(SparkApi::ClientError){ |e| e.status.
|
35
|
+
expect {subject.authenticate()}.to raise_error(SparkApi::ClientError){ |e| expect(e.status).to eq(401) }
|
37
36
|
end
|
38
37
|
end
|
39
38
|
|
@@ -41,16 +40,16 @@ describe SparkApi::Authentication::ApiAuth do
|
|
41
40
|
let(:session) { Object.new }
|
42
41
|
it "should return true when session is active" do
|
43
42
|
subject.session = session
|
44
|
-
session.
|
45
|
-
subject.authenticated
|
43
|
+
allow(session).to receive(:expired?) { false }
|
44
|
+
expect(subject.authenticated?).to eq(true)
|
46
45
|
end
|
47
46
|
it "should return false when session is expired" do
|
48
47
|
subject.session = session
|
49
|
-
session.
|
50
|
-
subject.authenticated
|
48
|
+
allow(session).to receive(:expired?) { true }
|
49
|
+
expect(subject.authenticated?).to eq(false)
|
51
50
|
end
|
52
51
|
it "should return false when session is uninitialized" do
|
53
|
-
subject.authenticated
|
52
|
+
expect(subject.authenticated?).to eq(false)
|
54
53
|
end
|
55
54
|
end
|
56
55
|
|
@@ -61,14 +60,14 @@ describe SparkApi::Authentication::ApiAuth do
|
|
61
60
|
it "should logout when there is an active session" do
|
62
61
|
logged_out = false
|
63
62
|
subject.session = session
|
64
|
-
client.
|
63
|
+
allow(client).to receive(:delete).with("/session/1234") { logged_out = true }
|
65
64
|
subject.logout
|
66
|
-
subject.session.
|
67
|
-
logged_out.
|
65
|
+
expect(subject.session).to eq(nil)
|
66
|
+
expect(logged_out).to eq(true)
|
68
67
|
end
|
69
68
|
it "should skip logging out when there is no active session information" do
|
70
|
-
client.
|
71
|
-
subject.logout.
|
69
|
+
allow(client).to receive(:delete) { raise "Should not be called" }
|
70
|
+
expect(subject.logout).to eq(nil)
|
72
71
|
end
|
73
72
|
end
|
74
73
|
|
@@ -98,7 +97,7 @@ describe SparkApi::Authentication::ApiAuth do
|
|
98
97
|
:AuthToken => "1234"}.merge(args)).
|
99
98
|
to_return(:body => fixture("listings/no_subresources.json"))
|
100
99
|
subject.session = session
|
101
|
-
subject.request(:get, "/#{SparkApi.version}/listings", nil, args).status.
|
100
|
+
expect(subject.request(:get, "/#{SparkApi.version}/listings", nil, args).status).to eq(200)
|
102
101
|
end
|
103
102
|
it "should handle a post request" do
|
104
103
|
stub_auth_request
|
@@ -118,14 +117,14 @@ describe SparkApi::Authentication::ApiAuth do
|
|
118
117
|
}]}
|
119
118
|
}',
|
120
119
|
:status=>201)
|
121
|
-
subject.request(:post, "/#{SparkApi.version}/contacts", contact, args).status.
|
120
|
+
expect(subject.request(:post, "/#{SparkApi.version}/contacts", contact, args).status).to eq(201)
|
122
121
|
end
|
123
122
|
end
|
124
123
|
|
125
124
|
describe "sign" do
|
126
125
|
it "should sign the auth parameters correctly" do
|
127
126
|
sign_token = "my_secretApiKeymy_key"
|
128
|
-
subject.sign(sign_token).
|
127
|
+
expect(subject.sign(sign_token)).to eq("c731cf2455fbc7a4ef937b2301108d7a")
|
129
128
|
end
|
130
129
|
end
|
131
130
|
|
@@ -134,7 +133,7 @@ describe SparkApi::Authentication::ApiAuth do
|
|
134
133
|
subject {SparkApi::Authentication::ApiAuth.new(client) }
|
135
134
|
it "should fully sign the token" do
|
136
135
|
parms = {:AuthToken => "1234", :ApiUser => "CoolAsIce"}
|
137
|
-
subject.sign_token("/test", parms).
|
136
|
+
expect(subject.sign_token("/test", parms)).to eq("7bbe3384a8b64368357f8551cab271e3")
|
138
137
|
end
|
139
138
|
end
|
140
139
|
|
@@ -160,8 +159,8 @@ describe SparkApi::Authentication::ApiAuth do
|
|
160
159
|
to_return(:body => fixture('listings/with_documents.json'))
|
161
160
|
l = Listing.find('1234', :_expand => "Documents")
|
162
161
|
|
163
|
-
count.
|
164
|
-
SparkApi.client.session.expired
|
162
|
+
expect(count).to eq(2)
|
163
|
+
expect(SparkApi.client.session.expired?).to eq(false)
|
165
164
|
end
|
166
165
|
end
|
167
166
|
|
@@ -3,8 +3,8 @@ require './spec/spec_helper'
|
|
3
3
|
describe SparkApi::Authentication::BaseAuth do
|
4
4
|
subject {SparkApi::Authentication::BaseAuth.new(nil) }
|
5
5
|
it "should raise an error" do
|
6
|
-
expect {subject.authenticate()}.to raise_error(){ |e| e.message.
|
7
|
-
expect {subject.logout()}.to raise_error(){ |e| e.message.
|
8
|
-
expect {subject.request(nil, nil, nil, nil)}.to raise_error(){ |e| e.message.
|
6
|
+
expect {subject.authenticate()}.to raise_error(){ |e| expect(e.message).to eq("Implement me!")}
|
7
|
+
expect {subject.logout()}.to raise_error(){ |e| expect(e.message).to eq("Implement me!")}
|
8
|
+
expect {subject.request(nil, nil, nil, nil)}.to raise_error(){ |e| expect(e.message).to eq("Implement me!")}
|
9
9
|
end
|
10
10
|
end
|
@@ -10,7 +10,7 @@ describe SparkApi::Authentication::OAuth2Impl::SparkbarFaradayMiddleware do
|
|
10
10
|
:status => 201
|
11
11
|
}
|
12
12
|
subject.on_complete env
|
13
|
-
env[:body]["token"].
|
13
|
+
expect(env[:body]["token"]).to eq("sp4rkb4rt0k3n")
|
14
14
|
end
|
15
15
|
|
16
16
|
it "should raise error on unsuccessful response" do
|
@@ -4,6 +4,6 @@ describe SparkApi::Authentication::OAuth2Impl::GrantTypeBase do
|
|
4
4
|
subject { SparkApi::Authentication::OAuth2Impl::GrantTypeBase }
|
5
5
|
# Make sure the client boostraps the right plugin based on configuration.
|
6
6
|
it "create should " do
|
7
|
-
expect {subject.create(nil, InvalidAuth2Provider.new())}.to raise_error(SparkApi::ClientError){ |e| e.message.
|
7
|
+
expect {subject.create(nil, InvalidAuth2Provider.new())}.to raise_error(SparkApi::ClientError){ |e| expect(e.message).to eq("Unsupported grant type [not_a_real_type]") }
|
8
8
|
end
|
9
9
|
end
|
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe SparkApi::Authentication::SingleSessionProvider do
|
4
4
|
subject { SparkApi::Authentication::SingleSessionProvider.new({ :access_token => "the_token" }) }
|
5
5
|
it "should initialize a new session with access_token" do
|
6
|
-
subject.load_session.
|
7
|
-
subject.load_session.access_token.
|
6
|
+
expect(subject.load_session).to respond_to(:access_token)
|
7
|
+
expect(subject.load_session.access_token).to eq("the_token")
|
8
8
|
end
|
9
9
|
end
|
@@ -11,7 +11,7 @@ describe SparkApi::Authentication::OAuth2 do
|
|
11
11
|
# Make sure the client boostraps the right plugin based on configuration.
|
12
12
|
describe "plugin" do
|
13
13
|
it "should load the oauth2 authenticator" do
|
14
|
-
client.authenticator.class.
|
14
|
+
expect(client.authenticator.class).to eq(SparkApi::Authentication::OAuth2)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
describe "authenticate" do
|
@@ -21,8 +21,8 @@ describe SparkApi::Authentication::OAuth2 do
|
|
21
21
|
'{"client_id":"example-id","client_secret":"example-password","code":"my_code","grant_type":"authorization_code","redirect_uri":"https://exampleapp.fbsdata.com/oauth-callback"}'
|
22
22
|
).
|
23
23
|
to_return(:body => fixture("oauth2/access.json"), :status=>200)
|
24
|
-
subject.authenticate.access_token.
|
25
|
-
subject.authenticate.expires_in.
|
24
|
+
expect(subject.authenticate.access_token).to eq("04u7h-4cc355-70k3n")
|
25
|
+
expect(subject.authenticate.expires_in).to eq(57600)
|
26
26
|
end
|
27
27
|
|
28
28
|
it "should raise an error when api credentials are invalid" do
|
@@ -31,7 +31,7 @@ describe SparkApi::Authentication::OAuth2 do
|
|
31
31
|
'{"client_id":"example-id","client_secret":"example-password","code":"my_code","grant_type":"authorization_code","redirect_uri":"https://exampleapp.fbsdata.com/oauth-callback"}'
|
32
32
|
).
|
33
33
|
to_return(:body => fixture("oauth2/error.json"), :status=>400)
|
34
|
-
expect {subject.authenticate()}.to raise_error(SparkApi::ClientError){ |e| e.status.
|
34
|
+
expect {subject.authenticate()}.to raise_error(SparkApi::ClientError){ |e| expect(e.status).to eq(400) }
|
35
35
|
end
|
36
36
|
|
37
37
|
end
|
@@ -40,16 +40,16 @@ describe SparkApi::Authentication::OAuth2 do
|
|
40
40
|
let(:session) { Object.new }
|
41
41
|
it "should return true when session is active" do
|
42
42
|
subject.session = session
|
43
|
-
session.
|
44
|
-
subject.authenticated
|
43
|
+
allow(session).to receive(:expired?) { false }
|
44
|
+
expect(subject.authenticated?).to eq(true)
|
45
45
|
end
|
46
46
|
it "should return false when session is expired" do
|
47
47
|
subject.session = session
|
48
|
-
session.
|
49
|
-
subject.authenticated
|
48
|
+
allow(session).to receive(:expired?) { true }
|
49
|
+
expect(subject.authenticated?).to eq(false)
|
50
50
|
end
|
51
51
|
it "should return false when session is uninitialized" do
|
52
|
-
subject.authenticated
|
52
|
+
expect(subject.authenticated?).to eq(false)
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
@@ -58,11 +58,11 @@ describe SparkApi::Authentication::OAuth2 do
|
|
58
58
|
it "should logout when there is an active session" do
|
59
59
|
subject.session = session
|
60
60
|
subject.logout
|
61
|
-
subject.session.
|
61
|
+
expect(subject.session).to eq(nil)
|
62
62
|
end
|
63
63
|
it "should skip logging out when there is no active session information" do
|
64
|
-
client.
|
65
|
-
subject.logout.
|
64
|
+
allow(client).to receive(:delete) { raise "Should not be called" }
|
65
|
+
expect(subject.logout).to eq(nil)
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
@@ -79,7 +79,7 @@ describe SparkApi::Authentication::OAuth2 do
|
|
79
79
|
with(:query => args).
|
80
80
|
to_return(:body => fixture("listings/no_subresources.json"))
|
81
81
|
subject.session = session
|
82
|
-
subject.request(:get, "/#{SparkApi.version}/listings", nil, args).status.
|
82
|
+
expect(subject.request(:get, "/#{SparkApi.version}/listings", nil, args).status).to eq(200)
|
83
83
|
end
|
84
84
|
it "should handle a post request" do
|
85
85
|
subject.session = session
|
@@ -95,7 +95,7 @@ describe SparkApi::Authentication::OAuth2 do
|
|
95
95
|
}]}
|
96
96
|
}',
|
97
97
|
:status=>201)
|
98
|
-
subject.request(:post, "/#{SparkApi.version}/contacts", contact, args).status.
|
98
|
+
expect(subject.request(:post, "/#{SparkApi.version}/contacts", contact, args).status).to eq(201)
|
99
99
|
end
|
100
100
|
end
|
101
101
|
|
@@ -106,7 +106,7 @@ describe SparkApi::Authentication::OAuth2 do
|
|
106
106
|
with(:body => "access_token=#{session.access_token}").
|
107
107
|
to_return(:body => '{"token":"sp4rkb4rt0k3n"}')
|
108
108
|
subject.session = session
|
109
|
-
subject.sparkbar_token.
|
109
|
+
expect(subject.sparkbar_token).to eq("sp4rkb4rt0k3n")
|
110
110
|
end
|
111
111
|
it "should raise an error on missing sparkbar token" do
|
112
112
|
c = stub_request(:post, "https://test.sparkplatform.com/appbar/authorize").
|
@@ -142,9 +142,9 @@ describe SparkApi::Authentication::OAuth2 do
|
|
142
142
|
to_return(:body => fixture('errors/expired.json'), :status => 401).times(1).then.
|
143
143
|
to_return(:body => fixture('listings/with_documents.json'))
|
144
144
|
client.get("/listings/1234")
|
145
|
-
count.
|
146
|
-
refresh_count.
|
147
|
-
client.session.expired
|
145
|
+
expect(count).to eq(1)
|
146
|
+
expect(refresh_count).to eq(1)
|
147
|
+
expect(client.session.expired?).to eq(false)
|
148
148
|
end
|
149
149
|
end
|
150
150
|
context "and an invalid refresh token" do
|
@@ -164,8 +164,8 @@ describe SparkApi::Authentication::OAuth2 do
|
|
164
164
|
to_return(:body => fixture('listings/with_documents.json'))
|
165
165
|
|
166
166
|
client.get("/listings/1234")
|
167
|
-
count.
|
168
|
-
client.session.expired
|
167
|
+
expect(count).to eq(2)
|
168
|
+
expect(client.session.expired?).to eq(false)
|
169
169
|
end
|
170
170
|
end
|
171
171
|
end
|
@@ -186,16 +186,16 @@ describe SparkApi::Authentication::OpenIdOAuth2Hybrid do
|
|
186
186
|
end
|
187
187
|
describe "plugin" do
|
188
188
|
it "should load the hybrid authenticator" do
|
189
|
-
client.authenticator.class.
|
189
|
+
expect(client.authenticator.class).to eq(SparkApi::Authentication::OpenIdOAuth2Hybrid)
|
190
190
|
end
|
191
191
|
end
|
192
192
|
|
193
193
|
describe "#authorization_url" do
|
194
194
|
it "should include combined flow parameter" do
|
195
|
-
client.authenticator.authorization_url.
|
195
|
+
expect(client.authenticator.authorization_url).to match("openid.spark.combined_flow=true")
|
196
196
|
end
|
197
197
|
it "should allow custom parameters" do
|
198
|
-
client.authenticator.authorization_url({"joshua" => "iscool"}).
|
198
|
+
expect(client.authenticator.authorization_url({"joshua" => "iscool"})).to match("joshua=iscool")
|
199
199
|
end
|
200
200
|
end
|
201
201
|
end
|
@@ -215,24 +215,24 @@ describe SparkApi::Authentication::OpenId do
|
|
215
215
|
|
216
216
|
describe "plugin" do
|
217
217
|
it "should not include combined flow parameter" do
|
218
|
-
client.authenticator.authorization_url.
|
218
|
+
expect(client.authenticator.authorization_url).not_to match("openid.spark.combined_flow=true")
|
219
219
|
end
|
220
220
|
it "should load the oauth2 authenticator" do
|
221
|
-
client.authenticator.class.
|
221
|
+
expect(client.authenticator.class).to eq(SparkApi::Authentication::OpenId)
|
222
222
|
end
|
223
223
|
end
|
224
224
|
|
225
225
|
describe "#authorization_url" do
|
226
226
|
it "should allow custom parameters" do
|
227
|
-
client.authenticator.authorization_url({"joshua" => "iscool"}).
|
227
|
+
expect(client.authenticator.authorization_url({"joshua" => "iscool"})).to match("joshua=iscool")
|
228
228
|
end
|
229
229
|
end
|
230
230
|
|
231
231
|
describe "forbidden methods" do
|
232
232
|
it "should not allow authentication" do
|
233
|
-
|
233
|
+
expect {
|
234
234
|
client.authenticate
|
235
|
-
}.
|
235
|
+
}.to raise_error(RuntimeError)
|
236
236
|
end
|
237
237
|
end
|
238
238
|
end
|
@@ -240,12 +240,12 @@ end
|
|
240
240
|
describe SparkApi::Authentication::BaseOAuth2Provider do
|
241
241
|
context "session_timeout" do
|
242
242
|
it "should provide a default" do
|
243
|
-
subject.session_timeout.
|
243
|
+
expect(subject.session_timeout).to eq(86400)
|
244
244
|
end
|
245
245
|
describe TestOAuth2Provider do
|
246
246
|
subject { TestOAuth2Provider.new }
|
247
247
|
it "should be able to override the session timeout" do
|
248
|
-
subject.session_timeout.
|
248
|
+
expect(subject.session_timeout).to eq(57600)
|
249
249
|
end
|
250
250
|
end
|
251
251
|
end
|
@@ -260,18 +260,18 @@ describe "password authentication" do
|
|
260
260
|
with(:body =>
|
261
261
|
'{"client_id":"example-id","client_secret":"example-secret","grant_type":"password","password":"example-password","username":"example-user"}'
|
262
262
|
).to_return(:body => fixture("oauth2/access.json"), :status=>200)
|
263
|
-
subject.authenticate.access_token.
|
264
|
-
subject.authenticate.expires_in.
|
263
|
+
expect(subject.authenticate.access_token).to eq("04u7h-4cc355-70k3n")
|
264
|
+
expect(subject.authenticate.expires_in).to eq(60)
|
265
265
|
end
|
266
266
|
end
|
267
267
|
describe SparkApi::Authentication::OAuth2Impl do
|
268
268
|
it "should load a provider" do
|
269
269
|
example = "SparkApi::Authentication::OAuth2Impl::CLIProvider"
|
270
|
-
SparkApi::Authentication::OAuth2Impl.load_provider(example,{}).class.to_s.
|
270
|
+
expect(SparkApi::Authentication::OAuth2Impl.load_provider(example,{}).class.to_s).to eq(example)
|
271
271
|
prefix = "::#{example}"
|
272
|
-
SparkApi::Authentication::OAuth2Impl.load_provider(prefix,{}).class.to_s.
|
272
|
+
expect(SparkApi::Authentication::OAuth2Impl.load_provider(prefix,{}).class.to_s).to eq(example)
|
273
273
|
bad_example = "Derp::Derp::Derp::DerpProvider"
|
274
|
-
expect{SparkApi::Authentication::OAuth2Impl.load_provider(bad_example,{}).class.to_s.
|
274
|
+
expect{expect(SparkApi::Authentication::OAuth2Impl.load_provider(bad_example,{}).class.to_s).to eq(bad_example)}.to raise_error(ArgumentError)
|
275
275
|
end
|
276
276
|
|
277
277
|
end
|
@@ -286,8 +286,8 @@ describe SparkApi::Authentication::OAuthSession do
|
|
286
286
|
"start_time" => "2012-01-01T00:00:00+00:00"
|
287
287
|
}
|
288
288
|
session = SparkApi::Authentication::OAuthSession.new(args)
|
289
|
-
session.start_time.
|
290
|
-
JSON.parse(session.to_json).
|
289
|
+
expect(session.start_time).to eq(DateTime.parse(args["start_time"]))
|
290
|
+
expect(JSON.parse(session.to_json)).to eq(args)
|
291
291
|
end
|
292
292
|
|
293
293
|
it "should accept symbolized parameters" do
|
@@ -299,12 +299,12 @@ describe SparkApi::Authentication::OAuthSession do
|
|
299
299
|
:start_time => "2012-01-01T00:00:00+00:00"
|
300
300
|
}
|
301
301
|
session = SparkApi::Authentication::OAuthSession.new(args)
|
302
|
-
session.start_time.
|
303
|
-
JSON.parse(session.to_json).
|
302
|
+
expect(session.start_time).to eq(DateTime.parse(args[:start_time]))
|
303
|
+
expect(JSON.parse(session.to_json)).to eq(JSON.parse(args.to_json))
|
304
304
|
end
|
305
305
|
|
306
306
|
it "should not expire if expires_in is nil" do
|
307
307
|
session = SparkApi::Authentication::OAuthSession.new
|
308
|
-
session.expired
|
308
|
+
expect(session.expired?).to eq(false)
|
309
309
|
end
|
310
310
|
end
|
@@ -13,7 +13,7 @@ describe SparkApi::Authentication do
|
|
13
13
|
client = SparkApi.client
|
14
14
|
stub_auth_request
|
15
15
|
session = client.get "/session/c401736bf3d3f754f07c04e460e09573"
|
16
|
-
session[0]["AuthToken"].
|
16
|
+
expect(session[0]["AuthToken"]).to eq("c401736bf3d3f754f07c04e460e09573")
|
17
17
|
end
|
18
18
|
it "should delete a session" do
|
19
19
|
stub_auth_request
|
@@ -26,7 +26,7 @@ describe SparkApi::Authentication do
|
|
26
26
|
to_return(:body => fixture("success.json"))
|
27
27
|
client = SparkApi.client
|
28
28
|
client.logout
|
29
|
-
client.session.
|
29
|
+
expect(client.session).to eq(nil)
|
30
30
|
end
|
31
31
|
|
32
32
|
end
|
@@ -4,70 +4,70 @@ describe SparkApi::Configuration::YamlConfig, "Yaml Config" do
|
|
4
4
|
describe "api auth" do
|
5
5
|
let(:api_file){ "spec/config/spark_api/test_key.yml" }
|
6
6
|
it "should load a configured api key for development" do
|
7
|
-
subject.
|
8
|
-
subject.api_env.
|
7
|
+
allow(subject).to receive(:env){ {} }
|
8
|
+
expect(subject.api_env).to eq("development")
|
9
9
|
subject.load_file(api_file)
|
10
|
-
subject.oauth2
|
11
|
-
subject.ssl_verify
|
12
|
-
subject.api_key.
|
13
|
-
subject.api_secret.
|
14
|
-
subject.endpoint.
|
15
|
-
subject.name.
|
16
|
-
subject.client_keys.keys.
|
17
|
-
subject.oauth2_keys.keys.
|
10
|
+
expect(subject.oauth2?).to eq(false)
|
11
|
+
expect(subject.ssl_verify?).to eq(false)
|
12
|
+
expect(subject.api_key).to eq("demo_key")
|
13
|
+
expect(subject.api_secret).to eq("t3sts3cr3t")
|
14
|
+
expect(subject.endpoint).to eq("https://developers.sparkapi.com")
|
15
|
+
expect(subject.name).to eq("test_key")
|
16
|
+
expect(subject.client_keys.keys).to match_array([:api_key, :api_secret, :endpoint, :ssl_verify])
|
17
|
+
expect(subject.oauth2_keys.keys).to eq([])
|
18
18
|
end
|
19
19
|
it "should load a configured api key for production" do
|
20
|
-
subject.
|
21
|
-
subject.api_env.
|
20
|
+
allow(subject).to receive(:env){ {"SPARK_API_ENV" => "production"} }
|
21
|
+
expect(subject.api_env).to eq("production")
|
22
22
|
subject.load_file(api_file)
|
23
|
-
subject.oauth2
|
24
|
-
subject.api_key.
|
25
|
-
subject.api_secret.
|
26
|
-
subject.endpoint.
|
23
|
+
expect(subject.oauth2?).to eq(false)
|
24
|
+
expect(subject.api_key).to eq("prod_demo_key")
|
25
|
+
expect(subject.api_secret).to eq("prod_t3sts3cr3t")
|
26
|
+
expect(subject.endpoint).to eq("https://api.sparkapi.com")
|
27
27
|
end
|
28
28
|
it "should raise an error for a bad configuration" do
|
29
|
-
subject.
|
29
|
+
allow(subject).to receive(:env){ {} }
|
30
30
|
expect { subject.load_file("spec/config/spark_api/some_random_key.yml")}.to raise_error
|
31
|
-
subject.
|
31
|
+
allow(subject).to receive(:env){ {"RAILS_ENV" => "fake_env"} }
|
32
32
|
expect { subject.load_file(api_file)}.to raise_error
|
33
33
|
end
|
34
34
|
end
|
35
35
|
describe "oauth2" do
|
36
36
|
let(:oauth2_file){ "spec/config/spark_api/test_oauth.yml" }
|
37
37
|
it "should load a configured api key for development" do
|
38
|
-
subject.
|
39
|
-
subject.api_env.
|
38
|
+
allow(subject).to receive(:env){ {} }
|
39
|
+
expect(subject.api_env).to eq("development")
|
40
40
|
subject.load_file(oauth2_file)
|
41
|
-
subject.oauth2
|
42
|
-
subject.authorization_uri.
|
43
|
-
subject.access_uri.
|
44
|
-
subject.redirect_uri.
|
45
|
-
subject.client_id.
|
46
|
-
subject.client_secret.
|
47
|
-
subject.endpoint.
|
48
|
-
subject.oauth2_provider.
|
49
|
-
subject.name.
|
50
|
-
subject.client_keys.keys.
|
51
|
-
subject.oauth2_keys.keys.
|
41
|
+
expect(subject.oauth2?).to eq(true)
|
42
|
+
expect(subject.authorization_uri).to eq("https://developers.sparkplatform.com/oauth2")
|
43
|
+
expect(subject.access_uri).to eq("https://developers.sparkapi.com/v1/oauth2/grant")
|
44
|
+
expect(subject.redirect_uri).to eq("http://localhost/oauth2/callback")
|
45
|
+
expect(subject.client_id).to eq("developmentid124nj4qu3pua")
|
46
|
+
expect(subject.client_secret).to eq("developmentsecret4orkp29f")
|
47
|
+
expect(subject.endpoint).to eq("https://developers.sparkapi.com")
|
48
|
+
expect(subject.oauth2_provider).to eq("SparkApi::TestOAuth2Provider")
|
49
|
+
expect(subject.name).to eq("test_oauth")
|
50
|
+
expect(subject.client_keys.keys).to match_array([:endpoint, :oauth2_provider])
|
51
|
+
expect(subject.oauth2_keys.keys).to match_array([:authorization_uri, :client_id, :access_uri, :client_secret, :redirect_uri, :sparkbar_uri])
|
52
52
|
end
|
53
53
|
it "should load a configured api key for production" do
|
54
|
-
subject.
|
55
|
-
subject.api_env.
|
54
|
+
allow(subject).to receive(:env){ {"SPARK_API_ENV" => "production"} }
|
55
|
+
expect(subject.api_env).to eq("production")
|
56
56
|
subject.load_file(oauth2_file)
|
57
|
-
subject.oauth2
|
58
|
-
subject.authorization_uri.
|
59
|
-
subject.access_uri.
|
60
|
-
subject.redirect_uri.
|
61
|
-
subject.client_id.
|
62
|
-
subject.client_secret.
|
63
|
-
subject.endpoint.
|
64
|
-
subject.oauth2_provider.
|
65
|
-
subject.name.
|
57
|
+
expect(subject.oauth2?).to eq(true)
|
58
|
+
expect(subject.authorization_uri).to eq("https://sparkplatform.com/oauth2")
|
59
|
+
expect(subject.access_uri).to eq("https://api.sparkapi.com/v1/oauth2/grant")
|
60
|
+
expect(subject.redirect_uri).to eq("http://localhost/oauth2/callback")
|
61
|
+
expect(subject.client_id).to eq("production1id124nj4qu3pua")
|
62
|
+
expect(subject.client_secret).to eq("productionsecret4orkp29fv")
|
63
|
+
expect(subject.endpoint).to eq("https://api.sparkapi.com")
|
64
|
+
expect(subject.oauth2_provider).to eq(subject.class::DEFAULT_OAUTH2_PROVIDER)
|
65
|
+
expect(subject.name).to eq("test_oauth")
|
66
66
|
end
|
67
67
|
|
68
68
|
it "should list available keys" do
|
69
|
-
SparkApi::Configuration::YamlConfig.
|
70
|
-
subject.class.config_keys.
|
69
|
+
allow(SparkApi::Configuration::YamlConfig).to receive(:config_path) { "spec/config/spark_api" }
|
70
|
+
expect(subject.class.config_keys).to match_array(["test_key", "test_oauth", "test_single_session_oauth"])
|
71
71
|
end
|
72
72
|
end
|
73
73
|
end
|