This repository has been archived by the owner on Nov 10, 2017. It is now read-only.
/
access_token_spec.rb
133 lines (102 loc) · 4.31 KB
/
access_token_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
require "fakeweb"
require "oauth"
require "quickeebooks"
describe "Quickeebooks::Shared::Service::AccessToken" do
shared_examples "access_token_operations" do
context "reconnect" do
let(:reconnect_url){ "https://appcenter.intuit.com/api/v1/Connection/Reconnect" }
it "can successfully reconnect" do
xml = sharedFixture("reconnect_success.xml")
FakeWeb.register_uri(:get, reconnect_url, :status => ["200", "OK"], :body => xml)
response = @service.reconnect
response.error?.should be_false
response.token.should == "qye2eIdQ5H5yMyrlJflUWh712xfFXjyNnW1MfbC0rz04TfCP"
response.secret.should == "cyDeUNQTkFzoR0KkDn7viN6uLQxWTobeEUKW7I79"
end
it "can handle expired tokens" do
xml = sharedFixture("reconnect_error_expired.xml")
FakeWeb.register_uri(:get, reconnect_url, :status => ["200", "OK"], :body => xml)
response = @service.reconnect
response.error?.should be_true
response.error_code.should == "270"
response.error_message.should == "OAuth Token Rejected"
end
it "can handle out-of-bounds refresh windows" do
xml = sharedFixture("reconnect_error_out_of_bounds.xml")
FakeWeb.register_uri(:get, reconnect_url, :status => ["200", "OK"], :body => xml)
response = @service.reconnect
response.error?.should be_true
response.error_code.should == "212"
response.error_message.should == "Token Refresh Window Out of Bounds"
end
it "can handle unapproved apps" do
xml = sharedFixture("reconnect_error_not_approved.xml")
FakeWeb.register_uri(:get, reconnect_url, :status => ["200", "OK"], :body => xml)
response = @service.reconnect
response.error?.should be_true
response.error_code.should == "24"
response.error_message.should == "Invalid App Token"
end
end
context "disconnect" do
let(:disconnect_url){ "https://appcenter.intuit.com/api/v1/Connection/Disconnect" }
it "can successfully disconnect" do
xml = sharedFixture("disconnect_success.xml")
FakeWeb.register_uri(:get, disconnect_url, :status => ["200", "OK"], :body => xml)
response = @service.disconnect
response.error?.should be_false
end
it "can handle invalid tokens" do
xml = sharedFixture("disconnect_invalid.xml")
FakeWeb.register_uri(:get, disconnect_url, :status => ["200", "OK"], :body => xml)
response = @service.disconnect
response.error?.should be_true
response.error_code.should == "270"
response.error_message.should == "OAuth Token rejected"
end
end
end
context "online" do
before(:all) do
FakeWeb.allow_net_connect = false
qb_key = "key"
qb_secret = "secreet"
@realm_id = "9991111222"
@oauth_consumer = OAuth::Consumer.new(qb_key, qb_key, {
:site => "https://oauth.intuit.com",
:request_token_path => "/oauth/v1/get_request_token",
:authorize_path => "/oauth/v1/get_access_token",
:access_token_path => "/oauth/v1/get_access_token"
})
@oauth = OAuth::AccessToken.new(@oauth_consumer, "blah", "blah")
@service = Quickeebooks::Online::Service::AccessToken.new
@service.access_token = @oauth
@service.instance_eval {
@realm_id = "9991111222"
}
end
it_behaves_like "access_token_operations"
end
context "windows" do
before(:all) do
FakeWeb.allow_net_connect = false
qb_key = "key"
qb_secret = "secreet"
@realm_id = "9991111222"
#@base_uri = "https://qbo.intuit.com/qbo36"
@oauth_consumer = OAuth::Consumer.new(qb_key, qb_key, {
:site => "https://oauth.intuit.com",
:request_token_path => "/oauth/v1/get_request_token",
:authorize_path => "/oauth/v1/get_access_token",
:access_token_path => "/oauth/v1/get_access_token"
})
@oauth = OAuth::AccessToken.new(@oauth_consumer, "blah", "blah")
@service = Quickeebooks::Windows::Service::AccessToken.new
@service.access_token = @oauth
@service.instance_eval {
@realm_id = "9991111222"
}
end
it_behaves_like "access_token_operations"
end
end