Пример #1
0
        public async Task NotAuthenticatedIntegrationTest()
        {
            WampAuthenticationPlayground playground =
                new WampAuthenticationPlayground
                    (new WampCraUserDbAuthenticationFactory
                        (new MyAuthenticationProvider(),
                        new MyUserDb()));

            SetupHost(playground);

            IWampClientAuthenticator authenticator =
                new WampCraClientAuthenticator(authenticationId: "peter", secret: "SECRET");

            IWampChannel channel =
                playground.CreateNewChannel("realm1", authenticator);

            IWampRealmProxy realmProxy = channel.RealmProxy;

            WampConnectionBrokenException openException = null;

            try
            {
                await channel.Open().ConfigureAwait(false);
            }
            catch (WampConnectionBrokenException ex)
            {
                openException = ex;
            }

            Assert.That(openException, Is.Not.Null);
            Assert.That(openException.CloseType, Is.EqualTo(SessionCloseType.Abort));
            Assert.That(openException.Reason, Is.EqualTo(WampErrors.NotAuthorized));
        }
Пример #2
0
        public async Task KillByAuthIdTest(int killingChannel, int killedChannel, IEnumerable <int> expectedDeadChannels)
        {
            WampAuthenticationPlayground playground = SetupAuthenticationHost();

            List <IWampChannel> channels = new List <IWampChannel>();

            for (int i = 0; i < 30; i++)
            {
                IWampChannel channel =
                    playground.CreateNewChannel("realm1", new WampCraClientAuthenticator("user" + i % 15, "secret"));

                channels.Add(channel);
            }

            Dictionary <int, (string reason, string message)> disconnectionDetails =
                await OpenChannels(channels);

            Assert.That(disconnectionDetails.Count, Is.EqualTo(0));

            IWampSessionManagementServiceProxy proxy =
                channels[killingChannel].RealmProxy.Services.GetCalleeProxy <IWampSessionManagementServiceProxy>();

            const string expectedReason  = "wamp.myreason";
            const string expectedMessage = "Bye bye bye";

            await proxy.KillByAuthIdAsync("user" + killedChannel, expectedReason, expectedMessage).ConfigureAwait(false);

            AssertClosedChannels(expectedDeadChannels, disconnectionDetails, expectedMessage, expectedReason);
        }
Пример #3
0
        public async Task AuthenticatedIntegrationTest()
        {
            WampAuthenticationPlayground playground =
                new WampAuthenticationPlayground
                    (new WampCraUserDbAuthenticationFactory
                        (new MyAuthenticationProvider(),
                        new MyUserDb()));

            SetupHost(playground);

            IWampClientAuthenticator authenticator =
                new WampCraClientAuthenticator(authenticationId: "peter", secret: "secret1");

            IWampChannel channel =
                playground.CreateNewChannel("realm1", authenticator);

            IWampRealmProxy realmProxy = channel.RealmProxy;

            await channel.Open().ConfigureAwait(false);

            // call a procedure we are allowed to call (so this should succeed)
            //
            IAdd2AsyncService proxy = realmProxy.Services.GetCalleeProxy <IAdd2AsyncService>();

            int five = await proxy.Add2(2, 3).ConfigureAwait(false);

            Assert.That(five, Is.EqualTo(5));

            // (try to) register a procedure where we are not allowed to (so this should fail)
            //
            Mul2Service service = new Mul2Service();

            WampException registerException = null;

            try
            {
                await realmProxy.Services.RegisterCallee(service)
                .ConfigureAwait(false);
            }
            catch (WampException ex)
            {
                registerException = ex;
            }

            Assert.That(registerException, Is.Not.Null);

            // (try to) publish to some topics
            //
            string[] topics =
            {
                "com.example.topic1",
                "com.example.topic2",
                "com.foobar.topic1",
                "com.foobar.topic2"
            };

            List <string> successfulTopics = new List <string>();

            foreach (string topic in topics)
            {
                IWampTopicProxy topicProxy = realmProxy.TopicContainer.GetTopicByUri(topic);

                try
                {
                    await topicProxy.Publish(new PublishOptions()
                    {
                        Acknowledge = true
                    },
                                             new object[] { "hello" })
                    .ConfigureAwait(false);

                    successfulTopics.Add(topic);
                }
                catch (WampException ex)
                {
                }
            }

            Assert.That(successfulTopics, Is.EquivalentTo(new string[]
            {
                "com.foobar.topic1",
                "com.example.topic1"
            }));
        }