1
0

RemoveEncryptionKeys.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. using System.Linq;
  2. using Content.IntegrationTests.Tests.Interaction;
  3. using Content.Shared.Radio.Components;
  4. using Content.Shared.Wires;
  5. namespace Content.IntegrationTests.Tests.EncryptionKeys;
  6. public sealed class RemoveEncryptionKeys : InteractionTest
  7. {
  8. [Test]
  9. public async Task HeadsetKeys()
  10. {
  11. await SpawnTarget("ClothingHeadsetGrey");
  12. var comp = Comp<EncryptionKeyHolderComponent>();
  13. Assert.Multiple(() =>
  14. {
  15. Assert.That(comp.KeyContainer.ContainedEntities, Has.Count.EqualTo(1));
  16. Assert.That(comp.DefaultChannel, Is.EqualTo("Common"));
  17. Assert.That(comp.Channels, Has.Count.EqualTo(1));
  18. Assert.That(comp.Channels.First(), Is.EqualTo("Common"));
  19. });
  20. // Remove the key
  21. await InteractUsing(Screw);
  22. Assert.Multiple(() =>
  23. {
  24. Assert.That(comp.KeyContainer.ContainedEntities, Has.Count.EqualTo(0));
  25. Assert.That(comp.DefaultChannel, Is.Null);
  26. Assert.That(comp.Channels, Has.Count.EqualTo(0));
  27. });
  28. // Check that the key was ejected and not just deleted or something.
  29. await AssertEntityLookup(("EncryptionKeyCommon", 1));
  30. // Re-insert a key.
  31. await InteractUsing("EncryptionKeyCentCom");
  32. Assert.Multiple(() =>
  33. {
  34. Assert.That(comp.KeyContainer.ContainedEntities, Has.Count.EqualTo(1));
  35. Assert.That(comp.DefaultChannel, Is.EqualTo("CentCom"));
  36. Assert.That(comp.Channels, Has.Count.EqualTo(1));
  37. Assert.That(comp.Channels.First(), Is.EqualTo("CentCom"));
  38. });
  39. }
  40. [Test]
  41. public async Task CommsServerKeys()
  42. {
  43. await SpawnTarget("TelecomServerFilled");
  44. var comp = Comp<EncryptionKeyHolderComponent>();
  45. var panel = Comp<WiresPanelComponent>();
  46. Assert.Multiple(() =>
  47. {
  48. Assert.That(comp.KeyContainer.ContainedEntities, Has.Count.GreaterThan(0));
  49. Assert.That(comp.Channels, Has.Count.GreaterThan(0));
  50. Assert.That(panel.Open, Is.False);
  51. });
  52. // cannot remove keys without opening panel
  53. await InteractUsing(Pry);
  54. Assert.Multiple(() =>
  55. {
  56. Assert.That(comp.KeyContainer.ContainedEntities, Has.Count.GreaterThan(0));
  57. Assert.That(comp.Channels, Has.Count.GreaterThan(0));
  58. Assert.That(panel.Open, Is.False);
  59. });
  60. // Open panel
  61. await InteractUsing(Screw);
  62. Assert.Multiple(() =>
  63. {
  64. Assert.That(panel.Open, Is.True);
  65. // Keys are still here
  66. Assert.That(comp.KeyContainer.ContainedEntities, Has.Count.GreaterThan(0));
  67. Assert.That(comp.Channels, Has.Count.GreaterThan(0));
  68. });
  69. // Now remove the keys
  70. await InteractUsing(Pry);
  71. Assert.Multiple(() =>
  72. {
  73. Assert.That(comp.KeyContainer.ContainedEntities, Has.Count.EqualTo(0));
  74. Assert.That(comp.Channels, Has.Count.EqualTo(0));
  75. });
  76. // Reinsert a key
  77. await InteractUsing("EncryptionKeyCentCom");
  78. Assert.Multiple(() =>
  79. {
  80. Assert.That(comp.KeyContainer.ContainedEntities, Has.Count.EqualTo(1));
  81. Assert.That(comp.DefaultChannel, Is.EqualTo("CentCom"));
  82. Assert.That(comp.Channels, Has.Count.EqualTo(1));
  83. Assert.That(comp.Channels.First(), Is.EqualTo("CentCom"));
  84. });
  85. // Remove it again
  86. await InteractUsing(Pry);
  87. Assert.Multiple(() =>
  88. {
  89. Assert.That(comp.KeyContainer.ContainedEntities, Has.Count.EqualTo(0));
  90. Assert.That(comp.Channels, Has.Count.EqualTo(0));
  91. });
  92. // Prying again will start deconstructing the machine.
  93. AssertPrototype("TelecomServerFilled");
  94. await InteractUsing(Pry);
  95. AssertPrototype("MachineFrame");
  96. }
  97. }