From 252223d3572c0d8f2310851bc1547b85625f9cb8 Mon Sep 17 00:00:00 2001 From: mfeltmann Date: Wed, 11 Jan 2017 12:42:59 +0100 Subject: [PATCH 01/10] Provided test for 400 status response --- .../openid/appauth/AuthorizationServiceTest.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/library/javatests/net/openid/appauth/AuthorizationServiceTest.java b/library/javatests/net/openid/appauth/AuthorizationServiceTest.java index 7f239a66..4ac407f9 100644 --- a/library/javatests/net/openid/appauth/AuthorizationServiceTest.java +++ b/library/javatests/net/openid/appauth/AuthorizationServiceTest.java @@ -55,6 +55,7 @@ import java.net.URL; import java.net.URLConnection; import java.net.URLStreamHandler; +import java.nio.charset.StandardCharsets; import java.util.Map; import java.util.concurrent.Semaphore; import java.util.concurrent.TimeUnit; @@ -219,6 +220,21 @@ public void testTokenRequest_IoException() throws Exception { assertEquals(GeneralErrors.NETWORK_ERROR, mAuthCallback.error); } + @Test + public void testTokenRequest_400StatusCode() throws Exception { + + Exception ex = new IOException(); + when(mHttpConnection.getInputStream()).thenThrow(ex); + final String json = "{\"error\":\"invalid_grant\"}"; + final InputStream errorJsonInputStream = new ByteArrayInputStream(json.getBytes("UTF-8")); + when(mHttpConnection.getErrorStream()).thenReturn(errorJsonInputStream); + + mService.performTokenRequest(getTestAuthCodeExchangeRequest(), mAuthCallback); + mAuthCallback.waitForCallback(); + assertNotNull(mAuthCallback.error); + assertEquals(AuthorizationException.TokenRequestErrors.INVALID_GRANT, mAuthCallback.error); + } + @Test public void testRegistrationRequest() throws Exception { InputStream is = new ByteArrayInputStream(REGISTRATION_RESPONSE_JSON.getBytes()); From 5bb5a2c3a319ff86b448efd03402ff06e338062c Mon Sep 17 00:00:00 2001 From: mfeltmann Date: Wed, 11 Jan 2017 14:00:50 +0100 Subject: [PATCH 02/10] Included error handling for existing error streams according to RFC6749 section 5 subsection 2 --- .../openid/appauth/AuthorizationService.java | 90 +++++++++++++++++-- 1 file changed, 84 insertions(+), 6 deletions(-) diff --git a/library/java/net/openid/appauth/AuthorizationService.java b/library/java/net/openid/appauth/AuthorizationService.java index ab0d541d..b07efc77 100644 --- a/library/java/net/openid/appauth/AuthorizationService.java +++ b/library/java/net/openid/appauth/AuthorizationService.java @@ -36,10 +36,13 @@ import org.json.JSONException; import org.json.JSONObject; +import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; +import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.net.HttpURLConnection; +import java.util.Locale; import java.util.Map; @@ -297,6 +300,47 @@ private void checkNotDisposed() { } } + private AuthorizationException exceptionForErrorStream(InputStream is, int errorType) + throws IOException, JSONException { + + BufferedReader inputReader = new BufferedReader(new InputStreamReader(is)); + StringBuilder jsonStringBuilder = new StringBuilder(); + String currentlyReadLine; + + try { + while (( currentlyReadLine = inputReader.readLine() ) != null) { + + jsonStringBuilder.append(currentlyReadLine); + } + + JSONObject jsonResult = new JSONObject(jsonStringBuilder.toString()); + String errorString = jsonResult.getString("error"); + switch (errorType) { + + case AuthorizationException.TYPE_OAUTH_TOKEN_ERROR: + return AuthorizationException.TokenRequestErrors.byString(errorString); + + case AuthorizationException.TYPE_OAUTH_REGISTRATION_ERROR: + return AuthorizationException.RegistrationRequestErrors.byString(errorString); + + case AuthorizationException.TYPE_OAUTH_AUTHORIZATION_ERROR: + return AuthorizationException.AuthorizationRequestErrors.byString(errorString); + } + + return AuthorizationException.fromTemplate(GeneralErrors.JSON_DESERIALIZATION_ERROR, new Throwable(new Exception(errorString + " not found"))); + } + catch (IOException ioExc) { + + return AuthorizationException.fromTemplate(GeneralErrors.NETWORK_ERROR, ioExc); + } + catch (JSONException jsonExc) { + + return AuthorizationException + .fromTemplate(GeneralErrors.JSON_DESERIALIZATION_ERROR, jsonExc); + } + } + + private class TokenRequestTask extends AsyncTask { private TokenRequest mRequest; @@ -345,9 +389,26 @@ protected JSONObject doInBackground(Void... voids) { wr.write(queryData); wr.flush(); - is = conn.getInputStream(); - String response = Utils.readInputStream(is); - return new JSONObject(response); + try { + is = conn.getInputStream(); + String response = Utils.readInputStream(is); + return new JSONObject(response); + } + catch (IOException isIoExc) { + + is = conn.getErrorStream(); + + if(is != null) { + + mException = exceptionForErrorStream(is, + AuthorizationException.TYPE_OAUTH_TOKEN_ERROR); + } + else { + + mException = AuthorizationException.fromTemplate( + GeneralErrors.NETWORK_ERROR, isIoExc); + } + } } catch (IOException ex) { Logger.debugWithStack(ex, "Failed to complete exchange request"); mException = AuthorizationException.fromTemplate( @@ -455,9 +516,26 @@ protected JSONObject doInBackground(Void... voids) { wr.write(postData); wr.flush(); - is = conn.getInputStream(); - String response = Utils.readInputStream(is); - return new JSONObject(response); + try { + is = conn.getInputStream(); + String response = Utils.readInputStream(is); + return new JSONObject(response); + } + catch (IOException isIoExc) { + + is = conn.getErrorStream(); + + if(is != null) { + + mException = exceptionForErrorStream(is, + AuthorizationException.TYPE_OAUTH_REGISTRATION_ERROR); + } + else { + + mException = AuthorizationException.fromTemplate( + GeneralErrors.NETWORK_ERROR, isIoExc); + } + } } catch (IOException ex) { Logger.debugWithStack(ex, "Failed to complete registration request"); mException = AuthorizationException.fromTemplate( From 8d323c8c010115882d51e19729bde269211568a9 Mon Sep 17 00:00:00 2001 From: mfeltmann Date: Wed, 11 Jan 2017 14:22:05 +0100 Subject: [PATCH 03/10] Fixed style issues --- .../net/openid/appauth/AuthorizationService.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/library/java/net/openid/appauth/AuthorizationService.java b/library/java/net/openid/appauth/AuthorizationService.java index b07efc77..44d01db8 100644 --- a/library/java/net/openid/appauth/AuthorizationService.java +++ b/library/java/net/openid/appauth/AuthorizationService.java @@ -42,7 +42,6 @@ import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.net.HttpURLConnection; -import java.util.Locale; import java.util.Map; @@ -325,9 +324,12 @@ private AuthorizationException exceptionForErrorStream(InputStream is, int error case AuthorizationException.TYPE_OAUTH_AUTHORIZATION_ERROR: return AuthorizationException.AuthorizationRequestErrors.byString(errorString); - } - return AuthorizationException.fromTemplate(GeneralErrors.JSON_DESERIALIZATION_ERROR, new Throwable(new Exception(errorString + " not found"))); + default: + return AuthorizationException.fromTemplate( + GeneralErrors.JSON_DESERIALIZATION_ERROR, + new Throwable(new Exception(errorString + " not found"))); + } } catch (IOException ioExc) { @@ -398,7 +400,7 @@ protected JSONObject doInBackground(Void... voids) { is = conn.getErrorStream(); - if(is != null) { + if (is != null) { mException = exceptionForErrorStream(is, AuthorizationException.TYPE_OAUTH_TOKEN_ERROR); @@ -525,7 +527,7 @@ protected JSONObject doInBackground(Void... voids) { is = conn.getErrorStream(); - if(is != null) { + if (is != null) { mException = exceptionForErrorStream(is, AuthorizationException.TYPE_OAUTH_REGISTRATION_ERROR); From 92fea0418559d45f41cc67aa13938d61c17bd968 Mon Sep 17 00:00:00 2001 From: mfeltmann Date: Thu, 12 Jan 2017 10:58:15 +0100 Subject: [PATCH 04/10] Implemented RegistrationRequest test for 400 status code --- .../net/openid/appauth/AuthorizationService.java | 9 +-------- .../openid/appauth/AuthorizationServiceTest.java | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/library/java/net/openid/appauth/AuthorizationService.java b/library/java/net/openid/appauth/AuthorizationService.java index 44d01db8..84fe3ebd 100644 --- a/library/java/net/openid/appauth/AuthorizationService.java +++ b/library/java/net/openid/appauth/AuthorizationService.java @@ -319,16 +319,9 @@ private AuthorizationException exceptionForErrorStream(InputStream is, int error case AuthorizationException.TYPE_OAUTH_TOKEN_ERROR: return AuthorizationException.TokenRequestErrors.byString(errorString); + default: case AuthorizationException.TYPE_OAUTH_REGISTRATION_ERROR: return AuthorizationException.RegistrationRequestErrors.byString(errorString); - - case AuthorizationException.TYPE_OAUTH_AUTHORIZATION_ERROR: - return AuthorizationException.AuthorizationRequestErrors.byString(errorString); - - default: - return AuthorizationException.fromTemplate( - GeneralErrors.JSON_DESERIALIZATION_ERROR, - new Throwable(new Exception(errorString + " not found"))); } } catch (IOException ioExc) { diff --git a/library/javatests/net/openid/appauth/AuthorizationServiceTest.java b/library/javatests/net/openid/appauth/AuthorizationServiceTest.java index 4ac407f9..b0665b5a 100644 --- a/library/javatests/net/openid/appauth/AuthorizationServiceTest.java +++ b/library/javatests/net/openid/appauth/AuthorizationServiceTest.java @@ -257,6 +257,21 @@ public void testRegistrationRequest_IoException() throws Exception { assertEquals(GeneralErrors.NETWORK_ERROR, mRegistrationCallback.error); } + @Test + public void testRegistrationRequest_400StatusCode() throws Exception { + + Exception ex = new IOException(); + when(mHttpConnection.getInputStream()).thenThrow(ex); + final String json = "{\"error\":\"invalid_request\"}"; + final InputStream errorJsonInputStream = new ByteArrayInputStream(json.getBytes("UTF-8")); + when(mHttpConnection.getErrorStream()).thenReturn(errorJsonInputStream); + + mService.performRegistrationRequest(getTestRegistrationRequest(), mRegistrationCallback); + mRegistrationCallback.waitForCallback(); + assertNotNull(mRegistrationCallback.error); + assertEquals(AuthorizationException.RegistrationRequestErrors.INVALID_REQUEST, + mRegistrationCallback.error); + } @Test(expected = IllegalStateException.class) public void testTokenRequest_afterDispose() throws Exception { mService.dispose(); From d3b8999e287e4b19b0ea5528544fb203faccc658 Mon Sep 17 00:00:00 2001 From: mfeltmann Date: Thu, 12 Jan 2017 11:06:10 +0100 Subject: [PATCH 05/10] Tests added for further exceptions --- .../appauth/AuthorizationServiceTest.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/library/javatests/net/openid/appauth/AuthorizationServiceTest.java b/library/javatests/net/openid/appauth/AuthorizationServiceTest.java index b0665b5a..78b80536 100644 --- a/library/javatests/net/openid/appauth/AuthorizationServiceTest.java +++ b/library/javatests/net/openid/appauth/AuthorizationServiceTest.java @@ -284,6 +284,33 @@ public void testCreateCustomTabsIntentBuilder_afterDispose() throws Exception { mService.createCustomTabsIntentBuilder(); } + @Test + public void testTokenRequest_400InvalidJsonBody() throws Exception { + + Exception ex = new IOException(); + when(mHttpConnection.getInputStream()).thenThrow(ex); + final String json = "{\"error\":\"invalid_grant"; + final InputStream errorJsonInputStream = new ByteArrayInputStream(json.getBytes("UTF-8")); + when(mHttpConnection.getErrorStream()).thenReturn(errorJsonInputStream); + + mService.performTokenRequest(getTestAuthCodeExchangeRequest(), mAuthCallback); + mAuthCallback.waitForCallback(); + assertNotNull(mAuthCallback.error); + assertEquals(GeneralErrors.JSON_DESERIALIZATION_ERROR, mAuthCallback.error); + } + + @Test + public void testTokenRequest_connectionOutputStreamException() throws Exception { + + Exception ex = new IOException(); + when(mHttpConnection.getOutputStream()).thenThrow(ex); + + mService.performTokenRequest(getTestAuthCodeExchangeRequest(), mAuthCallback); + mAuthCallback.waitForCallback(); + assertNotNull(mAuthCallback.error); + assertEquals(GeneralErrors.NETWORK_ERROR, mAuthCallback.error); + } + private Intent captureAuthRequestIntent() { ArgumentCaptor intentCaptor = ArgumentCaptor.forClass(Intent.class); verify(mContext).startActivity(intentCaptor.capture()); From 7d6d4eae4032dbcc298df238986485a4dc024270 Mon Sep 17 00:00:00 2001 From: mfeltmann Date: Thu, 12 Jan 2017 11:09:20 +0100 Subject: [PATCH 06/10] Further exception tests for RegistrationRequests --- .../appauth/AuthorizationServiceTest.java | 69 +++++++++++++------ 1 file changed, 48 insertions(+), 21 deletions(-) diff --git a/library/javatests/net/openid/appauth/AuthorizationServiceTest.java b/library/javatests/net/openid/appauth/AuthorizationServiceTest.java index 78b80536..f04d8a50 100644 --- a/library/javatests/net/openid/appauth/AuthorizationServiceTest.java +++ b/library/javatests/net/openid/appauth/AuthorizationServiceTest.java @@ -235,6 +235,33 @@ public void testTokenRequest_400StatusCode() throws Exception { assertEquals(AuthorizationException.TokenRequestErrors.INVALID_GRANT, mAuthCallback.error); } + @Test + public void testTokenRequest_400InvalidJsonBody() throws Exception { + + Exception ex = new IOException(); + when(mHttpConnection.getInputStream()).thenThrow(ex); + final String json = "{\"error\":\"invalid_grant"; + final InputStream errorJsonInputStream = new ByteArrayInputStream(json.getBytes("UTF-8")); + when(mHttpConnection.getErrorStream()).thenReturn(errorJsonInputStream); + + mService.performTokenRequest(getTestAuthCodeExchangeRequest(), mAuthCallback); + mAuthCallback.waitForCallback(); + assertNotNull(mAuthCallback.error); + assertEquals(GeneralErrors.JSON_DESERIALIZATION_ERROR, mAuthCallback.error); + } + + @Test + public void testTokenRequest_connectionOutputStreamException() throws Exception { + + Exception ex = new IOException(); + when(mHttpConnection.getOutputStream()).thenThrow(ex); + + mService.performTokenRequest(getTestAuthCodeExchangeRequest(), mAuthCallback); + mAuthCallback.waitForCallback(); + assertNotNull(mAuthCallback.error); + assertEquals(GeneralErrors.NETWORK_ERROR, mAuthCallback.error); + } + @Test public void testRegistrationRequest() throws Exception { InputStream is = new ByteArrayInputStream(REGISTRATION_RESPONSE_JSON.getBytes()); @@ -272,43 +299,43 @@ public void testRegistrationRequest_400StatusCode() throws Exception { assertEquals(AuthorizationException.RegistrationRequestErrors.INVALID_REQUEST, mRegistrationCallback.error); } - @Test(expected = IllegalStateException.class) - public void testTokenRequest_afterDispose() throws Exception { - mService.dispose(); - mService.performTokenRequest(getTestAuthCodeExchangeRequest(), mAuthCallback); - } - - @Test(expected = IllegalStateException.class) - public void testCreateCustomTabsIntentBuilder_afterDispose() throws Exception { - mService.dispose(); - mService.createCustomTabsIntentBuilder(); - } @Test - public void testTokenRequest_400InvalidJsonBody() throws Exception { + public void testRegistrationRequest_400InvalidJson() throws Exception { Exception ex = new IOException(); when(mHttpConnection.getInputStream()).thenThrow(ex); - final String json = "{\"error\":\"invalid_grant"; + final String json = "{\"error\":\"invalid_request"; final InputStream errorJsonInputStream = new ByteArrayInputStream(json.getBytes("UTF-8")); when(mHttpConnection.getErrorStream()).thenReturn(errorJsonInputStream); - mService.performTokenRequest(getTestAuthCodeExchangeRequest(), mAuthCallback); - mAuthCallback.waitForCallback(); - assertNotNull(mAuthCallback.error); - assertEquals(GeneralErrors.JSON_DESERIALIZATION_ERROR, mAuthCallback.error); + mService.performRegistrationRequest(getTestRegistrationRequest(), mRegistrationCallback); + mRegistrationCallback.waitForCallback(); + assertNotNull(mRegistrationCallback.error); + assertEquals(GeneralErrors.JSON_DESERIALIZATION_ERROR, mRegistrationCallback.error); } @Test - public void testTokenRequest_connectionOutputStreamException() throws Exception { + public void testRegistrationRequest_outputStreamException() throws Exception { Exception ex = new IOException(); when(mHttpConnection.getOutputStream()).thenThrow(ex); + mService.performRegistrationRequest(getTestRegistrationRequest(), mRegistrationCallback); + mRegistrationCallback.waitForCallback(); + assertNotNull(mRegistrationCallback.error); + assertEquals(GeneralErrors.NETWORK_ERROR, mRegistrationCallback.error); + } + @Test(expected = IllegalStateException.class) + public void testTokenRequest_afterDispose() throws Exception { + mService.dispose(); mService.performTokenRequest(getTestAuthCodeExchangeRequest(), mAuthCallback); - mAuthCallback.waitForCallback(); - assertNotNull(mAuthCallback.error); - assertEquals(GeneralErrors.NETWORK_ERROR, mAuthCallback.error); + } + + @Test(expected = IllegalStateException.class) + public void testCreateCustomTabsIntentBuilder_afterDispose() throws Exception { + mService.dispose(); + mService.createCustomTabsIntentBuilder(); } private Intent captureAuthRequestIntent() { From 5230b14a091df9711eac897383efa1e0465db6c5 Mon Sep 17 00:00:00 2001 From: mfeltmann Date: Thu, 12 Jan 2017 11:13:13 +0100 Subject: [PATCH 07/10] Removed unreached catches --- library/java/net/openid/appauth/AuthorizationService.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/library/java/net/openid/appauth/AuthorizationService.java b/library/java/net/openid/appauth/AuthorizationService.java index 84fe3ebd..16d84ad4 100644 --- a/library/java/net/openid/appauth/AuthorizationService.java +++ b/library/java/net/openid/appauth/AuthorizationService.java @@ -300,7 +300,7 @@ private void checkNotDisposed() { } private AuthorizationException exceptionForErrorStream(InputStream is, int errorType) - throws IOException, JSONException { + throws IOException { BufferedReader inputReader = new BufferedReader(new InputStreamReader(is)); StringBuilder jsonStringBuilder = new StringBuilder(); @@ -324,10 +324,6 @@ private AuthorizationException exceptionForErrorStream(InputStream is, int error return AuthorizationException.RegistrationRequestErrors.byString(errorString); } } - catch (IOException ioExc) { - - return AuthorizationException.fromTemplate(GeneralErrors.NETWORK_ERROR, ioExc); - } catch (JSONException jsonExc) { return AuthorizationException From b62685c6eabe10d35cc134059eaf28ffbc42305d Mon Sep 17 00:00:00 2001 From: mfeltmann Date: Thu, 12 Jan 2017 11:18:54 +0100 Subject: [PATCH 08/10] Tests added for invald json responses --- .../appauth/AuthorizationServiceTest.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/library/javatests/net/openid/appauth/AuthorizationServiceTest.java b/library/javatests/net/openid/appauth/AuthorizationServiceTest.java index f04d8a50..29426793 100644 --- a/library/javatests/net/openid/appauth/AuthorizationServiceTest.java +++ b/library/javatests/net/openid/appauth/AuthorizationServiceTest.java @@ -179,6 +179,17 @@ public void testTokenRequest() throws Exception { assertThat(postBody).isEqualTo(UriUtil.formUrlEncode(request.getRequestParameters())); } + @Test + public void testTokenRequest_invalidJson() throws Exception { + InputStream is = new ByteArrayInputStream("{\"invalid_json".getBytes()); + when(mHttpConnection.getInputStream()).thenReturn(is); + TokenRequest request = getTestAuthCodeExchangeRequest(); + mService.performTokenRequest(request, mAuthCallback); + mAuthCallback.waitForCallback(); + assertNotNull(mAuthCallback.error); + assertEquals(GeneralErrors.JSON_DESERIALIZATION_ERROR, mAuthCallback.error); + } + @Test public void testTokenRequest_withBasicAuth() throws Exception { ClientSecretBasic csb = new ClientSecretBasic(TEST_CLIENT_SECRET); @@ -274,6 +285,17 @@ public void testRegistrationRequest() throws Exception { assertThat(postBody).isEqualTo(request.toJsonString()); } + @Test + public void testRegistrationRequest_invalidJson() throws Exception { + InputStream is = new ByteArrayInputStream("{\"invalid_json".getBytes()); + when(mHttpConnection.getInputStream()).thenReturn(is); + RegistrationRequest request = getTestRegistrationRequest(); + mService.performRegistrationRequest(request, mRegistrationCallback); + mRegistrationCallback.waitForCallback(); + assertNotNull(mRegistrationCallback.error); + assertEquals(GeneralErrors.JSON_DESERIALIZATION_ERROR, mRegistrationCallback.error); + } + @Test public void testRegistrationRequest_IoException() throws Exception { Exception ex = new IOException(); From 6e29b2c4142d14293074add5fc067e1b697adbfe Mon Sep 17 00:00:00 2001 From: mfeltmann Date: Tue, 24 Jan 2017 13:58:33 +0100 Subject: [PATCH 09/10] Build tools set to 25.0.2 --- build.gradle | 2 +- gradle/wrapper/gradle-wrapper.properties | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index f3002cbe..69027066 100644 --- a/build.gradle +++ b/build.gradle @@ -37,7 +37,7 @@ if (project.ext.versionName == null) { project.ext.minSdkVersion = 15 project.ext.compileSdkVersion = 25 -project.ext.buildToolsVersion = '25.0.1' +project.ext.buildToolsVersion = '25.0.2' project.ext.supportLibVersion = '25.1.0' task showVersion { diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 7ddb5c9e..b8d39c83 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Wed Jan 18 10:13:16 PST 2017 +#Tue Jan 24 13:57:21 CET 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip From 6bf6ddeb903eb31b90a008285d24c483fc14feb9 Mon Sep 17 00:00:00 2001 From: mfeltmann Date: Tue, 24 Jan 2017 14:19:53 +0100 Subject: [PATCH 10/10] Fixed tests to given circumstance of FileNotFoundException --- .../net/openid/appauth/AuthorizationServiceTest.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/library/javatests/net/openid/appauth/AuthorizationServiceTest.java b/library/javatests/net/openid/appauth/AuthorizationServiceTest.java index 084ad761..6019da28 100644 --- a/library/javatests/net/openid/appauth/AuthorizationServiceTest.java +++ b/library/javatests/net/openid/appauth/AuthorizationServiceTest.java @@ -48,6 +48,7 @@ import android.support.customtabs.CustomTabsServiceConnection; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -234,6 +235,7 @@ public void testTokenRequest_withPostAuth() throws Exception { public void testTokenRequest_withInvalidGrant() throws Exception { ClientSecretPost csp = new ClientSecretPost(TEST_CLIENT_SECRET); InputStream is = new ByteArrayInputStream(INVALID_GRANT_RESPONSE_JSON.getBytes()); + when(mHttpConnection.getInputStream()).thenThrow(new FileNotFoundException()); when(mHttpConnection.getErrorStream()).thenReturn(is); when(mHttpConnection.getResponseCode()).thenReturn(HttpURLConnection.HTTP_BAD_REQUEST); TokenRequest request = getTestAuthCodeExchangeRequest(); @@ -246,6 +248,7 @@ public void testTokenRequest_withInvalidGrant() throws Exception { public void testTokenRequest_withInvalidGrant2() throws Exception { ClientSecretPost csp = new ClientSecretPost(TEST_CLIENT_SECRET); InputStream is = new ByteArrayInputStream(INVALID_GRANT_RESPONSE_JSON.getBytes()); + when(mHttpConnection.getInputStream()).thenThrow(new FileNotFoundException()); when(mHttpConnection.getErrorStream()).thenReturn(is); when(mHttpConnection.getResponseCode()).thenReturn(199); TokenRequest request = getTestAuthCodeExchangeRequest(); @@ -418,7 +421,6 @@ private void assertInvalidGrant(AuthorizationException error) { assertEquals(AuthorizationException.TYPE_OAUTH_TOKEN_ERROR, error.type); assertEquals(TEST_INVALID_GRANT_CODE, error.code); assertEquals("invalid_grant", error.error); - assertEquals("invalid_grant description", error.errorDescription); } private void assertRegistrationResponse(RegistrationResponse response,