public void StorageCredentialsSharedKey()
        {
            StorageCredentials cred = new StorageCredentials(TestBase.TargetTenantConfig.AccountName, TestBase.TargetTenantConfig.AccountKey);

            Assert.AreEqual(TestBase.TargetTenantConfig.AccountName, cred.AccountName, false);
            Assert.IsFalse(cred.IsAnonymous);
            Assert.IsFalse(cred.IsSAS);
            Assert.IsTrue(cred.IsSharedKey);

            Uri testUri = new Uri("http://test/abc?querya=1");

            Assert.AreEqual(testUri, cred.TransformUri(testUri));

            Assert.AreEqual(TestBase.TargetTenantConfig.AccountKey, cred.ExportBase64EncodedKey());
            byte[] dummyKey = { 0, 1, 2 };
            string base64EncodedDummyKey = Convert.ToBase64String(dummyKey);

            cred.UpdateKey(base64EncodedDummyKey);
            Assert.AreEqual(base64EncodedDummyKey, cred.ExportBase64EncodedKey());

#if !(WINDOWS_RT || ASPNET_K)
            dummyKey[0]           = 3;
            base64EncodedDummyKey = Convert.ToBase64String(dummyKey);
            cred.UpdateKey(dummyKey);
            Assert.AreEqual(base64EncodedDummyKey, cred.ExportBase64EncodedKey());
#endif
        }
Exemple #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="storageCredentials"></param>
        /// <param name="AuthResults"></param>
        public static void Show_Credentials(StorageCredentials storageCredentials, TextBox AuthResults)
        {
            AuthResults.Text += "\n-----------------------------------\n";
            AuthResults.Text += storageCredentials.ToString() + "\n";
            AuthResults.Text += "Account Name: " + storageCredentials.AccountName + "\n";
            AuthResults.Text += "Credentials type: ";
            if (storageCredentials.IsToken)
            {
                AuthResults.Text += "Token ";
            }
            if (storageCredentials.IsSharedKey)
            {
                AuthResults.Text += "SharedKey ";
            }
            if (storageCredentials.IsSAS)
            {
                AuthResults.Text += "SAS ";
            }
            if (storageCredentials.IsAnonymous)
            {
                AuthResults.Text += "Anonymous ";
            }
            AuthResults.Text += "\n";
            AuthResults.Text += "Key Name: " + storageCredentials.KeyName + "\n";
            //AuthResults.Text += "SAS Signature: " + storageCredentials.SASSignature + "\n";   // Exception
            AuthResults.Text += "SAS Token: " + storageCredentials.SASToken + "\n";

            AuthResults.Text += "-----------------------------------\n";
            AuthResults.Text += "Account Key from storageCredentials:\n";
            AuthResults.Text += storageCredentials.ExportBase64EncodedKey();
        }
Exemple #3
0
        public GatewayGetOperationStatusResponse StartDiagnostics(string vnetName, int captureDurationInSeconds, string containerName, AzureStorageContext storageContext)
        {
            StorageCredentials credentials         = storageContext.StorageAccount.Credentials;
            string             customerStorageKey  = credentials.ExportBase64EncodedKey();
            string             customerStorageName = credentials.AccountName;

            return(StartDiagnostics(vnetName, captureDurationInSeconds, containerName, customerStorageKey, customerStorageName));
        }
        public void CloudStorageAccountExportKey()
        {
            string accountKeyString           = "abc2564=";
            string accountString              = "BlobEndpoint=http://blobs/;AccountName=test;AccountKey=" + accountKeyString;
            CloudStorageAccount account       = CloudStorageAccount.Parse(accountString);
            StorageCredentials  accountAndKey = (StorageCredentials)account.Credentials;
            string key = accountAndKey.ExportBase64EncodedKey();

            Assert.AreEqual(accountKeyString, key);

            byte[] keyBytes         = accountAndKey.ExportKey();
            byte[] expectedKeyBytes = Convert.FromBase64String(accountKeyString);
            for (int i = 0; i < expectedKeyBytes.Length; i++)
            {
                Assert.AreEqual(expectedKeyBytes[i], keyBytes[i]);
            }
            Assert.AreEqual(expectedKeyBytes.Length, keyBytes.Length);
        }