OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library oauth2_test; | 5 library oauth2_test; |
6 | 6 |
7 import 'dart:io'; | 7 import 'dart:io'; |
8 import 'dart:json' as json; | 8 import 'dart:json' as json; |
9 import 'dart:uri'; | 9 import 'dart:uri'; |
10 | 10 |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 }); | 140 }); |
141 | 141 |
142 | 142 |
143 // After we give pub an invalid response, it should crash. We wait for it to | 143 // After we give pub an invalid response, it should crash. We wait for it to |
144 // do so rather than killing it so it'll write out the credentials file. | 144 // do so rather than killing it so it'll write out the credentials file. |
145 pub.shouldExit(1); | 145 pub.shouldExit(1); |
146 | 146 |
147 credentialsFile(server, 'new access token').scheduleValidate(); | 147 credentialsFile(server, 'new access token').scheduleValidate(); |
148 }); | 148 }); |
149 | 149 |
| 150 // Regression test for issue 8849. |
| 151 integration('with a server-rejected refresh token, authenticates again and ' |
| 152 'saves credentials.json', () { |
| 153 var server = new ScheduledServer(); |
| 154 credentialsFile(server, 'access token', |
| 155 refreshToken: 'bad refresh token', |
| 156 expiration: new DateTime.now().subtract(new Duration(hours: 1))) |
| 157 .scheduleCreate(); |
| 158 |
| 159 var pub = startPubLish(server); |
| 160 confirmPublish(pub); |
| 161 |
| 162 server.handle('POST', '/token', (request, response) { |
| 163 return new ByteStream(request).toBytes().then((bytes) { |
| 164 response.statusCode = 400; |
| 165 response.reasonPhrase = 'Bad request'; |
| 166 response.headers.contentType = new ContentType("application", "json"); |
| 167 response.write(json.stringify({"error": "invalid_request"})); |
| 168 response.close(); |
| 169 }); |
| 170 }); |
| 171 |
| 172 authorizePub(pub, server, 'new access token'); |
| 173 |
| 174 server.handle('GET', '/packages/versions/new.json', (request, response) { |
| 175 expect(request.headers.value('authorization'), |
| 176 equals('Bearer new access token')); |
| 177 |
| 178 response.close(); |
| 179 }); |
| 180 |
| 181 pub.kill(); |
| 182 }); |
| 183 |
150 integration('with server-rejected credentials, authenticates again and saves ' | 184 integration('with server-rejected credentials, authenticates again and saves ' |
151 'credentials.json', () { | 185 'credentials.json', () { |
152 var server = new ScheduledServer(); | 186 var server = new ScheduledServer(); |
153 credentialsFile(server, 'access token').scheduleCreate(); | 187 credentialsFile(server, 'access token').scheduleCreate(); |
154 var pub = startPubLish(server); | 188 var pub = startPubLish(server); |
155 | 189 |
156 confirmPublish(pub); | 190 confirmPublish(pub); |
157 | 191 |
158 server.handle('GET', '/packages/versions/new.json', (request, response) { | 192 server.handle('GET', '/packages/versions/new.json', (request, response) { |
159 response.statusCode = 401; | 193 response.statusCode = 401; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 | 245 |
212 response.headers.contentType = new ContentType("application", "json"); | 246 response.headers.contentType = new ContentType("application", "json"); |
213 response.write(json.stringify({ | 247 response.write(json.stringify({ |
214 "access_token": accessToken, | 248 "access_token": accessToken, |
215 "token_type": "bearer" | 249 "token_type": "bearer" |
216 })); | 250 })); |
217 response.close(); | 251 response.close(); |
218 }); | 252 }); |
219 }); | 253 }); |
220 } | 254 } |
| 255 |
OLD | NEW |