Skip to content

Commit 9385722

Browse files
committed
[Gradle Release Plugin] - pre tag commit: 'v0.5.1'.
1 parent 782e6d8 commit 9385722

File tree

6 files changed

+51
-9
lines changed

6 files changed

+51
-9
lines changed

CHANGELOG.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
v0.5.1 - 6/7/2016
2+
------------
3+
### Fixed
4+
- [Issue #14](https://github.com/uber/rides-java-sdk/issues/14) Adjust RefreshAuthenticator to ignore Invalid scope
5+
6+
17
v0.5.0 - 6/2/2016
28
------------------
39
This release sets up the Java SDK for the Uber Android SDK to utilize it as a third party dependency by adding common interfaces and removing heavier weight components.
@@ -26,7 +32,7 @@ Replaces `UberRidesSyncService` and `UberRidesAsyncService` with a Retrofit 2 ba
2632
- Updated from Retrofit 1 to Retrofit 2
2733
- Updated from OkHttp2 to OkHttp3
2834
- Removed Gauva dependency
29-
35+
3036
### Breaking
3137
- Removed `UberServices` in favor of `UberRidesApi`
3238
- Removed `UberRidesSyncService` and `UberRidesAsyncService` in favor of `RidesService`
@@ -45,4 +51,3 @@ v0.2.0 - 2/25/2016
4551
v0.1.0 - 9/23/2015
4652
------------------
4753
- Initial version.
48-

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Note: Using Android? Be sure to checkout the [Uber Android SDK](github.com/uber/
1414
If using Gradle, add this to your project’s `build.gradle` file:
1515
```gradle
1616
dependencies {
17-
compile 'com.uber.sdk:rides:0.5.0'
17+
compile 'com.uber.sdk:rides:0.5.1'
1818
}
1919
```
2020

@@ -24,7 +24,7 @@ If using Maven, add this to your project's `pom.xml` file:
2424
<dependency>
2525
<groupId>com.uber.sdk</groupId>
2626
<artifactId>rides</artifactId>
27-
<version>0.5.0</version>
27+
<version>0.5.1</version>
2828
</dependency>
2929
```
3030

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ group=com.uber.sdk
2424
groupId=com.uber.sdk
2525
artifactId=rides
2626
githubDownloadPrefix=https://github.com/uber/rides-java-sdk/releases/download/
27-
version=0.5.1-SNAPSHOT
27+
version=0.5.1

sdk/src/main/java/com/uber/sdk/rides/client/internal/ApiInterceptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class ApiInterceptor implements Interceptor {
3434
static final String HEADER_ACCESS_TOKEN = "Authorization";
3535

3636

37-
static final String LIB_VERSION = "0.5.0";
37+
static final String LIB_VERSION = "0.5.1";
3838
static final String HEADER_ACCEPT_LANGUAGE = "Accept-Language";
3939
static final String HEADER_USER_AGENT = "X-Uber-User-Agent";
4040

sdk/src/main/java/com/uber/sdk/rides/client/internal/RefreshAuthenticator.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
public class RefreshAuthenticator implements okhttp3.Authenticator {
3434

35+
static final String HEADER_INVALID_SCOPES = "X-Uber-Missing-Scopes";
3536
static final int MAX_RETRIES = 3;
3637
public final Authenticator authenticator;
3738

@@ -41,13 +42,24 @@ public RefreshAuthenticator(Authenticator authenticator) {
4142

4243
@Override
4344
public Request authenticate(Route route, Response response) throws IOException {
44-
if (authenticator.isRefreshable() && canRetry(response)) {
45+
if (authenticator.isRefreshable() && canRefresh(response) && canRetry(response)) {
4546
return authenticator.refresh(response);
4647
}
4748

4849
return null;
4950
}
5051

52+
/**
53+
* The Uber API returns invalid scopes as 401's and will migrate to 403's in the future.
54+
* This is a temporary measure and will be updated in the future.
55+
*
56+
* @param response to check for {@link RefreshAuthenticator#HEADER_INVALID_SCOPES} header.
57+
* @return true if a true 401 and can refresh, otherwise false
58+
*/
59+
boolean canRefresh(Response response) {
60+
return response.header(HEADER_INVALID_SCOPES) == null;
61+
}
62+
5163

5264
boolean canRetry(Response response) {
5365
int responseCount = 1;

sdk/src/test/java/com/uber/sdk/rides/client/internal/RefreshAuthenticatorTest.java

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,29 +51,54 @@ public void testAuthenticate_canReAuthAndRetry_callsRefresh() throws Exception {
5151
doReturn(new Request.Builder().url("http://test").build()).when(authenticator).refresh(eq(response));
5252
doReturn(true).when(authenticator).isRefreshable();
5353
doReturn(true).when(refreshAuthenticator).canRetry(eq(response));
54+
doReturn(true).when(refreshAuthenticator).canRefresh(eq(response));
5455

5556
assertNotNull(refreshAuthenticator.authenticate(null, response));
5657
verify(authenticator).refresh(eq(response));
5758
}
5859

5960
@Test
60-
public void testAuthenticate_canReAuthButCannotRetry_callsRefresh() throws Exception {
61+
public void testAuthenticate_canReAuthButCannotRetry_returnsNull() throws Exception {
6162
doReturn(true).when(authenticator).isRefreshable();
6263
doReturn(false).when(refreshAuthenticator).canRetry(eq(response));
64+
doReturn(true).when(refreshAuthenticator).canRefresh(eq(response));
6365

6466
assertNull(refreshAuthenticator.authenticate(null, response));
6567
verify(authenticator, never()).refresh(eq(response));
6668
}
6769

6870
@Test
69-
public void testAuthenticate_cannotReAuthButCanRetry_callsRefresh() throws Exception {
71+
public void testAuthenticate_cannotReAuthButCanRetry_returnsNull() throws Exception {
7072
doReturn(false).when(authenticator).isRefreshable();
7173
doReturn(true).when(refreshAuthenticator).canRetry(eq(response));
74+
doReturn(true).when(refreshAuthenticator).canRefresh(eq(response));
7275

7376
assertNull(refreshAuthenticator.authenticate(null, response));
7477
verify(authenticator, never()).refresh(eq(response));
7578
}
7679

80+
@Test
81+
public void testAuthenticate_canReAuthRetryButCannotRefresh_returnsNull() throws Exception {
82+
doReturn(true).when(authenticator).isRefreshable();
83+
doReturn(true).when(refreshAuthenticator).canRetry(eq(response));
84+
doReturn(false).when(refreshAuthenticator).canRefresh(eq(response));
85+
86+
assertNull(refreshAuthenticator.authenticate(null, response));
87+
verify(authenticator, never()).refresh(eq(response));
88+
}
89+
90+
@Test
91+
public void testCanRefresh_whenContainsHeader_returnsFalse() {
92+
Response cannotRefresh = response.newBuilder().header(RefreshAuthenticator.HEADER_INVALID_SCOPES, "true").build();
93+
assertFalse(refreshAuthenticator.canRefresh(cannotRefresh));
94+
}
95+
96+
@Test
97+
public void testCanRefresh_whenMissingHeader_returnsTrue() {
98+
Response canRefresh = response.newBuilder().build();
99+
assertTrue(refreshAuthenticator.canRefresh(canRefresh));
100+
}
101+
77102
@Test
78103
public void testCanRetry_whenUnderMax_returnsTrue() throws Exception {
79104
Response underMax = response.newBuilder().priorResponse(response).build();

0 commit comments

Comments
 (0)