Skip to content

Commit

Permalink
[Gradle Release Plugin] - pre tag commit: 'v0.5.1'.
Browse files Browse the repository at this point in the history
  • Loading branch information
tyvsmith committed Jun 8, 2016
1 parent 782e6d8 commit 9385722
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 9 deletions.
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
v0.5.1 - 6/7/2016
------------
### Fixed
- [Issue #14](https://github.com/uber/rides-java-sdk/issues/14) Adjust RefreshAuthenticator to ignore Invalid scope


v0.5.0 - 6/2/2016
------------------
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.
Expand Down Expand Up @@ -26,7 +32,7 @@ Replaces `UberRidesSyncService` and `UberRidesAsyncService` with a Retrofit 2 ba
- Updated from Retrofit 1 to Retrofit 2
- Updated from OkHttp2 to OkHttp3
- Removed Gauva dependency

### Breaking
- Removed `UberServices` in favor of `UberRidesApi`
- Removed `UberRidesSyncService` and `UberRidesAsyncService` in favor of `RidesService`
Expand All @@ -45,4 +51,3 @@ v0.2.0 - 2/25/2016
v0.1.0 - 9/23/2015
------------------
- Initial version.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Note: Using Android? Be sure to checkout the [Uber Android SDK](github.com/uber/
If using Gradle, add this to your project’s `build.gradle` file:
```gradle
dependencies {
compile 'com.uber.sdk:rides:0.5.0'
compile 'com.uber.sdk:rides:0.5.1'
}
```

Expand All @@ -24,7 +24,7 @@ If using Maven, add this to your project's `pom.xml` file:
<dependency>
<groupId>com.uber.sdk</groupId>
<artifactId>rides</artifactId>
<version>0.5.0</version>
<version>0.5.1</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ group=com.uber.sdk
groupId=com.uber.sdk
artifactId=rides
githubDownloadPrefix=https://github.com/uber/rides-java-sdk/releases/download/
version=0.5.1-SNAPSHOT
version=0.5.1
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class ApiInterceptor implements Interceptor {
static final String HEADER_ACCESS_TOKEN = "Authorization";


static final String LIB_VERSION = "0.5.0";
static final String LIB_VERSION = "0.5.1";
static final String HEADER_ACCEPT_LANGUAGE = "Accept-Language";
static final String HEADER_USER_AGENT = "X-Uber-User-Agent";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

public class RefreshAuthenticator implements okhttp3.Authenticator {

static final String HEADER_INVALID_SCOPES = "X-Uber-Missing-Scopes";
static final int MAX_RETRIES = 3;
public final Authenticator authenticator;

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

@Override
public Request authenticate(Route route, Response response) throws IOException {
if (authenticator.isRefreshable() && canRetry(response)) {
if (authenticator.isRefreshable() && canRefresh(response) && canRetry(response)) {
return authenticator.refresh(response);
}

return null;
}

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


boolean canRetry(Response response) {
int responseCount = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,29 +51,54 @@ public void testAuthenticate_canReAuthAndRetry_callsRefresh() throws Exception {
doReturn(new Request.Builder().url("http://test").build()).when(authenticator).refresh(eq(response));
doReturn(true).when(authenticator).isRefreshable();
doReturn(true).when(refreshAuthenticator).canRetry(eq(response));
doReturn(true).when(refreshAuthenticator).canRefresh(eq(response));

assertNotNull(refreshAuthenticator.authenticate(null, response));
verify(authenticator).refresh(eq(response));
}

@Test
public void testAuthenticate_canReAuthButCannotRetry_callsRefresh() throws Exception {
public void testAuthenticate_canReAuthButCannotRetry_returnsNull() throws Exception {
doReturn(true).when(authenticator).isRefreshable();
doReturn(false).when(refreshAuthenticator).canRetry(eq(response));
doReturn(true).when(refreshAuthenticator).canRefresh(eq(response));

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

@Test
public void testAuthenticate_cannotReAuthButCanRetry_callsRefresh() throws Exception {
public void testAuthenticate_cannotReAuthButCanRetry_returnsNull() throws Exception {
doReturn(false).when(authenticator).isRefreshable();
doReturn(true).when(refreshAuthenticator).canRetry(eq(response));
doReturn(true).when(refreshAuthenticator).canRefresh(eq(response));

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

@Test
public void testAuthenticate_canReAuthRetryButCannotRefresh_returnsNull() throws Exception {
doReturn(true).when(authenticator).isRefreshable();
doReturn(true).when(refreshAuthenticator).canRetry(eq(response));
doReturn(false).when(refreshAuthenticator).canRefresh(eq(response));

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

@Test
public void testCanRefresh_whenContainsHeader_returnsFalse() {
Response cannotRefresh = response.newBuilder().header(RefreshAuthenticator.HEADER_INVALID_SCOPES, "true").build();
assertFalse(refreshAuthenticator.canRefresh(cannotRefresh));
}

@Test
public void testCanRefresh_whenMissingHeader_returnsTrue() {
Response canRefresh = response.newBuilder().build();
assertTrue(refreshAuthenticator.canRefresh(canRefresh));
}

@Test
public void testCanRetry_whenUnderMax_returnsTrue() throws Exception {
Response underMax = response.newBuilder().priorResponse(response).build();
Expand Down

0 comments on commit 9385722

Please sign in to comment.