Skip to content

Commit

Permalink
check for null or empty description
Browse files Browse the repository at this point in the history
  • Loading branch information
lbalmaceda committed Apr 5, 2017
1 parent 4da9670 commit bced8e5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

package com.auth0.android.authentication;

import android.text.TextUtils;
import android.util.Log;

import com.auth0.android.Auth0Exception;
Expand Down Expand Up @@ -122,7 +123,7 @@ public int getStatusCode() {
* @return the error description.
*/
public String getDescription() {
if (description != null) {
if (!TextUtils.isEmpty(description)) {
return description;
}
if (UNKNOWN_ERROR.equals(getCode())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1552,43 +1552,42 @@ private Intent createAuthIntent(String hash) {
private String createHash(@Nullable String idToken, @Nullable String accessToken, @Nullable String refreshToken, @Nullable String tokenType, @Nullable String state, @Nullable String error, @Nullable String errorDescription) {
String hash = "#";
if (accessToken != null) {
hash = hash.concat("access_token=" + accessToken);
hash = hash.concat("access_token=")
.concat(accessToken)
.concat("&");
}
if (idToken != null) {
if (!hash.endsWith("&")) {
hash = hash.concat("&");
}
hash = hash.concat("id_token=" + idToken);
hash = hash.concat("id_token=")
.concat(idToken)
.concat("&");
}
if (refreshToken != null) {
if (!hash.endsWith("&")) {
hash = hash.concat("&");
}
hash = hash.concat("refresh_token=" + refreshToken);
hash = hash.concat("refresh_token=")
.concat(refreshToken)
.concat("&");
}
if (tokenType != null) {
if (!hash.endsWith("&")) {
hash = hash.concat("&");
}
hash = hash.concat("token_type=" + tokenType);
hash = hash.concat("token_type=")
.concat(tokenType)
.concat("&");
}
if (state != null) {
if (!hash.endsWith("&")) {
hash = hash.concat("&");
}
hash = hash.concat("state=" + state);
hash = hash.concat("state=")
.concat(state)
.concat("&");
}
if (error != null) {
if (!hash.endsWith("&")) {
hash = hash.concat("&");
}
hash = hash.concat("error=" + error);
hash = hash.concat("error=")
.concat(error)
.concat("&");
}
if (errorDescription != null) {
if (!hash.endsWith("&")) {
hash = hash.concat("&");
}
hash = hash.concat("error_description=" + errorDescription);
hash = hash.concat("error_description=")
.concat(errorDescription)
.concat("&");
}
if (hash.endsWith("&")) {
hash = hash.substring(0, hash.length() - 1);
}
return hash.length() == 1 ? "" : hash;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
import org.hamcrest.CoreMatchers;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;

import java.util.HashMap;
import java.util.Map;
Expand All @@ -16,6 +19,8 @@
import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assert.assertThat;

@RunWith(RobolectricTestRunner.class)
@Config(constants = com.auth0.android.auth0.BuildConfig.class, sdk = 21, manifest = Config.NONE)
public class AuthenticationErrorBuilderTest {

private AuthenticationErrorBuilder builder;
Expand Down

0 comments on commit bced8e5

Please sign in to comment.