public void ChallengeParametersArePassedToClient()
        {
            MockSessionAuthenticationFactory mockSessionAuthenticationFactory =
                new MockSessionAuthenticationFactory();

            WampPendingClientDetails authenticatorFactoryParameters = null;

            mockSessionAuthenticationFactory.SetGetSessionAuthenticator
                ((clientDetails, transportAuthenticator) =>
            {
                authenticatorFactoryParameters = clientDetails;
                MockSessionAuthenticator mockSessionAuthenticator = new MockSessionAuthenticator();
                mockSessionAuthenticator.SetAuthenticationMethod("ticket");
                mockSessionAuthenticator.SetChallengeDetails
                    (new MyChallenge {
                    President = "Obama"
                });

                return(mockSessionAuthenticator);
            });

            WampAuthenticationPlayground playground =
                new WampAuthenticationPlayground(mockSessionAuthenticationFactory);

            playground.Host.Open();

            string           clientAuthMethod       = null;
            ChallengeDetails clientChallengeDetails = null;

            Mock <IWampClient <JToken> > clientMock = new Mock <IWampClient <JToken> >();

            clientMock.Setup(x => x.Challenge(It.IsAny <string>(), It.IsAny <ChallengeDetails>()))
            .Callback((string authMethod, ChallengeDetails details) =>
            {
                clientAuthMethod       = authMethod;
                clientChallengeDetails = details;
            });

            IWampServerProxy serverProxy =
                playground.CreateRawConnection(clientMock.Object);

            serverProxy.Hello("realm1", new HelloDetailsHack()
            {
                AuthenticationId      = "joe",
                AuthenticationMethods = new string[] { "wampcra", "ticket" }
            });

            MyChallenge deserializedChallengeDetails =
                clientChallengeDetails.OriginalValue.Deserialize <MyChallenge>();

            Assert.That(deserializedChallengeDetails.President, Is.EqualTo("Obama"));
            Assert.That(clientAuthMethod, Is.EqualTo("ticket"));
        }
Example #2
0
        public WampRealmProxy(string name, IWampServerProxy proxy, IWampBinding <TMessage> binding, IWampClientAuthenticator authenticator)
        {
            Name  = name;
            Proxy = proxy;
            IWampFormatter <TMessage> formatter = binding.Formatter;

            mMonitor       = new WampSessionClient <TMessage>(this, formatter, authenticator);
            RpcCatalog     = new WampRpcOperationCatalogProxy <TMessage>(proxy, formatter, mMonitor);
            TopicContainer = new WampTopicContainerProxy <TMessage>(proxy, formatter, mMonitor);
            Services       = new WampRealmProxyServiceProvider(this);
            Authenticator  = authenticator;
        }
        public void ExceptionOnGetSessionAuthenticatorRaisesAbort()
        {
            MockSessionAuthenticationFactory mockSessionAuthenticationFactory =
                new MockSessionAuthenticationFactory();

            WampPendingClientDetails authenticatorFactoryParameters = null;

            mockSessionAuthenticationFactory.SetGetSessionAuthenticator
                ((clientDetails, transportAuthenticator) =>
            {
                throw new WampAuthenticationException(new MyAbortDetails()
                {
                    Message = "aborted!", Year = 2015
                }, "com.myapp.abortreason");
            });

            WampAuthenticationPlayground playground =
                new WampAuthenticationPlayground(mockSessionAuthenticationFactory);

            playground.Host.Open();

            string       clientReason       = null;
            AbortDetails clientAbortDetails = null;

            Mock <IWampClient <JToken> > clientMock = new Mock <IWampClient <JToken> >();

            clientMock.Setup(x => x.Abort(It.IsAny <AbortDetails>(), It.IsAny <string>()))
            .Callback((AbortDetails details, string reason) =>
            {
                clientReason       = reason;
                clientAbortDetails = details;
            });

            IWampServerProxy serverProxy =
                playground.CreateRawConnection(clientMock.Object);

            serverProxy.Hello("realm1", new HelloDetailsHack()
            {
                AuthenticationId      = "joe",
                AuthenticationMethods = new string[] { "wampcra", "ticket" }
            });

            Assert.That(clientReason, Is.EqualTo("com.myapp.abortreason"));
            Assert.That(clientAbortDetails.Message, Is.EqualTo("aborted!"));

            var deserialized =
                clientAbortDetails.OriginalValue.Deserialize <MyAbortDetails>();

            Assert.That(deserialized.Year, Is.EqualTo(2015));
        }
Example #4
0
        public void AuthenticateParametersArePassedToSessionAuthenticator()
        {
            MockSessionAuthenticationFactory mockSessionAuthenticationFactory =
                new MockSessionAuthenticationFactory();

            string receivedSignature = null;
            AuthenticateExtraData receivedExtraData = null;

            mockSessionAuthenticationFactory.SetGetSessionAuthenticator
                ((clientDetails, transportAuthenticator) =>
            {
                MockSessionAuthenticator mockSessionAuthenticator = new MockSessionAuthenticator();
                mockSessionAuthenticator.SetAuthenticationMethod("ticket");
                mockSessionAuthenticator.SetAuthenticate((signature, extra) =>
                {
                    receivedSignature = signature;
                    receivedExtraData = extra;
                });
                return(mockSessionAuthenticator);
            });


            WampAuthenticationPlayground playground =
                new WampAuthenticationPlayground(mockSessionAuthenticationFactory);

            playground.Host.Open();

            Mock <IWampClient <JToken> > clientMock = new Mock <IWampClient <JToken> >();

            IWampServerProxy serverProxy =
                playground.CreateRawConnection(clientMock.Object);

            serverProxy.Hello("realm1", new HelloDetailsHack()
            {
                AuthenticationId      = "joe",
                AuthenticationMethods = new string[] { "wampcra", "ticket" }
            });

            serverProxy.Authenticate("Barack Hussein", new MyAuthenticateExtraData()
            {
                Wife = "Michelle"
            });

            MyAuthenticateExtraData deserializedExtraData =
                receivedExtraData.OriginalValue.Deserialize <MyAuthenticateExtraData>();

            Assert.That(receivedSignature, Is.EqualTo("Barack Hussein"));

            Assert.That(deserializedExtraData.Wife, Is.EqualTo("Michelle"));
        }
        public void NotAuthenticatedRaisesAbort()
        {
            MockSessionAuthenticationFactory mockSessionAuthenticationFactory =
                new MockSessionAuthenticationFactory();

            WampPendingClientDetails authenticatorFactoryParameters = null;

            mockSessionAuthenticationFactory.SetGetSessionAuthenticator
                ((clientDetails, transportAuthenticator) =>
            {
                authenticatorFactoryParameters = clientDetails;
                MockSessionAuthenticator mockSessionAuthenticator = new MockSessionAuthenticator();
                mockSessionAuthenticator.SetAuthenticationMethod("ticket");

                mockSessionAuthenticator.SetAuthenticate((signature, extraData) =>
                {
                    mockSessionAuthenticator.SetAuthenticationId(clientDetails.HelloDetails.AuthenticationId);
                    mockSessionAuthenticator.SetIsAuthenticated(false);
                });

                return(mockSessionAuthenticator);
            });

            WampAuthenticationPlayground playground =
                new WampAuthenticationPlayground(mockSessionAuthenticationFactory);

            playground.Host.Open();

            Mock <IWampClient <JToken> > clientMock = new Mock <IWampClient <JToken> >();

            IWampServerProxy serverProxy =
                playground.CreateRawConnection(clientMock.Object);

            serverProxy.Hello("realm1", new HelloDetailsHack()
            {
                AuthenticationId      = "joe",
                AuthenticationMethods = new string[] { "wampcra", "ticket" }
            });

            serverProxy.Authenticate("Barack Hussein", new AuthenticateExtraData());

            clientMock.Verify(x => x.Abort(It.IsAny <AbortDetails>(), It.IsAny <string>()));
        }
Example #6
0
 public ServerProxyCallback(IWampServerProxy proxy, long requestId)
 {
     mProxy     = proxy;
     mRequestId = requestId;
 }
        public void WelcomeParametersArePassedToClient()
        {
            MockSessionAuthenticationFactory mockSessionAuthenticationFactory =
                new MockSessionAuthenticationFactory();

            WampPendingClientDetails authenticatorFactoryParameters = null;

            mockSessionAuthenticationFactory.SetGetSessionAuthenticator
                ((clientDetails, transportAuthenticator) =>
            {
                authenticatorFactoryParameters = clientDetails;
                MockSessionAuthenticator mockSessionAuthenticator = new MockSessionAuthenticator();
                mockSessionAuthenticator.SetAuthenticationMethod("ticket");

                mockSessionAuthenticator.SetAuthenticate((signature, extraData) =>
                {
                    mockSessionAuthenticator.SetAuthenticationId(clientDetails.HelloDetails.AuthenticationId);
                    mockSessionAuthenticator.SetIsAuthenticated(true);
                    mockSessionAuthenticator.SetWelcomeDetails(new MyWelcomeDetails()
                    {
                        AuthenticationProvider = "unittest",
                        AuthenticationRole     = "testee",
                        Country = "United States of America"
                    });

                    mockSessionAuthenticator.SetAuthorizer(new WampStaticAuthorizer(new List <WampUriPermissions>()));
                });

                return(mockSessionAuthenticator);
            });

            WampAuthenticationPlayground playground =
                new WampAuthenticationPlayground(mockSessionAuthenticationFactory);

            playground.Host.Open();

            long?          clientSessionId      = null;
            WelcomeDetails clientWelcomeDetails = null;

            Mock <IWampClient <JToken> > clientMock = new Mock <IWampClient <JToken> >();

            clientMock.Setup(x => x.Welcome(It.IsAny <long>(), It.IsAny <WelcomeDetails>()))
            .Callback((long sessionId, WelcomeDetails details) =>
            {
                clientSessionId      = sessionId;
                clientWelcomeDetails = details;
            });

            IWampServerProxy serverProxy =
                playground.CreateRawConnection(clientMock.Object);

            serverProxy.Hello("realm1", new HelloDetailsHack()
            {
                AuthenticationId      = "joe",
                AuthenticationMethods = new string[] { "wampcra", "ticket" }
            });

            serverProxy.Authenticate("Barack Hussein", new AuthenticateExtraData());

            Assert.That(clientWelcomeDetails.AuthenticationMethod, Is.EqualTo("ticket"));
            Assert.That(clientWelcomeDetails.AuthenticationId, Is.EqualTo("joe"));
            Assert.That(clientWelcomeDetails.AuthenticationProvider, Is.EqualTo("unittest"));
            Assert.That(clientWelcomeDetails.AuthenticationRole, Is.EqualTo("testee"));
            Assert.That(clientSessionId, Is.EqualTo(authenticatorFactoryParameters.SessionId));

            MyWelcomeDetails deserializedWelcomeDetails =
                clientWelcomeDetails.OriginalValue.Deserialize <MyWelcomeDetails>();

            Assert.That(deserializedWelcomeDetails.Country, Is.EqualTo("United States of America"));
        }
 public WampRpcOperationCatalogProxy(IWampServerProxy proxy, IWampFormatter <TMessage> formatter, IWampClientConnectionMonitor monitor)
 {
     mCallee = new WampCallee <TMessage>(proxy, formatter, monitor);
     mCaller = new WampCaller <TMessage>(proxy, formatter, monitor);
 }
Example #9
0
 public WampCancellableInvocationProxy(IWampServerProxy proxy, long requestId)
 {
     Proxy     = proxy;
     RequestId = requestId;
 }
 public WampTopicContainerProxy(IWampServerProxy proxy, IWampFormatter <TMessage> formatter, IWampClientConnectionMonitor monitor)
 {
     mProxy      = proxy;
     mSubscriber = new WampSubscriber <TMessage>(proxy, formatter, monitor);
     mPublisher  = new WampPublisher <TMessage>(proxy, formatter, monitor);
 }