Exemplo n.º 1
0
        public void ParsingNegotiateResponseMessageThrowsForInvalid(string payload, string expectedMessage)
        {
            var responseData = Encoding.UTF8.GetBytes(payload);

            var exception = Assert.Throws <InvalidDataException>(() => NegotiateProtocol.ParseResponse(responseData));

            Assert.Equal(expectedMessage, exception.InnerException.Message);
        }
Exemplo n.º 2
0
        public void ParsingNegotiateResponseMessageSuccessForValid(string json, string connectionId, string[] availableTransports)
        {
            var responseData = Encoding.UTF8.GetBytes(json);
            var ms           = new MemoryStream(responseData);
            var response     = NegotiateProtocol.ParseResponse(ms);

            Assert.Equal(connectionId, response.ConnectionId);
            Assert.Equal(availableTransports.Length, response.AvailableTransports.Count);

            var responseTransports = response.AvailableTransports.Select(t => t.Transport).ToList();

            Assert.Equal(availableTransports, responseTransports);
        }
Exemplo n.º 3
0
        public void ParsingNegotiateResponseMessageSuccessForValid(string json, string connectionId, string[] availableTransports, string url, string accessToken)
        {
            var responseData = Encoding.UTF8.GetBytes(json);
            var response     = NegotiateProtocol.ParseResponse(responseData);

            Assert.Equal(connectionId, response.ConnectionId);
            Assert.Equal(availableTransports?.Length, response.AvailableTransports?.Count);
            Assert.Equal(url, response.Url);
            Assert.Equal(accessToken, response.AccessToken);

            if (response.AvailableTransports != null)
            {
                var responseTransports = response.AvailableTransports.Select(t => t.Transport).ToList();

                Assert.Equal(availableTransports, responseTransports);
            }
        }
Exemplo n.º 4
0
        public void ParsingAspNetSignalRResponseThrowsError()
        {
            var payload = "{\"Url\":\"/signalr\"," +
                          "\"ConnectionToken\":\"X97dw3uxW4NPPggQsYVcNcyQcuz4w2\"," +
                          "\"ConnectionId\":\"05265228-1e2c-46c5-82a1-6a5bcc3f0143\"," +
                          "\"KeepAliveTimeout\":10.0," +
                          "\"DisconnectTimeout\":5.0," +
                          "\"TryWebSockets\":true," +
                          "\"ProtocolVersion\":\"1.5\"," +
                          "\"TransportConnectTimeout\":30.0," +
                          "\"LongPollDelay\":0.0}";

            var responseData = Encoding.UTF8.GetBytes(payload);

            var exception = Assert.Throws <InvalidDataException>(() => NegotiateProtocol.ParseResponse(responseData));

            Assert.Equal("Detected a connection attempt to an ASP.NET SignalR Server. This client only supports connecting to an ASP.NET Core SignalR Server. See https://aka.ms/signalr-core-differences for details.", exception.InnerException.Message);
        }
Exemplo n.º 5
0
        private async Task <NegotiationResponse> Negotiate(Uri url, HttpClient httpClient, ILogger logger)
        {
            try
            {
                // Get a connection ID from the server
                Log.EstablishingConnection(logger, url);
                var urlBuilder = new UriBuilder(url);
                if (!urlBuilder.Path.EndsWith("/"))
                {
                    urlBuilder.Path += "/";
                }
                urlBuilder.Path += "negotiate";

                using (var request = new HttpRequestMessage(HttpMethod.Post, urlBuilder.Uri))
                {
                    // Corefx changed the default version and High Sierra curlhandler tries to upgrade request
                    request.Version = new Version(1, 1);

                    // ResponseHeadersRead instructs SendAsync to return once headers are read
                    // rather than buffer the entire response. This gives a small perf boost.
                    // Note that it is important to dispose of the response when doing this to
                    // avoid leaving the connection open.
                    using (var response = await httpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead))
                    {
                        response.EnsureSuccessStatusCode();
                        NegotiationResponse negotiateResponse;
                        using (var responseStream = await response.Content.ReadAsStreamAsync())
                        {
                            negotiateResponse = NegotiateProtocol.ParseResponse(responseStream);
                        }
                        Log.ConnectionEstablished(_logger, negotiateResponse.ConnectionId);
                        return(negotiateResponse);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.ErrorWithNegotiation(logger, url, ex);
                throw;
            }
        }
Exemplo n.º 6
0
 public void ParsingNegotiateResponseMessageSuccessForValid5()
 => NegotiateProtocol.ParseResponse(new MemoryStream(_responseData5));
Exemplo n.º 7
0
 public void ParsingNegotiateResponseMessageSuccessForValid5()
 => NegotiateProtocol.ParseResponse(_responseData5);