|
106 | 106 | its(:expires_in) { should == 3600 } |
107 | 107 | end |
108 | 108 |
|
109 | | - context 'when legacy-style (JSON) token is given' do |
| 109 | + context 'when no-type token is given (JSON)' do |
110 | 110 | before do |
111 | 111 | client.authorization_code = 'code' |
112 | 112 | fake_response( |
|
115 | 115 | 'tokens/legacy.json' |
116 | 116 | ) |
117 | 117 | end |
118 | | - it { should be_instance_of ActiveSupport::HashWithIndifferentAccess } |
119 | | - it do |
120 | | - client.access_token!.should == { |
121 | | - 'access_token' => 'access_token', |
122 | | - 'refresh_token' => 'refresh_token', |
123 | | - 'expires_in' => 3600 |
124 | | - } |
125 | | - end |
| 118 | + it { should be_instance_of Rack::OAuth2::AccessToken::Legacy } |
| 119 | + its(:token_type) { should == :legacy } |
| 120 | + its(:access_token) { should == 'access_token' } |
| 121 | + its(:refresh_token) { should == 'refresh_token' } |
| 122 | + its(:expires_in) { should == 3600 } |
126 | 123 | end |
127 | 124 |
|
128 | | - context 'when legacy-style (key-value) response is given' do |
| 125 | + context 'when no-type token is given (key-value)' do |
129 | 126 | before do |
130 | 127 | fake_response( |
131 | 128 | :post, |
132 | 129 | 'https://server.example.com/oauth2/token', |
133 | 130 | 'tokens/legacy.txt' |
134 | 131 | ) |
135 | 132 | end |
136 | | - it { should be_instance_of ActiveSupport::HashWithIndifferentAccess } |
| 133 | + it { should be_instance_of Rack::OAuth2::AccessToken::Legacy } |
| 134 | + its(:token_type) { should == :legacy } |
| 135 | + its(:access_token) { should == 'access_token' } |
| 136 | + its(:expires_in) { should == 3600 } |
| 137 | + |
| 138 | + context 'when expires_in is not given' do |
| 139 | + before do |
| 140 | + fake_response( |
| 141 | + :post, |
| 142 | + 'https://server.example.com/oauth2/token', |
| 143 | + 'tokens/legacy_without_expires_in.txt' |
| 144 | + ) |
| 145 | + end |
| 146 | + its(:expires_in) { should be_nil } |
| 147 | + end |
| 148 | + end |
| 149 | + |
| 150 | + context 'when unknown-type token is given' do |
| 151 | + before do |
| 152 | + client.authorization_code = 'code' |
| 153 | + fake_response( |
| 154 | + :post, |
| 155 | + 'https://server.example.com/oauth2/token', |
| 156 | + 'tokens/unknown.json' |
| 157 | + ) |
| 158 | + end |
137 | 159 | it do |
138 | | - client.access_token!.should == { |
139 | | - 'access_token' => 'access_token', |
140 | | - 'expires_in' => '3600' # NOTE: String not Integer |
141 | | - } |
| 160 | + expect { client.access_token! }.should raise_error(StandardError, 'Unknown Token Type') |
142 | 161 | end |
143 | 162 | end |
144 | 163 |
|
|
0 commit comments