values.add(String.format(attributeFormat, TABLE_ENDPOINT_NAME, this.getTableEndpoint()));
values.add(String.format(attributeFormat, TABLE_ENDPOINT_NAME, this.getTableEndpoint()));
public static CloudTableClient createCloudTableClient(SharedAccessAccountPolicy policy, boolean useHttps) throws StorageException, InvalidKeyException, URISyntaxException { CloudStorageAccount sasAccount = getAccount(); final String token = sasAccount.generateSharedAccessSignature(policy); final StorageCredentials creds = new StorageCredentialsSharedAccessSignature(token); final URI tableUri = new URI(useHttps ? "https" : "http", sasAccount.getTableEndpoint().getAuthority(), sasAccount.getTableEndpoint().getPath(), sasAccount.getTableEndpoint().getQuery(), null); sasAccount = new CloudStorageAccount(creds, sasAccount.getBlobEndpoint(), sasAccount.getQueueEndpoint(), tableUri, sasAccount.getFileEndpoint()); return sasAccount.createCloudTableClient(); }
public static CloudBlobClient createCloudBlobClient(SharedAccessAccountPolicy policy, boolean useHttps) throws StorageException, InvalidKeyException, URISyntaxException { CloudStorageAccount sasAccount = getAccount(); final String token = sasAccount.generateSharedAccessSignature(policy); final StorageCredentials creds = new StorageCredentialsSharedAccessSignature(token); final URI blobUri = new URI(useHttps ? "https" : "http", sasAccount.getBlobEndpoint().getAuthority(), sasAccount.getBlobEndpoint().getPath(), sasAccount.getBlobEndpoint().getQuery(), null); sasAccount = new CloudStorageAccount(creds, blobUri, sasAccount.getQueueEndpoint(), sasAccount.getTableEndpoint(), sasAccount.getFileEndpoint()); return sasAccount.createCloudBlobClient(); }
public static CloudQueueClient createCloudQueueClient(SharedAccessAccountPolicy policy, boolean useHttps) throws StorageException, InvalidKeyException, URISyntaxException { CloudStorageAccount sasAccount = getAccount(); final String token = sasAccount.generateSharedAccessSignature(policy); final StorageCredentials creds = new StorageCredentialsSharedAccessSignature(token); final URI queueUri = new URI(useHttps ? "https" : "http", sasAccount.getQueueEndpoint().getAuthority(), sasAccount.getQueueEndpoint().getPath(), sasAccount.getQueueEndpoint().getQuery(), null); sasAccount = new CloudStorageAccount(creds, sasAccount.getBlobEndpoint(), queueUri, sasAccount.getTableEndpoint(), sasAccount.getFileEndpoint()); return sasAccount.createCloudQueueClient(); }
public static CloudFileClient createCloudFileClient(SharedAccessAccountPolicy policy, boolean useHttps) throws StorageException, InvalidKeyException, URISyntaxException { CloudStorageAccount sasAccount = getAccount(); final String token = sasAccount.generateSharedAccessSignature(policy); final StorageCredentials creds = new StorageCredentialsSharedAccessSignature(token); final URI fileUri = new URI(useHttps ? "https" : "http", sasAccount.getFileEndpoint().getAuthority(), sasAccount.getFileEndpoint().getPath(), sasAccount.getFileEndpoint().getQuery(), null); sasAccount = new CloudStorageAccount( creds, sasAccount.getBlobEndpoint(), sasAccount.getQueueEndpoint(), sasAccount.getTableEndpoint(), fileUri); return sasAccount.createCloudFileClient(); }
@Test public void testIsUsePathStyleUri() throws InvalidKeyException, URISyntaxException, StorageException { // normal account StorageCredentials creds = new StorageCredentialsAccountAndKey("testAccountName", "/g6UPBuy0ypCpAbYTL6/KA+dI/7gyoWvLFYmah3IviUP1jykOHHOlA=="); CloudStorageAccount account = new CloudStorageAccount(creds); testIsUsePathStyleUri(creds, account.getTableEndpoint().toString(), false); // normal account with path creds = new StorageCredentialsAccountAndKey("testAccountName", "/g6UPBuy0ypCpAbYTL6/KA+dI/7gyoWvLFYmah3IviUP1jykOHHOlA=="); account = new CloudStorageAccount(creds); testIsUsePathStyleUri(creds, account.getTableEndpoint().toString() + "/mytable", false); // custom endpoint creds = new StorageCredentialsAccountAndKey("testAccountName", "/g6UPBuy0ypCpAbYTL6/KA+dI/7gyoWvLFYmah3IviUP1jykOHHOlA=="); testIsUsePathStyleUri(creds, "http://www.contoso.com", false); // dev store account = CloudStorageAccount.getDevelopmentStorageAccount(); testIsUsePathStyleUri(account.getCredentials(), account.getTableEndpoint().toString(), true); // dev store with proxy account = CloudStorageAccount.getDevelopmentStorageAccount(new URI("http://ipv4.fiddler")); testIsUsePathStyleUri(account.getCredentials(), account.getTableEndpoint().toString(), true); // custom endpoints ipv4 with path-style (internal test) creds = new StorageCredentialsAccountAndKey("testAccountName", "/g6UPBuy0ypCpAbYTL6/KA+dI/7gyoWvLFYmah3IviUP1jykOHHOlA=="); testIsUsePathStyleUri(creds, "http://93.184.216.119/testAccountName", true); }
@Test public void testCloudStorageAccountDefaultStorageAccountWithHttp() throws URISyntaxException, InvalidKeyException { StorageCredentialsAccountAndKey cred = new StorageCredentialsAccountAndKey(ACCOUNT_NAME, ACCOUNT_KEY); CloudStorageAccount cloudStorageAccount = new CloudStorageAccount(cred, false); assertEquals(cloudStorageAccount.getBlobEndpoint(), new URI(String.format("http://%s.blob.core.windows.net", ACCOUNT_NAME))); assertEquals(cloudStorageAccount.getQueueEndpoint(), new URI(String.format("http://%s.queue.core.windows.net", ACCOUNT_NAME))); assertEquals(cloudStorageAccount.getTableEndpoint(), new URI(String.format("http://%s.table.core.windows.net", ACCOUNT_NAME))); assertEquals(cloudStorageAccount.getFileEndpoint(), new URI(String.format("http://%s.file.core.windows.net", ACCOUNT_NAME))); assertEquals(cloudStorageAccount.getBlobStorageUri().getSecondaryUri(), new URI(String.format("http://%s-secondary.blob.core.windows.net", ACCOUNT_NAME))); assertEquals(cloudStorageAccount.getQueueStorageUri().getSecondaryUri(), new URI(String.format("http://%s-secondary.queue.core.windows.net", ACCOUNT_NAME))); assertEquals(cloudStorageAccount.getTableStorageUri().getSecondaryUri(), new URI(String.format("http://%s-secondary.table.core.windows.net", ACCOUNT_NAME))); assertEquals(cloudStorageAccount.getFileStorageUri().getSecondaryUri(), new URI(String.format("http://%s-secondary.file.core.windows.net", ACCOUNT_NAME))); String cloudStorageAccountToStringWithSecrets = cloudStorageAccount.toString(true); CloudStorageAccount testAccount = CloudStorageAccount.parse(cloudStorageAccountToStringWithSecrets); AccountsAreEqual(testAccount, cloudStorageAccount); }
@Test public void testCloudStorageAccountDevStoreProxyUri() throws InvalidKeyException, URISyntaxException { CloudStorageAccount account = CloudStorageAccount .parse("UseDevelopmentStorage=true;DevelopmentStorageProxyUri=http://ipv4.fiddler"); assertEquals(new URI("http://ipv4.fiddler:10000/devstoreaccount1"), account.getBlobEndpoint()); assertEquals(new URI("http://ipv4.fiddler:10001/devstoreaccount1"), account.getQueueEndpoint()); assertEquals(new URI("http://ipv4.fiddler:10002/devstoreaccount1"), account.getTableEndpoint()); assertEquals(new URI("http://ipv4.fiddler:10000/devstoreaccount1-secondary"), account.getBlobStorageUri() .getSecondaryUri()); assertEquals(new URI("http://ipv4.fiddler:10001/devstoreaccount1-secondary"), account.getQueueStorageUri() .getSecondaryUri()); assertEquals(new URI("http://ipv4.fiddler:10002/devstoreaccount1-secondary"), account.getTableStorageUri() .getSecondaryUri()); }
@Test public void testCloudStorageAccountDefaultStorageAccountWithHttps() throws URISyntaxException, InvalidKeyException { StorageCredentialsAccountAndKey cred = new StorageCredentialsAccountAndKey(ACCOUNT_NAME, ACCOUNT_KEY); CloudStorageAccount cloudStorageAccount = new CloudStorageAccount(cred, true); assertEquals(cloudStorageAccount.getBlobEndpoint(), new URI(String.format("https://%s.blob.core.windows.net", ACCOUNT_NAME))); assertEquals(cloudStorageAccount.getQueueEndpoint(), new URI(String.format("https://%s.queue.core.windows.net", ACCOUNT_NAME))); assertEquals(cloudStorageAccount.getTableEndpoint(), new URI(String.format("https://%s.table.core.windows.net", ACCOUNT_NAME))); assertEquals(cloudStorageAccount.getFileEndpoint(), new URI(String.format("https://%s.file.core.windows.net", ACCOUNT_NAME))); assertEquals(cloudStorageAccount.getBlobStorageUri().getSecondaryUri(), new URI(String.format("https://%s-secondary.blob.core.windows.net", ACCOUNT_NAME))); assertEquals(cloudStorageAccount.getQueueStorageUri().getSecondaryUri(), new URI(String.format("https://%s-secondary.queue.core.windows.net", ACCOUNT_NAME))); assertEquals(cloudStorageAccount.getTableStorageUri().getSecondaryUri(), new URI(String.format("https://%s-secondary.table.core.windows.net", ACCOUNT_NAME))); assertEquals(cloudStorageAccount.getFileStorageUri().getSecondaryUri(), new URI(String.format("https://%s-secondary.file.core.windows.net", ACCOUNT_NAME))); String cloudStorageAccountToStringWithSecrets = cloudStorageAccount.toString(true); CloudStorageAccount testAccount = CloudStorageAccount.parse(cloudStorageAccountToStringWithSecrets); AccountsAreEqual(testAccount, cloudStorageAccount); }
@Test public void testCloudStorageAccountDevStore() throws URISyntaxException { // default CloudStorageAccount account = CloudStorageAccount.getDevelopmentStorageAccount(); assertEquals(new URI("http://127.0.0.1:10000/devstoreaccount1"), account.getBlobEndpoint()); assertEquals(new URI("http://127.0.0.1:10001/devstoreaccount1"), account.getQueueEndpoint()); assertEquals(new URI("http://127.0.0.1:10002/devstoreaccount1"), account.getTableEndpoint()); assertEquals(new URI("http://127.0.0.1:10000/devstoreaccount1-secondary"), account.getBlobStorageUri() .getSecondaryUri()); assertEquals(new URI("http://127.0.0.1:10001/devstoreaccount1-secondary"), account.getQueueStorageUri() .getSecondaryUri()); assertEquals(new URI("http://127.0.0.1:10002/devstoreaccount1-secondary"), account.getTableStorageUri() .getSecondaryUri()); // proxy account = CloudStorageAccount.getDevelopmentStorageAccount(new URI("http://ipv4.fiddler")); assertEquals(new URI("http://ipv4.fiddler:10000/devstoreaccount1"), account.getBlobEndpoint()); assertEquals(new URI("http://ipv4.fiddler:10001/devstoreaccount1"), account.getQueueEndpoint()); assertEquals(new URI("http://ipv4.fiddler:10002/devstoreaccount1"), account.getTableEndpoint()); assertEquals(new URI("http://ipv4.fiddler:10000/devstoreaccount1-secondary"), account.getBlobStorageUri() .getSecondaryUri()); assertEquals(new URI("http://ipv4.fiddler:10001/devstoreaccount1-secondary"), account.getQueueStorageUri() .getSecondaryUri()); assertEquals(new URI("http://ipv4.fiddler:10002/devstoreaccount1-secondary"), account.getTableStorageUri() .getSecondaryUri()); }
@Test public void testCloudStorageAccountWithStorageUri() throws URISyntaxException, InvalidKeyException { StorageUri blobEndpoint = new StorageUri(new URI("http://" + ACCOUNT_NAME + BLOB_SERVICE + ENDPOINT_SUFFIX), new URI("http://" + ACCOUNT_NAME + SECONDARY_SUFFIX + BLOB_SERVICE + ENDPOINT_SUFFIX)); StorageUri queueEndpoint = new StorageUri(new URI("http://" + ACCOUNT_NAME + QUEUE_SERVICE + ENDPOINT_SUFFIX), new URI("http://" + ACCOUNT_NAME + SECONDARY_SUFFIX + QUEUE_SERVICE + ENDPOINT_SUFFIX)); StorageUri tableEndpoint = new StorageUri(new URI("http://" + ACCOUNT_NAME + TABLE_SERVICE + ENDPOINT_SUFFIX), new URI("http://" + ACCOUNT_NAME + SECONDARY_SUFFIX + TABLE_SERVICE + ENDPOINT_SUFFIX)); CloudStorageAccount account = CloudStorageAccount.parse(String.format( "DefaultEndpointsProtocol=http;AccountName=%s;AccountKey=dummyKey", ACCOUNT_NAME)); assertEquals(blobEndpoint, account.getBlobStorageUri()); assertEquals(queueEndpoint, account.getQueueStorageUri()); assertEquals(tableEndpoint, account.getTableStorageUri()); assertEquals(blobEndpoint, account.createCloudBlobClient().getStorageUri()); assertEquals(queueEndpoint, account.createCloudQueueClient().getStorageUri()); assertEquals(tableEndpoint, account.createCloudTableClient().getStorageUri()); assertEquals(blobEndpoint.getPrimaryUri(), account.getBlobEndpoint()); assertEquals(queueEndpoint.getPrimaryUri(), account.getQueueEndpoint()); assertEquals(tableEndpoint.getPrimaryUri(), account.getTableEndpoint()); }
@Test public void testCloudStorageAccountClientUriVerify() throws URISyntaxException, StorageException { StorageCredentialsAccountAndKey cred = new StorageCredentialsAccountAndKey(ACCOUNT_NAME, ACCOUNT_KEY); CloudStorageAccount cloudStorageAccount = new CloudStorageAccount(cred, true); CloudBlobClient blobClient = cloudStorageAccount.createCloudBlobClient(); CloudBlobContainer container = blobClient.getContainerReference("container1"); assertEquals(cloudStorageAccount.getBlobEndpoint().toString() + "/container1", container.getUri().toString()); CloudQueueClient queueClient = cloudStorageAccount.createCloudQueueClient(); CloudQueue queue = queueClient.getQueueReference("queue1"); assertEquals(cloudStorageAccount.getQueueEndpoint().toString() + "/queue1", queue.getUri().toString()); CloudTableClient tableClient = cloudStorageAccount.createCloudTableClient(); CloudTable table = tableClient.getTableReference("table1"); assertEquals(cloudStorageAccount.getTableEndpoint().toString() + "/table1", table.getUri().toString()); CloudFileClient fileClient = cloudStorageAccount.createCloudFileClient(); CloudFileShare share = fileClient.getShareReference("share1"); assertEquals(cloudStorageAccount.getFileEndpoint().toString() + "/share1", share.getUri().toString()); }
assertEquals(accountParse.getTableEndpoint(), tableClientParse.getEndpoint()); assertTrue(tableClientParse.getEndpoint().toString().endsWith("tables/"));
private void AccountsAreEqual(CloudStorageAccount a, CloudStorageAccount b) { // endpoints are the same assertEquals(a.getBlobEndpoint(), b.getBlobEndpoint()); assertEquals(a.getQueueEndpoint(), b.getQueueEndpoint()); assertEquals(a.getTableEndpoint(), b.getTableEndpoint()); assertEquals(a.getFileEndpoint(), b.getFileEndpoint()); // storage uris are the same assertEquals(a.getBlobStorageUri(), b.getBlobStorageUri()); assertEquals(a.getQueueStorageUri(), b.getQueueStorageUri()); assertEquals(a.getTableStorageUri(), b.getTableStorageUri()); assertEquals(a.getFileStorageUri(), b.getFileStorageUri()); // seralized representatons are the same. String aToStringNoSecrets = a.toString(); String aToStringWithSecrets = a.toString(true); String bToStringNoSecrets = b.toString(false); String bToStringWithSecrets = b.toString(true); assertEquals(aToStringNoSecrets, bToStringNoSecrets); assertEquals(aToStringWithSecrets, bToStringWithSecrets); // credentials are the same if (a.getCredentials() != null && b.getCredentials() != null) { assertEquals(a.getCredentials().getClass(), b.getCredentials().getClass()); } else if (a.getCredentials() == null && b.getCredentials() == null) { return; } else { fail("credentials mismatch"); } }
@Test public void testCloudStorageAccountClientMethods() throws URISyntaxException { StorageCredentialsAccountAndKey cred = new StorageCredentialsAccountAndKey(ACCOUNT_NAME, ACCOUNT_KEY); CloudStorageAccount account = new CloudStorageAccount(cred, false); CloudBlobClient blob = account.createCloudBlobClient(); CloudQueueClient queue = account.createCloudQueueClient(); CloudTableClient table = account.createCloudTableClient(); CloudFileClient file = account.createCloudFileClient(); // check endpoints assertEquals("Blob endpoint doesn't match account", account.getBlobEndpoint(), blob.getEndpoint()); assertEquals("Queue endpoint doesn't match account", account.getQueueEndpoint(), queue.getEndpoint()); assertEquals("Table endpoint doesn't match account", account.getTableEndpoint(), table.getEndpoint()); assertEquals("File endpoint doesn't match account", account.getFileEndpoint(), file.getEndpoint()); // check storage uris assertEquals("Blob endpoint doesn't match account", account.getBlobStorageUri(), blob.getStorageUri()); assertEquals("Queue endpoint doesn't match account", account.getQueueStorageUri(), queue.getStorageUri()); assertEquals("Table endpoint doesn't match account", account.getTableStorageUri(), table.getStorageUri()); assertEquals("File endpoint doesn't match account", account.getFileStorageUri(), file.getStorageUri()); // check creds assertEquals("Blob creds don't match account", account.getCredentials(), blob.getCredentials()); assertEquals("Queue creds don't match account", account.getCredentials(), queue.getCredentials()); assertEquals("Table creds don't match account", account.getCredentials(), table.getCredentials()); assertEquals("File creds don't match account", account.getCredentials(), file.getCredentials()); }