PageRenderTime 50ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/src/ResourceManager/KeyVault/Commands.KeyVault.Test/ScenarioTests/KeyVaultManagementTests.cs

https://gitlab.com/jslee1/azure-powershell
C# | 747 lines | 649 code | 82 blank | 16 comment | 15 complexity | 1c3d23e6e3e5054f75674e0c2089c470 MD5 | raw file
  1. // ----------------------------------------------------------------------------------
  2. //
  3. // Copyright Microsoft Corporation
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. // ----------------------------------------------------------------------------------
  14. using Microsoft.Azure.Graph.RBAC;
  15. using Microsoft.Azure.Graph.RBAC.Models;
  16. using Microsoft.Azure.Test;
  17. using Microsoft.Azure.Test.HttpRecorder;
  18. using Microsoft.WindowsAzure.Commands.ScenarioTest;
  19. using System;
  20. using System.Linq;
  21. using Xunit;
  22. namespace Microsoft.Azure.Commands.KeyVault.Test.ScenarioTests
  23. {
  24. public class KeyVaultManagementTests : IClassFixture<KeyVaultTestFixture>
  25. {
  26. private KeyVaultTestFixture _data;
  27. public KeyVaultManagementTests(KeyVaultTestFixture fixture)
  28. {
  29. this._data = fixture;
  30. this._data.Initialize(TestUtilities.GetCallingClass());
  31. }
  32. private void Initialize()
  33. {
  34. if (HttpMockServer.Mode == HttpRecorderMode.Record)
  35. {
  36. HttpMockServer.Variables["ResourceGroupName"] = _data.resourceGroupName;
  37. HttpMockServer.Variables["Location"] = _data.location;
  38. HttpMockServer.Variables["PreCreatedVault"] = _data.preCreatedVault;
  39. }
  40. else
  41. {
  42. _data.resourceGroupName = HttpMockServer.Variables["ResourceGroupName"];
  43. _data.location = HttpMockServer.Variables["Location"];
  44. _data.preCreatedVault = HttpMockServer.Variables["PreCreatedVault"];
  45. }
  46. }
  47. #region New-AzureRmKeyVault
  48. [Fact(Skip = "Graph authentication blocks test passes")]
  49. [Trait(Category.AcceptanceType, Category.CheckIn)]
  50. public void TestCreateNewVault()
  51. {
  52. KeyVaultManagementController.NewInstance.RunPsTestWorkflow(
  53. () => { return new[] { string.Format("{0} {1} {2} {3} {4}", "Test-CreateNewVault", _data.resourceGroupName, _data.location, _data.tagName, _data.tagValue) }; },
  54. (env) => Initialize(),
  55. null,
  56. TestUtilities.GetCallingClass(),
  57. TestUtilities.GetCurrentMethodName()
  58. );
  59. }
  60. [Fact(Skip = "Graph authentication blocks test passes")]
  61. [Trait(Category.AcceptanceType, Category.CheckIn)]
  62. public void TestCreateNewPremiumVaultEnabledForDeployment()
  63. {
  64. KeyVaultManagementController.NewInstance.RunPsTestWorkflow(
  65. () => { return new[] { string.Format("{0} {1} {2}", "Test-CreateNewPremiumVaultEnabledForDeployment", _data.resourceGroupName, _data.location) }; },
  66. (env) => Initialize(),
  67. null,
  68. TestUtilities.GetCallingClass(),
  69. TestUtilities.GetCurrentMethodName()
  70. );
  71. }
  72. [Fact]
  73. [Trait(Category.AcceptanceType, Category.CheckIn)]
  74. public void TestRecreateVaultFails()
  75. {
  76. KeyVaultManagementController.NewInstance.RunPsTestWorkflow(
  77. () => { return new[] { string.Format("{0} {1} {2} {3}", "Test-RecreateVaultFails", _data.preCreatedVault, _data.resourceGroupName, _data.location) }; },
  78. (env) => Initialize(),
  79. null,
  80. TestUtilities.GetCallingClass(),
  81. TestUtilities.GetCurrentMethodName()
  82. );
  83. }
  84. [Fact]
  85. [Trait(Category.AcceptanceType, Category.CheckIn)]
  86. public void TestCreateVaultInUnknownResGrpFails()
  87. {
  88. KeyVaultManagementController.NewInstance.RunPsTestWorkflow(
  89. () => { return new[] { string.Format("{0} {1}", "Test-CreateVaultInUnknownResGrpFails", _data.location) }; },
  90. (env) => Initialize(),
  91. null,
  92. TestUtilities.GetCallingClass(),
  93. TestUtilities.GetCurrentMethodName()
  94. );
  95. }
  96. [Fact(Skip = "Graph authentication blocks test passes")]
  97. [Trait(Category.AcceptanceType, Category.CheckIn)]
  98. public void TestCreateVaultPositionalParams()
  99. {
  100. KeyVaultManagementController.NewInstance.RunPsTestWorkflow(
  101. () => { return new[] { string.Format("{0} {1} {2}", "Test-CreateVaultPositionalParams", _data.resourceGroupName, _data.location) }; },
  102. (env) => Initialize(),
  103. null,
  104. TestUtilities.GetCallingClass(),
  105. TestUtilities.GetCurrentMethodName()
  106. );
  107. }
  108. #endregion
  109. #region Get-AzureRmKeyVault
  110. [Fact(Skip = "Graph authentication blocks test passes")]
  111. [Trait(Category.AcceptanceType, Category.CheckIn)]
  112. public void TestGetVaultByNameAndResourceGroup()
  113. {
  114. KeyVaultManagementController.NewInstance.RunPsTestWorkflow(
  115. () => { return new[] { string.Format("{0} {1} {2}", "Test-GetVaultByNameAndResourceGroup", _data.preCreatedVault, _data.resourceGroupName) }; },
  116. (env) => Initialize(),
  117. null,
  118. TestUtilities.GetCallingClass(),
  119. TestUtilities.GetCurrentMethodName()
  120. );
  121. }
  122. [Fact(Skip = "Graph authentication blocks test passes")]
  123. [Trait(Category.AcceptanceType, Category.CheckIn)]
  124. public void TestGetVaultByNameAndResourceGroupPositionalParams()
  125. {
  126. KeyVaultManagementController.NewInstance.RunPsTestWorkflow(
  127. () => { return new[] { string.Format("{0} {1} {2}", "Test-GetVaultByNameAndResourceGroupPositionalParams", _data.preCreatedVault, _data.resourceGroupName) }; },
  128. (env) => Initialize(),
  129. null,
  130. TestUtilities.GetCallingClass(),
  131. TestUtilities.GetCurrentMethodName()
  132. );
  133. }
  134. [Fact(Skip = "Graph authentication blocks test passes")]
  135. [Trait(Category.AcceptanceType, Category.CheckIn)]
  136. public void TestGetVaultByName()
  137. {
  138. KeyVaultManagementController.NewInstance.RunPsTestWorkflow(
  139. () => { return new[] { string.Format("{0} {1}", "Test-GetVaultByName", _data.preCreatedVault) }; },
  140. (env) => Initialize(),
  141. null,
  142. TestUtilities.GetCallingClass(),
  143. TestUtilities.GetCurrentMethodName()
  144. );
  145. }
  146. [Fact(Skip = "Graph authentication blocks test passes")]
  147. [Trait(Category.AcceptanceType, Category.CheckIn)]
  148. public void TestGetVaultByNameCapitalized()
  149. {
  150. KeyVaultManagementController.NewInstance.RunPsTestWorkflow(
  151. () => new[] { string.Format("{0} {1}", "Test-GetVaultByName", _data.preCreatedVault.ToUpper()) },
  152. env => Initialize(),
  153. null,
  154. TestUtilities.GetCallingClass(),
  155. TestUtilities.GetCurrentMethodName()
  156. );
  157. }
  158. [Fact]
  159. [Trait(Category.AcceptanceType, Category.CheckIn)]
  160. public void TestGetUnknownVaultFails()
  161. {
  162. KeyVaultManagementController.NewInstance.RunPsTestWorkflow(
  163. () => { return new[] { string.Format("{0} {1}", "Test-GetUnknownVaultFails", _data.resourceGroupName) }; },
  164. (env) => Initialize(),
  165. null,
  166. TestUtilities.GetCallingClass(),
  167. TestUtilities.GetCurrentMethodName()
  168. );
  169. }
  170. [Fact]
  171. [Trait(Category.AcceptanceType, Category.CheckIn)]
  172. public void TestGetVaultFromUnknownResourceGroupFails()
  173. {
  174. KeyVaultManagementController.NewInstance.RunPsTestWorkflow(
  175. () => { return new[] { string.Format("{0} {1}", "Test-GetVaultFromUnknownResourceGroupFails", _data.preCreatedVault) }; },
  176. (env) => Initialize(),
  177. null,
  178. TestUtilities.GetCallingClass(),
  179. TestUtilities.GetCurrentMethodName()
  180. );
  181. }
  182. #endregion
  183. #region Get-AzureRmKeyVault (list)
  184. [Fact]
  185. [Trait(Category.AcceptanceType, Category.CheckIn)]
  186. public void TestListVaultsByResourceGroup()
  187. {
  188. KeyVaultManagementController.NewInstance.RunPsTestWorkflow(
  189. () => { return new[] { string.Format("{0} {1}", "Test-ListVaultsByResourceGroup", _data.resourceGroupName) }; },
  190. (env) => Initialize(),
  191. null,
  192. TestUtilities.GetCallingClass(),
  193. TestUtilities.GetCurrentMethodName()
  194. );
  195. }
  196. [Fact]
  197. [Trait(Category.AcceptanceType, Category.CheckIn)]
  198. public void TestListAllVaultsInSubscription()
  199. {
  200. KeyVaultManagementController.NewInstance.RunPsTestWorkflow(
  201. () => { return new[] { "Test-ListAllVaultsInSubscription" }; },
  202. (env) => Initialize(),
  203. null,
  204. TestUtilities.GetCallingClass(),
  205. TestUtilities.GetCurrentMethodName()
  206. );
  207. }
  208. [Fact]
  209. [Trait(Category.AcceptanceType, Category.CheckIn)]
  210. public void TestListVaultsByTag()
  211. {
  212. KeyVaultManagementController.NewInstance.RunPsTestWorkflow(
  213. () => { return new[] { string.Format("{0} {1} {2}", "Test-ListVaultsByTag", _data.tagName, _data.tagValue) }; },
  214. (env) => Initialize(),
  215. null,
  216. TestUtilities.GetCallingClass(),
  217. TestUtilities.GetCurrentMethodName()
  218. );
  219. }
  220. [Fact]
  221. [Trait(Category.AcceptanceType, Category.CheckIn)]
  222. public void TestListVaultsByUnknownResourceGroupFails()
  223. {
  224. KeyVaultManagementController.NewInstance.RunPsTestWorkflow(
  225. () => { return new[] { "Test-ListVaultsByUnknownResourceGroupFails" }; },
  226. (env) => Initialize(),
  227. null,
  228. TestUtilities.GetCallingClass(),
  229. TestUtilities.GetCurrentMethodName()
  230. );
  231. }
  232. #endregion
  233. #region Remove-AzureRmKeyVault
  234. [Fact(Skip = "Graph authentication blocks test passes")]
  235. [Trait(Category.AcceptanceType, Category.CheckIn)]
  236. public void TestDeleteVaultByName()
  237. {
  238. KeyVaultManagementController.NewInstance.RunPsTestWorkflow(
  239. () => { return new[] { string.Format("{0} {1} {2}", "Test-DeleteVaultByName", _data.resourceGroupName, _data.location) }; },
  240. (env) => Initialize(),
  241. null,
  242. TestUtilities.GetCallingClass(),
  243. TestUtilities.GetCurrentMethodName()
  244. );
  245. }
  246. [Fact]
  247. [Trait(Category.AcceptanceType, Category.CheckIn)]
  248. public void TestDeleteUnknownVaultFails()
  249. {
  250. KeyVaultManagementController.NewInstance.RunPsTestWorkflow(
  251. () => { return new[] { string.Format("{0} ", "Test-DeleteUnknownVaultFails") }; },
  252. (env) => Initialize(),
  253. null,
  254. TestUtilities.GetCallingClass(),
  255. TestUtilities.GetCurrentMethodName()
  256. );
  257. }
  258. #endregion
  259. #region Set-AzureRmKeyVaultAccessPolicy & Remove-AzureRmKeyVaultAccessPolicy
  260. [Fact(Skip = "Graph authentication blocks test passes")]
  261. [Trait(Category.AcceptanceType, Category.CheckIn)]
  262. public void TestSetRemoveAccessPolicyByObjectId()
  263. {
  264. string upn = "";
  265. _data.ResetPreCreatedVault();
  266. KeyVaultManagementController controller = KeyVaultManagementController.NewInstance;
  267. controller.RunPsTestWorkflow(
  268. () =>
  269. {
  270. var objId = GetUserObjectId(controller, upn);
  271. return new[] { string.Format("{0} {1} {2} {3}", "Test-SetRemoveAccessPolicyByObjectId", _data.preCreatedVault, _data.resourceGroupName, objId) };
  272. },
  273. (env) =>
  274. {
  275. Initialize();
  276. upn = GetUser(env.GetTestEnvironment());
  277. },
  278. null,
  279. TestUtilities.GetCallingClass(),
  280. TestUtilities.GetCurrentMethodName()
  281. );
  282. }
  283. [Fact(Skip = "Graph authentication blocks test passes")]
  284. [Trait(Category.AcceptanceType, Category.CheckIn)]
  285. public void TestSetRemoveAccessPolicyByUPN()
  286. {
  287. string upn = "";
  288. _data.ResetPreCreatedVault();
  289. KeyVaultManagementController.NewInstance.RunPsTestWorkflow(
  290. () =>
  291. {
  292. return new[] { string.Format("{0} {1} {2} {3}", "Test-SetRemoveAccessPolicyByUPN", _data.preCreatedVault, _data.resourceGroupName, upn) };
  293. },
  294. (env) =>
  295. {
  296. Initialize();
  297. upn = GetUser(env.GetTestEnvironment());
  298. },
  299. null,
  300. TestUtilities.GetCallingClass(),
  301. TestUtilities.GetCurrentMethodName()
  302. );
  303. }
  304. [Fact(Skip = "Graph authentication blocks test passes")]
  305. [Trait(Category.AcceptanceType, Category.CheckIn)]
  306. public void TestSetRemoveAccessPolicyByCompoundId()
  307. {
  308. string upn = "";
  309. Guid? appId = null;
  310. _data.ResetPreCreatedVault();
  311. KeyVaultManagementController controller = KeyVaultManagementController.NewInstance;
  312. controller.RunPsTestWorkflow(
  313. () =>
  314. {
  315. var objId = GetUserObjectId(controller, upn);
  316. return new[] { string.Format("{0} {1} {2} {3} {4}", "Test-SetRemoveAccessPolicyByCompoundId", _data.preCreatedVault, _data.resourceGroupName, appId, objId) };
  317. },
  318. (env) =>
  319. {
  320. Initialize();
  321. upn = GetUser(env.GetTestEnvironment());
  322. appId = GetApplicationId(env.GetTestEnvironment(), 1);
  323. },
  324. null,
  325. TestUtilities.GetCallingClass(),
  326. TestUtilities.GetCurrentMethodName()
  327. );
  328. }
  329. [Fact(Skip = "Graph authentication blocks test passes")]
  330. [Trait(Category.AcceptanceType, Category.CheckIn)]
  331. public void TestRemoveAccessPolicyWithCompoundIdPolicies()
  332. {
  333. string upn = "";
  334. Guid? appId1 = null;
  335. Guid? appId2 = null;
  336. _data.ResetPreCreatedVault();
  337. KeyVaultManagementController controller = KeyVaultManagementController.NewInstance;
  338. controller.RunPsTestWorkflow(
  339. () =>
  340. {
  341. var objId = GetUserObjectId(controller, upn);
  342. return new[] { string.Format("{0} {1} {2} {3} {4} {5}", "Test-RemoveAccessPolicyWithCompoundIdPolicies", _data.preCreatedVault, _data.resourceGroupName, appId1, appId2, objId) };
  343. },
  344. (env) =>
  345. {
  346. Initialize();
  347. upn = GetUser(env.GetTestEnvironment());
  348. appId1 = GetApplicationId(env.GetTestEnvironment(), 1);
  349. appId2 = GetApplicationId(env.GetTestEnvironment(), 2);
  350. },
  351. null,
  352. TestUtilities.GetCallingClass(),
  353. TestUtilities.GetCurrentMethodName()
  354. );
  355. }
  356. [Fact(Skip = "Graph authentication blocks test passes")]
  357. [Trait(Category.AcceptanceType, Category.CheckIn)]
  358. public void TestSetCompoundIdAccessPolicy()
  359. {
  360. string upn = "";
  361. Guid? appId = null;
  362. _data.ResetPreCreatedVault();
  363. KeyVaultManagementController controller = KeyVaultManagementController.NewInstance;
  364. controller.RunPsTestWorkflow(
  365. () =>
  366. {
  367. var objId = GetUserObjectId(controller, upn);
  368. return new[] { string.Format("{0} {1} {2} {3} {4}", "Test-SetCompoundIdAccessPolicy", _data.preCreatedVault, _data.resourceGroupName, appId, objId) };
  369. },
  370. (env) =>
  371. {
  372. Initialize();
  373. upn = GetUser(env.GetTestEnvironment());
  374. appId = GetApplicationId(env.GetTestEnvironment(), 1);
  375. },
  376. null,
  377. TestUtilities.GetCallingClass(),
  378. TestUtilities.GetCurrentMethodName()
  379. );
  380. }
  381. [Fact(Skip = "Graph authentication blocks test passes")]
  382. [Trait(Category.AcceptanceType, Category.CheckIn)]
  383. public void TestSetRemoveAccessPolicyBySPN()
  384. {
  385. Application app = null;
  386. ServicePrincipal principal = null;
  387. KeyVaultManagementController controller = KeyVaultManagementController.NewInstance;
  388. _data.ResetPreCreatedVault();
  389. controller.RunPsTestWorkflow(
  390. //script builder
  391. () =>
  392. {
  393. app = CreateNewAdApp(controller);
  394. principal = CreateNewAdServicePrincipal(controller, app.AppId);
  395. return new[] { string.Format("{0} {1} {2} {3}", "Test-SetRemoveAccessPolicyBySPN",
  396. _data.preCreatedVault,
  397. _data.resourceGroupName,
  398. principal.ServicePrincipalNames.Where(s => s.StartsWith("http")).FirstOrDefault()) };
  399. },
  400. //Initialize
  401. (env) =>
  402. {
  403. Initialize();
  404. },
  405. // cleanup
  406. () =>
  407. {
  408. DeleteAdServicePrincipal(controller, principal);
  409. DeleteAdApp(controller, app);
  410. },
  411. TestUtilities.GetCallingClass(),
  412. TestUtilities.GetCurrentMethodName()
  413. );
  414. }
  415. [Fact(Skip = "Graph authentication blocks test passes")]
  416. [Trait(Category.AcceptanceType, Category.CheckIn)]
  417. public void TestModifyAccessPolicy()
  418. {
  419. string upn = "";
  420. KeyVaultManagementController controller = KeyVaultManagementController.NewInstance;
  421. _data.ResetPreCreatedVault();
  422. controller.RunPsTestWorkflow(
  423. () =>
  424. {
  425. var objId = GetUserObjectId(controller, upn);
  426. return new[] { string.Format("{0} {1} {2} {3}", "Test-ModifyAccessPolicy", _data.preCreatedVault, _data.resourceGroupName, objId) };
  427. },
  428. (env) =>
  429. {
  430. Initialize();
  431. upn = GetUser(env.GetTestEnvironment());
  432. },
  433. null,
  434. TestUtilities.GetCallingClass(),
  435. TestUtilities.GetCurrentMethodName()
  436. );
  437. }
  438. [Fact(Skip = "Graph authentication blocks test passes")]
  439. [Trait(Category.AcceptanceType, Category.CheckIn)]
  440. public void TestModifyAccessPolicyEnabledForDeployment()
  441. {
  442. string upn = "";
  443. _data.ResetPreCreatedVault();
  444. KeyVaultManagementController.NewInstance.RunPsTestWorkflow(
  445. () =>
  446. {
  447. return new[] { string.Format("{0} {1} {2} {3}", "Test-ModifyAccessPolicyEnabledForDeployment", _data.preCreatedVault, _data.resourceGroupName, upn) };
  448. },
  449. (env) =>
  450. {
  451. Initialize();
  452. upn = GetUser(env.GetTestEnvironment());
  453. },
  454. null,
  455. TestUtilities.GetCallingClass(),
  456. TestUtilities.GetCurrentMethodName()
  457. );
  458. }
  459. [Fact(Skip = "Graph authentication blocks test passes")]
  460. [Trait(Category.AcceptanceType, Category.CheckIn)]
  461. public void TestModifyAccessPolicyEnabledForTemplateDeployment()
  462. {
  463. string upn = "";
  464. _data.ResetPreCreatedVault();
  465. KeyVaultManagementController.NewInstance.RunPsTestWorkflow(
  466. () =>
  467. {
  468. return new[] { string.Format("{0} {1} {2} {3}", "Test-ModifyAccessPolicyEnabledForTemplateDeployment", _data.preCreatedVault, _data.resourceGroupName, upn) };
  469. },
  470. (env) =>
  471. {
  472. Initialize();
  473. upn = GetUser(env.GetTestEnvironment());
  474. },
  475. null,
  476. TestUtilities.GetCallingClass(),
  477. TestUtilities.GetCurrentMethodName()
  478. );
  479. }
  480. [Fact(Skip = "Graph authentication blocks test passes")]
  481. [Trait(Category.AcceptanceType, Category.CheckIn)]
  482. public void TestModifyAccessPolicyEnabledForDiskEncryption()
  483. {
  484. string upn = "";
  485. _data.ResetPreCreatedVault();
  486. KeyVaultManagementController.NewInstance.RunPsTestWorkflow(
  487. () =>
  488. {
  489. return new[] { string.Format("{0} {1} {2} {3}", "Test-ModifyAccessPolicyEnabledForDiskEncryption", _data.preCreatedVault, _data.resourceGroupName, upn) };
  490. },
  491. (env) =>
  492. {
  493. Initialize();
  494. upn = GetUser(env.GetTestEnvironment());
  495. },
  496. null,
  497. TestUtilities.GetCallingClass(),
  498. TestUtilities.GetCurrentMethodName()
  499. );
  500. }
  501. [Fact]
  502. [Trait(Category.AcceptanceType, Category.CheckIn)]
  503. public void TestModifyAccessPolicyNegativeCases()
  504. {
  505. string upn = "";
  506. _data.ResetPreCreatedVault();
  507. KeyVaultManagementController.NewInstance.RunPsTestWorkflow(
  508. () =>
  509. {
  510. return new[] { string.Format("{0} {1} {2} {3}", "Test-ModifyAccessPolicyNegativeCases", _data.preCreatedVault, _data.resourceGroupName, upn) };
  511. },
  512. (env) =>
  513. {
  514. Initialize();
  515. upn = GetUser(env.GetTestEnvironment());
  516. },
  517. null,
  518. TestUtilities.GetCallingClass(),
  519. TestUtilities.GetCurrentMethodName()
  520. );
  521. }
  522. [Fact(Skip = "Graph authentication blocks test passes")]
  523. [Trait(Category.AcceptanceType, Category.CheckIn)]
  524. public void TestRemoveNonExistentAccessPolicyDoesNotThrow()
  525. {
  526. string upn = "";
  527. _data.ResetPreCreatedVault();
  528. KeyVaultManagementController controller = KeyVaultManagementController.NewInstance;
  529. controller.RunPsTestWorkflow(
  530. () =>
  531. {
  532. var objId = GetUserObjectId(controller, upn);
  533. return new[] { string.Format("{0} {1} {2} {3}", "Test-RemoveNonExistentAccessPolicyDoesNotThrow", _data.preCreatedVault, _data.resourceGroupName, objId) };
  534. },
  535. (env) =>
  536. {
  537. Initialize();
  538. upn = GetUser(env.GetTestEnvironment());
  539. },
  540. null,
  541. TestUtilities.GetCallingClass(),
  542. TestUtilities.GetCurrentMethodName()
  543. );
  544. }
  545. #endregion
  546. #region Piping
  547. [Fact(Skip = "Graph authentication blocks test passes")]
  548. [Trait(Category.AcceptanceType, Category.CheckIn)]
  549. public void TestCreateDeleteVaultWithPiping()
  550. {
  551. KeyVaultManagementController.NewInstance.RunPsTestWorkflow(
  552. () => { return new[] { string.Format("{0} {1} {2}", "Test-CreateDeleteVaultWithPiping", _data.resourceGroupName, _data.location) }; },
  553. (env) => Initialize(),
  554. null,
  555. TestUtilities.GetCallingClass(),
  556. TestUtilities.GetCurrentMethodName()
  557. );
  558. }
  559. #endregion
  560. #region Helper Methods
  561. private string GetUser(TestEnvironment environment)
  562. {
  563. if (HttpMockServer.Mode == HttpRecorderMode.Record)
  564. {
  565. HttpMockServer.Variables["User"] = environment.AuthorizationContext.UserId;
  566. return environment.AuthorizationContext.UserId;
  567. }
  568. else
  569. {
  570. return HttpMockServer.Variables["User"];
  571. }
  572. }
  573. private string GetUserObjectId(KeyVaultManagementController controllerAdmin, string upn)
  574. {
  575. if (HttpMockServer.Mode == HttpRecorderMode.Record)
  576. {
  577. var result = controllerAdmin.GraphClient.User.Get(upn);
  578. HttpMockServer.Variables["ObjectId"] = result.User.ObjectId;
  579. return result.User.ObjectId;
  580. }
  581. else
  582. {
  583. return HttpMockServer.Variables["ObjectId"];
  584. }
  585. }
  586. private Guid GetApplicationId(TestEnvironment environment, int appNum)
  587. {
  588. if (appNum < 0)
  589. throw new ArgumentException("Invalid appNum");
  590. string variableName = "AppId" + appNum;
  591. if (HttpMockServer.Mode == HttpRecorderMode.Record)
  592. {
  593. Guid appId = Guid.NewGuid();
  594. HttpMockServer.Variables[variableName] = appId.ToString();
  595. return appId;
  596. }
  597. else
  598. {
  599. return new Guid(HttpMockServer.Variables[variableName]);
  600. }
  601. }
  602. private Application CreateNewAdApp(KeyVaultManagementController controllerAdmin)
  603. {
  604. var appName = TestUtilities.GenerateName("adApplication");
  605. var url = string.Format("http://{0}/home", appName);
  606. var appParam = new ApplicationCreateParameters
  607. {
  608. AvailableToOtherTenants = false,
  609. DisplayName = appName,
  610. Homepage = url,
  611. IdentifierUris = new[] { url },
  612. ReplyUrls = new[] { url }
  613. };
  614. return controllerAdmin.GraphClient.Application.Create(appParam).Application;
  615. }
  616. private ServicePrincipal CreateNewAdServicePrincipal(KeyVaultManagementController controllerAdmin, string appId)
  617. {
  618. var spParam = new ServicePrincipalCreateParameters
  619. {
  620. AppId = appId,
  621. AccountEnabled = true
  622. };
  623. return controllerAdmin.GraphClient.ServicePrincipal.Create(spParam).ServicePrincipal;
  624. }
  625. private User CreateNewAdUser(KeyVaultManagementController controllerAdmin)
  626. {
  627. var name = TestUtilities.GenerateName("aduser");
  628. var parameter = new UserCreateParameters
  629. {
  630. DisplayName = name,
  631. UserPrincipalName = name + "@" + controllerAdmin.UserDomain,
  632. AccountEnabled = true,
  633. MailNickname = name + "test",
  634. PasswordProfileSettings = new UserCreateParameters.PasswordProfile
  635. {
  636. ForceChangePasswordNextLogin = false,
  637. Password = TestUtilities.GenerateName("adpass") + "0#$"
  638. }
  639. };
  640. return controllerAdmin.GraphClient.User.Create(parameter).User;
  641. }
  642. private void DeleteAdUser(KeyVaultManagementController controllerAdmin, User user)
  643. {
  644. if (user != null)
  645. {
  646. controllerAdmin.GraphClient.User.Delete(user.ObjectId);
  647. }
  648. }
  649. private void DeleteAdApp(KeyVaultManagementController controllerAdmin, Application app)
  650. {
  651. if (app != null)
  652. {
  653. controllerAdmin.GraphClient.Application.Delete(app.ObjectId);
  654. }
  655. }
  656. private void DeleteAdServicePrincipal(KeyVaultManagementController controllerAdmin, ServicePrincipal newServicePrincipal)
  657. {
  658. if (newServicePrincipal != null)
  659. {
  660. controllerAdmin.GraphClient.ServicePrincipal.Delete(newServicePrincipal.ObjectId);
  661. }
  662. }
  663. #endregion
  664. }
  665. }