Skip to content

Commit

Permalink
improve exceptions catching tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lbalmaceda committed Oct 5, 2017
1 parent 2aaeb34 commit 8bca0cd
Show file tree
Hide file tree
Showing 5 changed files with 374 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
*/
@SuppressWarnings("WeakerAccess")
public class CredentialsManagerException extends Auth0Exception {
public CredentialsManagerException(String message, Throwable cause) {
CredentialsManagerException(String message, Throwable cause) {
super(message, cause);
}

public CredentialsManagerException(String message) {
CredentialsManagerException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
package com.auth0.android.authentication.storage;

/**
* Created by lbalmaceda on 8/29/17.
*/

/**
* Exception thrown by the {@link CryptoUtil} class whenever an operation goes wrong.
*/
public class CryptoException extends RuntimeException {
public CryptoException(String message, Throwable cause) {
CryptoException(String message, Throwable cause) {
super(message, cause);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ KeyStore.PrivateKeyEntry getRSAKeyEntry() throws KeyException {
generator.generateKeyPair();
return (KeyStore.PrivateKeyEntry) keyStore.getEntry(KEY_ALIAS, null);
} catch (KeyStoreException | IOException | NoSuchProviderException | InvalidAlgorithmParameterException | NoSuchAlgorithmException | CertificateException e) {
Log.e(TAG, "An error occurred while trying to obtain the RSA Key Entry from the Android KeyStore.", e);
Log.e(TAG, "An error occurred while trying to obtain the RSA KeyPair Entry from the Android KeyStore.", e);
throw new KeyException("An error occurred while trying to obtain the RSA KeyPair Entry from the Android KeyStore.", e);
} catch (UnrecoverableEntryException e) {
//Remove keys and Retry
Expand Down Expand Up @@ -233,7 +233,7 @@ public byte[] decrypt(byte[] encryptedInput) throws CryptoException {
byte[] iv = Base64.decode(encodedIV, Base64.DEFAULT);
cipher.init(Cipher.DECRYPT_MODE, key, new IvParameterSpec(iv));
return cipher.doFinal(encryptedInput);
} catch (KeyException | NoSuchAlgorithmException | InvalidAlgorithmParameterException | BadPaddingException | NoSuchPaddingException | IllegalBlockSizeException e) {
} catch (KeyException | NoSuchAlgorithmException | NoSuchPaddingException | InvalidAlgorithmParameterException | BadPaddingException | IllegalBlockSizeException e) {
Log.e(TAG, "Error while decrypting the input.", e);
throw new CryptoException("Error while decrypting the input.", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,4 +386,18 @@ public void shouldNotHaveCredentialsWhenAccessTokenAndIdTokenAreMissing() throws

assertFalse(manager.hasValidCredentials());
}

@Test
public void shouldRecreateTheCredentials() throws Exception {
CredentialsManager credentialsManager = new CredentialsManager(client, storage);
Date now = new Date();
final Credentials credentials = credentialsManager.recreateCredentials("idTOKEN", "accessTOKEN", "tokenTYPE", "refreshTOKEN", now, "openid profile");
assertThat(credentials, is(notNullValue()));
assertThat(credentials.getIdToken(), is("idTOKEN"));
assertThat(credentials.getAccessToken(), is("accessTOKEN"));
assertThat(credentials.getType(), is("tokenTYPE"));
assertThat(credentials.getRefreshToken(), is("refreshTOKEN"));
assertThat(credentials.getExpiresAt(), is(now));
assertThat(credentials.getScope(), is("openid profile"));
}
}
Loading

0 comments on commit 8bca0cd

Please sign in to comment.