public void ChannelDataDecrypterWillRaiseErrorWhenEncryptedDataPropertiesAreNotProvided() { // Arrange ChannelDecryptionException error = null; ChannelDataDecrypter decrypter = new ChannelDataDecrypter(); EncryptedChannelData data = new EncryptedChannelData(); // Act try { decrypter.DecryptData(EncryptionMasterKey, data); } catch (ChannelDecryptionException exception) { error = exception; } // Assert Assert.IsNotNull(error, $"Expected a {nameof(ChannelDecryptionException)} exception"); }
public void ChannelDataDecrypterWillRaiseErrorWhenEncryptedDataIsNull() { // Arrange ChannelDecryptionException error = null; ChannelDataDecrypter decrypter = new ChannelDataDecrypter(); string keyText = System.Convert.ToBase64String(EncryptionMasterKey); Assert.IsNotNull(keyText); // Act try { decrypter.DecryptData(EncryptionMasterKey, null); } catch (ChannelDecryptionException exception) { error = exception; } // Assert Assert.IsNotNull(error, $"Expected a {nameof(ChannelDecryptionException)} exception"); }
public async Task PusherEventEmitterPrivateEncryptedChannelDecryptionFailureTestAsync() { // Arrange var pusherServer = new PusherServer.Pusher(Config.AppId, Config.AppKey, Config.AppSecret, new PusherServer.PusherOptions { Cluster = Config.Cluster, EncryptionMasterKey = GenerateEncryptionMasterKey(), }); ChannelDecryptionException decryptionException = null; ChannelTypes channelType = ChannelTypes.PrivateEncrypted; // Use a different encryption master key - decryption should fail Pusher localPusher = PusherFactory.GetPusher(channelType: ChannelTypes.Presence, saveTo: _clients, encryptionKey: GenerateEncryptionMasterKey()); string testEventName = "private-encrypted-event-test"; AutoResetEvent globalEventReceived = new AutoResetEvent(false); AutoResetEvent channelEventReceived = new AutoResetEvent(false); AutoResetEvent errorReceived = new AutoResetEvent(false); PusherEvent pusherEvent = CreatePusherEvent(channelType, testEventName); await localPusher.ConnectAsync().ConfigureAwait(false); Channel localChannel = await localPusher.SubscribeAsync(pusherEvent.ChannelName).ConfigureAwait(false); void GeneralListener(string eventName, PusherEvent eventData) { if (eventName == testEventName) { globalEventReceived.Set(); } } void Listener(PusherEvent eventData) { channelEventReceived.Set(); } EventTestData data = new EventTestData { TextField = ExpectedTextField, IntegerField = ExpectedIntegerField, }; void ErrorHandler(object sender, PusherException error) { decryptionException = error as ChannelDecryptionException; if (decryptionException != null) { errorReceived.Set(); } } // Act localPusher.Error += ErrorHandler; localPusher.BindAll(GeneralListener); localChannel.Bind(testEventName, Listener); await pusherServer.TriggerAsync(pusherEvent.ChannelName, testEventName, data).ConfigureAwait(false); // Assert Assert.IsTrue(errorReceived.WaitOne(TimeSpan.FromSeconds(5)), "Expected to handle an error."); Assert.IsNotNull(decryptionException.SocketID, nameof(decryptionException.SocketID)); Assert.AreEqual(testEventName, decryptionException.EventName, nameof(decryptionException.EventName)); Assert.AreEqual(localChannel.Name, decryptionException.ChannelName, nameof(decryptionException.ChannelName)); Assert.IsFalse(globalEventReceived.WaitOne(TimeSpan.FromSeconds(0.1)), "Did not expect to get a global event raised."); Assert.IsFalse(channelEventReceived.WaitOne(TimeSpan.FromSeconds(0.1)), "Did not expect to get a channel event raised."); }