public void HttpAuthorizerShouldReturnStringToken()
        {
            int    hostPort      = 3000;
            string hostUrl       = "http://localhost:" + (hostPort).ToString();
            string FakeTokenAuth = "{auth: 'b928ab800c5c554a47ad:f41b9934520700d8474928d03ea7d808cab0cc7fcec082676f6b73ca0d9ab2b'}";

            var server = FluentMockServer.Start(hostPort);

            server
            .Given(
                Requests.WithUrl("/authz").UsingPost()
                )
            .RespondWith(
                Responses
                .WithStatusCode(200)
                .WithHeader("Content-Type", "application/json")
                .WithBody(FakeTokenAuth)
                );

            var testHttpAuthorizer = new PusherClient.HttpAuthorizer(hostUrl + "/authz");
            var AuthToken          = testHttpAuthorizer.Authorize("private-test", "fsfsdfsgsfs");

            Assert.AreNotEqual("System.Net.Http.StreamContent", AuthToken);
            Assert.AreEqual(FakeTokenAuth, AuthToken);
        }
示例#2
0
        public void HttpAuthorizerShouldRaiseExceptionIfUnauthorized()
        {
            string channelName   = "private-unauthorized-test";
            string socketId      = Guid.NewGuid().ToString("N");
            int    hostPort      = _HostPort++;
            string hostUrl       = "http://localhost:" + (hostPort).ToString();
            string FakeTokenAuth = "Forbidden";

            var server = FluentMockServer.Start(hostPort);

            server
            .Given(
                Requests.WithUrl("/unauthz").UsingPost()
                )
            .RespondWith(
                Responses
                .WithStatusCode(403)
                .WithHeader("Content-Type", "application/json")
                .WithBody(FakeTokenAuth)
                );

            ChannelUnauthorizedException exception = null;
            var testHttpAuthorizer = new PusherClient.HttpAuthorizer(hostUrl + "/unauthz");

            try
            {
                testHttpAuthorizer.Authorize(channelName, socketId);
            }
            catch (ChannelUnauthorizedException e)
            {
                exception = e;
            }

            Assert.IsNotNull(exception, $"Expecting a {nameof(ChannelUnauthorizedException)}");
            Assert.AreEqual(channelName, exception.ChannelName, nameof(ChannelUnauthorizedException.ChannelName));
            Assert.AreEqual(socketId, exception.SocketID, nameof(ChannelUnauthorizedException.SocketID));
            Assert.AreEqual(ErrorCodes.ChannelUnauthorized, exception.PusherCode);
        }