Inheritance: ICloudBlobStorageProvider
Esempio n. 1
0
        private async Task <IReadOnlyCollection <Payload> > ReceiveMessageAsync(Mocks.CloudBlobStorageProviderMock cloudBlobStorage, Mocks.InboxHttpHandlerMock inboxMock, ICryptoProvider cryptoProvider, OwnEndpoint receiver)
        {
            Requires.NotNull(cloudBlobStorage, "cloudBlobStorage");
            Requires.NotNull(receiver, "receiver");

            var httpHandler = new Mocks.HttpMessageHandlerMock();

            cloudBlobStorage.AddHttpHandler(httpHandler);
            inboxMock.Register(httpHandler);

            var channel = new Channel {
                HttpClient         = new HttpClient(httpHandler),
                HttpClientLongPoll = new HttpClient(httpHandler),
                CloudBlobStorage   = cloudBlobStorage,
                CryptoServices     = cryptoProvider,
                Endpoint           = receiver,
                Logger             = this.logger,
            };

            var progressMessage = new TaskCompletionSource <Payload>();
            var progress        = new Progress <Payload>(m => progressMessage.SetResult(m));

            var messages = await channel.ReceiveAsync(progress : progress);

            Assert.That(messages.Count, Is.EqualTo(1));
            await progressMessage.Task;

            Assert.That(progressMessage.Task.Result, Is.SameAs(messages.Single()));
            return(messages);
        }
Esempio n. 2
0
        private async Task ReceiveMessageAsync(Mocks.CloudBlobStorageProviderMock cloudStorage, Mocks.InboxHttpHandlerMock inboxMock, CryptoSettings receiverCrypto, OwnEndpoint receiverEndpoint)
        {
            Requires.NotNull(cloudStorage, "cloudStorage");
            Requires.NotNull(receiverCrypto, "receiverCrypto");
            Requires.NotNull(receiverEndpoint, "receiverEndpoint");

            var httpHandler = new Mocks.HttpMessageHandlerMock();

            cloudStorage.AddHttpHandler(httpHandler);
            inboxMock.Register(httpHandler);

            var channel = new Channel
            {
                HttpClient         = new HttpClient(httpHandler),
                HttpClientLongPoll = new HttpClient(httpHandler),
                CloudBlobStorage   = cloudStorage,
                CryptoServices     = receiverCrypto,
                Endpoint           = receiverEndpoint,
                Logger             = this.logger,
            };

            var messages = await channel.ReceiveAsync();

            Assert.Equal(1, messages.Count);
            Assert.Equal(Valid.Message, messages[0].Payload);
        }
Esempio n. 3
0
        private async Task SendMessageAsync(Mocks.CloudBlobStorageProviderMock cloudStorage, Mocks.InboxHttpHandlerMock inboxMock, CryptoSettings senderCrypto, OwnEndpoint senderEndpoint, Endpoint receiverEndpoint)
        {
            Requires.NotNull(cloudStorage, "cloudStorage");
            Requires.NotNull(senderCrypto, "senderCrypto");
            Requires.NotNull(senderEndpoint, "senderEndpoint");
            Requires.NotNull(receiverEndpoint, "receiverEndpoint");

            var httpHandler = new Mocks.HttpMessageHandlerMock();

            cloudStorage.AddHttpHandler(httpHandler);

            inboxMock.Register(httpHandler);

            var sentMessage = Valid.Message;

            var channel = new Channel()
            {
                HttpClient       = new HttpClient(httpHandler),
                CloudBlobStorage = cloudStorage,
                CryptoServices   = senderCrypto,
                Endpoint         = senderEndpoint,
                Logger           = this.logger,
            };

            await channel.PostAsync(sentMessage, new[] { receiverEndpoint }, Valid.ExpirationUtc);
        }
Esempio n. 4
0
		private async Task TestSendAndReceiveAsync(
			ICryptoProvider senderCrypto, OwnEndpoint senderEndpoint, ICryptoProvider receiverCrypto, OwnEndpoint receiverEndpoint) {
			var inboxMock = new Mocks.InboxHttpHandlerMock(new[] { receiverEndpoint.PublicEndpoint });
			var cloudStorage = new Mocks.CloudBlobStorageProviderMock();

			await this.SendMessageAsync(cloudStorage, inboxMock, senderCrypto, senderEndpoint, receiverEndpoint.PublicEndpoint);
			await this.ReceiveMessageAsync(cloudStorage, inboxMock, receiverCrypto, receiverEndpoint);
		}
Esempio n. 5
0
        private async Task TestSendAndReceiveAsync(
            CryptoSettings senderCrypto, OwnEndpoint senderEndpoint, CryptoSettings receiverCrypto, OwnEndpoint receiverEndpoint)
        {
            var inboxMock = new Mocks.InboxHttpHandlerMock(new[] { receiverEndpoint.PublicEndpoint });
            var cloudStorage = new Mocks.CloudBlobStorageProviderMock();

            await this.SendMessageAsync(cloudStorage, inboxMock, senderCrypto, senderEndpoint, receiverEndpoint.PublicEndpoint);
            await this.ReceiveMessageAsync(cloudStorage, inboxMock, receiverCrypto, receiverEndpoint);
        }
Esempio n. 6
0
		public void PostAndReceiveAsync() {
			Task.Run(async delegate {
				var sender = Valid.GenerateOwnEndpoint();
				var receiver = Valid.GenerateOwnEndpoint();

				var cloudStorage = new Mocks.CloudBlobStorageProviderMock();
				var inboxMock = new Mocks.InboxHttpHandlerMock(new[] { receiver.PublicEndpoint });
				var cryptoProvider = new Mocks.MockCryptoProvider();

				var sentMessage = Valid.Message;
				await this.SendMessageAsync(cloudStorage, inboxMock, cryptoProvider, sender, receiver.PublicEndpoint, sentMessage);
				var messages = await this.ReceiveMessageAsync(cloudStorage, inboxMock, new Mocks.MockCryptoProvider(), receiver);

				Assert.That(messages.Count, Is.EqualTo(1));
				var receivedMessage = messages.Single();
				Assert.That(receivedMessage.ContentType, Is.EqualTo(sentMessage.ContentType));
				Assert.That(receivedMessage.Content, Is.EqualTo(sentMessage.Content));
			}).GetAwaiter().GetResult();
		}
Esempio n. 7
0
        public void PostAndReceiveAsync()
        {
            Task.Run(async delegate {
                var sender   = Valid.GenerateOwnEndpoint();
                var receiver = Valid.GenerateOwnEndpoint();

                var cloudStorage   = new Mocks.CloudBlobStorageProviderMock();
                var inboxMock      = new Mocks.InboxHttpHandlerMock(new[] { receiver.PublicEndpoint });
                var cryptoProvider = new Mocks.MockCryptoProvider();

                var sentMessage = Valid.Message;
                await this.SendMessageAsync(cloudStorage, inboxMock, cryptoProvider, sender, receiver.PublicEndpoint, sentMessage);
                var messages = await this.ReceiveMessageAsync(cloudStorage, inboxMock, new Mocks.MockCryptoProvider(), receiver);

                Assert.That(messages.Count, Is.EqualTo(1));
                var receivedMessage = messages.Single();
                Assert.That(receivedMessage.Payload.ContentType, Is.EqualTo(sentMessage.ContentType));
                Assert.That(receivedMessage.Payload.Content, Is.EqualTo(sentMessage.Content));
            }).GetAwaiter().GetResult();
        }
Esempio n. 8
0
        public void PostAndReceiveAsync()
        {
            Task.Run(async delegate
            {
                var sender = Valid.GenerateOwnEndpoint();
                var receiver = Valid.GenerateOwnEndpoint();

                var cloudStorage = new Mocks.CloudBlobStorageProviderMock();
                var inboxMock = new Mocks.InboxHttpHandlerMock(new[] { receiver.PublicEndpoint });
                var cryptoProvider = new CryptoSettings(SecurityLevel.Minimum);

                var sentMessage = Valid.Message;
                await this.SendMessageAsync(cloudStorage, inboxMock, cryptoProvider, sender, receiver.PublicEndpoint, sentMessage);
                var messages = await this.ReceiveMessageAsync(cloudStorage, inboxMock, new CryptoSettings(SecurityLevel.Minimum), receiver);

                Assert.Equal(1, messages.Count);
                var receivedMessage = messages.Single();
                Assert.Equal(receivedMessage.Payload.ContentType, sentMessage.ContentType);
                Assert.Equal(receivedMessage.Payload.Content, sentMessage.Content);
            }).GetAwaiter().GetResult();
        }
Esempio n. 9
0
        public void PayloadTamperingTests()
        {
            Task.Run(async delegate {
                var sender   = Valid.GenerateOwnEndpoint(this.desktopCryptoProvider);
                var receiver = Valid.GenerateOwnEndpoint(this.desktopCryptoProvider);

                for (int i = 0; i < 100; i++)
                {
                    var cloudStorage = new Mocks.CloudBlobStorageProviderMock();
                    var inboxMock    = new Mocks.InboxHttpHandlerMock(new[] { receiver.PublicEndpoint });

                    var sentMessage = Valid.Message;
                    await this.SendMessageAsync(cloudStorage, inboxMock, this.desktopCryptoProvider, sender, receiver.PublicEndpoint, sentMessage);

                    // Tamper with the payload itself.
                    TestUtilities.ApplyFuzzing(cloudStorage.Blobs.Single().Value, 1);

                    Assert.Throws <InvalidMessageException>(() => this.ReceiveMessageAsync(cloudStorage, inboxMock, this.desktopCryptoProvider, receiver).GetAwaiter().GetResult());
                }
            }).GetAwaiter().GetResult();
        }
Esempio n. 10
0
        private async Task SendMessageAsync(Mocks.CloudBlobStorageProviderMock cloudBlobStorage, Mocks.InboxHttpHandlerMock inboxMock, ICryptoProvider cryptoProvider, OwnEndpoint sender, Endpoint receiver, Payload message)
        {
            Requires.NotNull(cloudBlobStorage, "cloudBlobStorage");
            Requires.NotNull(sender, "sender");
            Requires.NotNull(message, "message");

            var httpHandler = new Mocks.HttpMessageHandlerMock();

            cloudBlobStorage.AddHttpHandler(httpHandler);
            inboxMock.Register(httpHandler);

            var channel = new Channel()
            {
                HttpClient       = new HttpClient(httpHandler),
                CloudBlobStorage = cloudBlobStorage,
                CryptoServices   = cryptoProvider,
                Endpoint         = sender,
                Logger           = this.logger,
            };

            await channel.PostAsync(Valid.Message, new[] { receiver }, Valid.ExpirationUtc);
        }
Esempio n. 11
0
        public void PayloadReferenceTamperingTests()
        {
            Task.Run(async delegate {
                var sender   = Valid.GenerateOwnEndpoint(this.desktopCryptoProvider);
                var receiver = Valid.GenerateOwnEndpoint(this.desktopCryptoProvider);

                for (int i = 0; i < 100; i++)
                {
                    var cloudStorage = new Mocks.CloudBlobStorageProviderMock();
                    var inboxMock    = new Mocks.InboxHttpHandlerMock(new[] { receiver.PublicEndpoint });

                    var sentMessage = Valid.Message;
                    await this.SendMessageAsync(cloudStorage, inboxMock, this.desktopCryptoProvider, sender, receiver.PublicEndpoint, sentMessage);

                    // Tamper with the payload reference.
                    TestUtilities.ApplyFuzzing(inboxMock.Inboxes[receiver.PublicEndpoint][0].Item2, 1);

                    var receivedMessages =
                        await this.ReceiveMessageAsync(cloudStorage, inboxMock, this.desktopCryptoProvider, receiver, expectMessage: false);
                    Assert.AreEqual(0, receivedMessages.Count);
                }
            }).GetAwaiter().GetResult();
        }
Esempio n. 12
0
        public void PayloadReferenceTamperingTests()
        {
            Task.Run(async delegate
            {
                var sender = Valid.GenerateOwnEndpoint(this.desktopCryptoProvider);
                var receiver = Valid.GenerateOwnEndpoint(this.desktopCryptoProvider);

                for (int i = 0; i < 100; i++)
                {
                    var cloudStorage = new Mocks.CloudBlobStorageProviderMock();
                    var inboxMock = new Mocks.InboxHttpHandlerMock(new[] { receiver.PublicEndpoint });

                    var sentMessage = Valid.Message;
                    await this.SendMessageAsync(cloudStorage, inboxMock, this.desktopCryptoProvider, sender, receiver.PublicEndpoint, sentMessage);

                    // Tamper with the payload reference.
                    TestUtilities.ApplyFuzzing(inboxMock.Inboxes[receiver.PublicEndpoint][0].Item2, 1);

                    var receivedMessages =
                        await this.ReceiveMessageAsync(cloudStorage, inboxMock, this.desktopCryptoProvider, receiver, expectMessage: false);
                    Assert.Equal(0, receivedMessages.Count);
                }
            }).GetAwaiter().GetResult();
        }
Esempio n. 13
0
		public void PayloadTamperingTests() {
			Task.Run(async delegate {
				var sender = Valid.GenerateOwnEndpoint(this.desktopCryptoProvider);
				var receiver = Valid.GenerateOwnEndpoint(this.desktopCryptoProvider);

				for (int i = 0; i < 100; i++) {
					var cloudStorage = new Mocks.CloudBlobStorageProviderMock();
					var inboxMock = new Mocks.InboxHttpHandlerMock(new[] { receiver.PublicEndpoint });

					var sentMessage = Valid.Message;
					await this.SendMessageAsync(cloudStorage, inboxMock, this.desktopCryptoProvider, sender, receiver.PublicEndpoint, sentMessage);

					// Tamper with the payload itself.
					TestUtilities.ApplyFuzzing(cloudStorage.Blobs.Single().Value, 1);

					Assert.Throws<InvalidMessageException>(() => this.ReceiveMessageAsync(cloudStorage, inboxMock, this.desktopCryptoProvider, receiver).GetAwaiter().GetResult());
				}
			}).GetAwaiter().GetResult();
		}
Esempio n. 14
0
        private async Task <IReadOnlyCollection <Channel.PayloadReceipt> > ReceiveMessageAsync(Mocks.CloudBlobStorageProviderMock cloudBlobStorage, Mocks.InboxHttpHandlerMock inboxMock, CryptoSettings cryptoProvider, OwnEndpoint receiver, bool expectMessage = true)
        {
            Requires.NotNull(cloudBlobStorage, "cloudBlobStorage");
            Requires.NotNull(receiver, "receiver");

            var httpHandler = new Mocks.HttpMessageHandlerMock();

            cloudBlobStorage.AddHttpHandler(httpHandler);
            inboxMock.Register(httpHandler);

            var channel = new Channel
            {
                HttpClient         = new HttpClient(httpHandler),
                HttpClientLongPoll = new HttpClient(httpHandler),
                CloudBlobStorage   = cloudBlobStorage,
                CryptoServices     = cryptoProvider,
                Endpoint           = receiver,
                Logger             = this.logger,
            };

            var progressMessage = new TaskCompletionSource <Payload>();
            var progress        = new Progress <Channel.PayloadReceipt>(m => progressMessage.SetResult(m.Payload));

            var messages = await channel.ReceiveAsync(progress : progress);

            if (expectMessage)
            {
                Assert.Equal(1, messages.Count);
                await progressMessage.Task;
                Assert.Same(progressMessage.Task.Result, messages.Single().Payload);
            }
            else
            {
                Assert.Equal(0, messages.Count);
            }

            return(messages);
        }