/** * Returns a <code>String</code> that represents this instance, optionally including sensitive data. * * @param exportSecrets * <code>true</code> to include sensitive data in the return string; otherwise, <code>false</code>. * * @return A <code>String</code> that represents this object, optionally including sensitive data. */ @Override public String toString(final boolean exportSecrets) { return String.format("%s=%s;%s=%s", CloudStorageAccount.ACCOUNT_NAME_NAME, this.getAccountName(), CloudStorageAccount.ACCOUNT_KEY_NAME, exportSecrets ? this.exportBase64EncodedKey() : "[key hidden]"); }
/** * Returns a <code>String</code> that represents this instance, optionally including sensitive data. * * @param exportSecrets * <code>true</code> to include sensitive data in the return string; otherwise, <code>false</code>. * * @return A <code>String</code> that represents this object, optionally including sensitive data. */ @Override public String toString(final boolean exportSecrets) { return String.format("%s=%s;%s=%s", CloudStorageAccount.ACCOUNT_NAME_NAME, this.getAccountName(), CloudStorageAccount.ACCOUNT_KEY_NAME, exportSecrets ? this.exportBase64EncodedKey() : "[key hidden]"); }
@Test public void testStorageCredentialsNullKeyValue() { String nullKeyValueAsString = null; try { new StorageCredentialsAccountAndKey(ACCOUNT_NAME, nullKeyValueAsString); fail("Did not hit expected exception"); } catch (IllegalArgumentException ex) { assertEquals(SR.STRING_NOT_VALID, ex.getMessage()); } StorageCredentialsAccountAndKey credentials2 = new StorageCredentialsAccountAndKey(ACCOUNT_NAME, ACCOUNT_KEY); assertEquals(ACCOUNT_NAME, credentials2.getAccountName()); assertEquals(ACCOUNT_KEY, Base64.encode(credentials2.exportKey())); byte[] nullKeyValueAsByteArray = null; try { new StorageCredentialsAccountAndKey(ACCOUNT_NAME, nullKeyValueAsByteArray); fail("Did not hit expected exception"); } catch (IllegalArgumentException ex) { assertEquals(SR.INVALID_KEY, ex.getMessage()); } }
@Test public void testStorageCredentialsSharedKey() throws URISyntaxException, StorageException { StorageCredentialsAccountAndKey cred = new StorageCredentialsAccountAndKey(ACCOUNT_NAME, ACCOUNT_KEY); assertEquals(ACCOUNT_NAME, cred.getAccountName()); URI testUri = new URI("http://test/abc?querya=1"); assertEquals(testUri, cred.transformUri(testUri)); assertEquals(ACCOUNT_KEY, cred.exportBase64EncodedKey()); byte[] dummyKey = { 0, 1, 2 }; String base64EncodedDummyKey = Base64.encode(dummyKey); cred = new StorageCredentialsAccountAndKey(ACCOUNT_NAME, base64EncodedDummyKey); assertEquals(base64EncodedDummyKey, cred.exportBase64EncodedKey()); dummyKey[0] = 3; base64EncodedDummyKey = Base64.encode(dummyKey); cred = new StorageCredentialsAccountAndKey(ACCOUNT_NAME, base64EncodedDummyKey); assertEquals(base64EncodedDummyKey, cred.exportBase64EncodedKey()); }