Beispiel #1
0
 public void Init()
 {
     unitLog          = new Tests.UnitTestLog();
     unitLog.LogLevel = MockServer.LoggingMethod.Level.Verbose;
     server           = Server.Instance();
     MockServer.LoggingMethod.MockServerLog = unitLog;
     server.Start();
 }
        public void Init()
        {
            unitLog          = new Tests.UnitTestLog();
            unitLog.LogLevel = MockServer.LoggingMethod.Level.Verbose;
            server           = Server.Instance();
            MockServer.LoggingMethod.MockServerLog = unitLog;
            server.Start();

            if (!PubnubCommon.PAMEnabled)
            {
                return;
            }

            receivedGrantMessage = false;

            PNConfiguration config = new PNConfiguration()
            {
                PublishKey   = PubnubCommon.PublishKey,
                SubscribeKey = PubnubCommon.SubscribeKey,
                SecretKey    = PubnubCommon.SecretKey,
                AuthKey      = authKey,
                Uuid         = "mytestuuid",
            };

            pubnub = this.createPubNubInstance(config);

            string expected = "{\"message\":\"Success\",\"payload\":{\"level\":\"channel-group\",\"subscribe_key\":\"demo-36\",\"ttl\":20,\"channel-groups\":{\"hello_my_group\":{\"r\":1,\"w\":0,\"m\":1}}},\"service\":\"Access Manager\",\"status\":200}";

            server.AddRequest(new Request()
                              .WithMethod("GET")
                              .WithPath(string.Format("/v2/auth/grant/sub-key/{0}", PubnubCommon.SubscribeKey))
                              .WithParameter("auth", authKey)
                              .WithParameter("channel-group", channelGroupName)
                              .WithParameter("m", "1")
                              .WithParameter("pnsdk", PubnubCommon.EncodedSDK)
                              .WithParameter("r", "1")
                              .WithParameter("requestid", "myRequestId")
                              .WithParameter("timestamp", "1356998400")
                              .WithParameter("ttl", "20")
                              .WithParameter("uuid", config.Uuid)
                              .WithParameter("w", "1")
                              .WithParameter("signature", "mnWJN7WSbajMt_LWpuiXGhcs3NUcVbU3L_MZpb9_blU=")
                              .WithResponse(expected)
                              .WithStatusCode(System.Net.HttpStatusCode.OK));

            pubnub.Grant().ChannelGroups(new string[] { channelGroupName }).AuthKeys(new string[] { authKey }).Read(true).Write(true).Manage(true).TTL(20).Async(new GrantResult());

            Thread.Sleep(1000);

            grantManualEvent.WaitOne();

            pubnub.Destroy();
            pubnub.PubnubUnitTest = null;
            pubnub = null;
            Assert.IsTrue(receivedGrantMessage, "WhenChannelGroupIsRequested Grant access failed.");
        }
        public void Init()
        {
            unitLog          = new Tests.UnitTestLog();
            unitLog.LogLevel = MockServer.LoggingMethod.Level.Verbose;
            server           = Server.Instance();
            MockServer.LoggingMethod.MockServerLog = unitLog;
            server.Start();

            if (!PubnubCommon.PAMEnabled)
            {
                return;
            }

            currentTestCase      = "Init";
            receivedGrantMessage = false;

            PNConfiguration config = new PNConfiguration()
            {
                PublishKey   = PubnubCommon.PublishKey,
                SubscribeKey = PubnubCommon.SubscribeKey,
                SecretKey    = PubnubCommon.SecretKey,
                Uuid         = "mytestuuid",
                Secure       = false
            };

            server.RunOnHttps(false);

            pubnub = this.createPubNubInstance(config);
            manualResetEventWaitTimeout = (PubnubCommon.EnableStubTest) ? 1000 : 310 * 1000;

            grantManualEvent = new ManualResetEvent(false);

            string expected = "{\"message\":\"Success\",\"payload\":{\"level\":\"user\",\"subscribe_key\":\"demo-36\",\"ttl\":20,\"channel\":\"hello_my_channel\",\"auths\":{\"myAuth\":{\"r\":1,\"w\":1,\"m\":1}}},\"service\":\"Access Manager\",\"status\":200}";

            server.AddRequest(new Request()
                              .WithMethod("GET")
                              .WithPath(string.Format("/v2/auth/grant/sub-key/{0}", PubnubCommon.SubscribeKey))
                              .WithParameter("auth", authKey)
                              .WithParameter("channel", "hello_my_channel")
                              .WithParameter("channel-group", "hello_my_group%2Chello_my_group1%2Chello_my_group2")
                              .WithParameter("m", "1")
                              .WithParameter("pnsdk", PubnubCommon.EncodedSDK)
                              .WithParameter("r", "1")
                              .WithParameter("requestid", "myRequestId")
                              .WithParameter("timestamp", "1356998400")
                              .WithParameter("ttl", "20")
                              .WithParameter("uuid", config.Uuid)
                              .WithParameter("w", "1")
                              .WithParameter("signature", "oiUrVMZSf7NEGk6M9JrvpnffmMEy7wWLgYGHwMztIlU=")
                              .WithResponse(expected)
                              .WithStatusCode(System.Net.HttpStatusCode.OK));

            pubnub.Grant().AuthKeys(new string[] { authKey }).ChannelGroups(new string[] { channelGroupName, channelGroupName1, channelGroupName2 }).Channels(new string[] { channelName }).Read(true).Write(true).Manage(true).TTL(20).Async(new UTGrantResult());
            Thread.Sleep(1000);
            grantManualEvent.WaitOne(manualResetEventWaitTimeout);

            pubnub.Destroy();
            pubnub.PubnubUnitTest = null;
            pubnub = null;

            Assert.IsTrue(receivedGrantMessage, "WhenSubscribedToAChannelGroup Grant access failed.");
        }
Beispiel #4
0
        public void Init()
        {
            unitLog          = new Tests.UnitTestLog();
            unitLog.LogLevel = MockServer.LoggingMethod.Level.Verbose;
            server           = Server.Instance();
            MockServer.LoggingMethod.MockServerLog = unitLog;
            server.Start();

            if (!PubnubCommon.PAMEnabled)
            {
                return;
            }

            receivedGrantMessage = false;
            currentTestCase      = "Init";

            PNConfiguration config = new PNConfiguration()
            {
                PublishKey   = PubnubCommon.PublishKey,
                SubscribeKey = PubnubCommon.SubscribeKey,
                SecretKey    = PubnubCommon.SecretKey,
                AuthKey      = authKey,
                Uuid         = "mytestuuid",
                Secure       = false
            };

            server.RunOnHttps(false);

            pubnub = this.createPubNubInstance(config);
            manualResetEventWaitTimeout = 310 * 1000;

            channel          = "foo.*";
            grantManualEvent = new ManualResetEvent(false);

            string expected = "{\"message\":\"Success\",\"payload\":{\"level\":\"user\",\"subscribe_key\":\"demo-36\",\"ttl\":20,\"channel\":\"foo.*\",\"auths\":{\"myAuth\":{\"r\":1,\"w\":1,\"m\":1}}},\"service\":\"Access Manager\",\"status\":200}";

            server.AddRequest(new Request()
                              .WithMethod("GET")
                              .WithPath(string.Format("/v2/auth/grant/sub-key/{0}", PubnubCommon.SubscribeKey))
                              .WithParameter("auth", authKey)
                              .WithParameter("channel", "foo.%2A")
                              .WithParameter("m", "1")
                              .WithParameter("pnsdk", PubnubCommon.EncodedSDK)
                              .WithParameter("r", "1")
                              .WithParameter("requestid", "myRequestId")
                              .WithParameter("timestamp", "1356998400")
                              .WithParameter("ttl", "20")
                              .WithParameter("uuid", config.Uuid)
                              .WithParameter("w", "1")
                              .WithParameter("signature", "0OiQ1k5uyR4Y56XBmpCfMFtMkUiJKMf6k-OZEs5ea5c=")
                              .WithResponse(expected)
                              .WithStatusCode(System.Net.HttpStatusCode.OK));

            pubnub.Grant().Channels(new string[] { channel }).AuthKeys(new string[] { authKey }).Read(true).Write(true).Manage(true).TTL(20).Async(new UTGrantResult());
            Thread.Sleep(1000);
            grantManualEvent.WaitOne(manualResetEventWaitTimeout);

            if (receivedGrantMessage)
            {
                receivedGrantMessage = false;

                channel          = "foo.bar";
                grantManualEvent = new ManualResetEvent(false);

                expected = "{\"message\":\"Success\",\"payload\":{\"level\":\"user\",\"subscribe_key\":\"demo-36\",\"ttl\":20,\"channel\":\"foo.bar\",\"auths\":{\"myAuth\":{\"r\":1,\"w\":1,\"m\":1}}},\"service\":\"Access Manager\",\"status\":200}";

                server.AddRequest(new Request()
                                  .WithMethod("GET")
                                  .WithPath(string.Format("/v2/auth/grant/sub-key/{0}", PubnubCommon.SubscribeKey))
                                  .WithParameter("auth", authKey)
                                  .WithParameter("channel", channel)
                                  .WithParameter("m", "1")
                                  .WithParameter("pnsdk", PubnubCommon.EncodedSDK)
                                  .WithParameter("r", "1")
                                  .WithParameter("requestid", "myRequestId")
                                  .WithParameter("timestamp", "1356998400")
                                  .WithParameter("ttl", "20")
                                  .WithParameter("uuid", config.Uuid)
                                  .WithParameter("w", "1")
                                  .WithParameter("signature", "aIQJHjVxSH626VLkW7ULvBcifLYGyZBWGQ-Nbpss4Qw=")
                                  .WithResponse(expected)
                                  .WithStatusCode(System.Net.HttpStatusCode.OK));

                pubnub.Grant().Channels(new string[] { channel }).AuthKeys(new string[] { authKey }).Read(true).Write(true).Manage(true).TTL(20).Async(new UTGrantResult());
                Thread.Sleep(1000);
                grantManualEvent.WaitOne(manualResetEventWaitTimeout);
            }

            if (receivedGrantMessage)
            {
                receivedGrantMessage = false;

                channel          = "hello_my_channel";
                grantManualEvent = new ManualResetEvent(false);

                expected = "{\"message\":\"Success\",\"payload\":{\"level\":\"user\",\"subscribe_key\":\"demo-36\",\"ttl\":20,\"channel\":\"hello_my_channel\",\"auths\":{\"myAuth\":{\"r\":1,\"w\":1,\"m\":1}}},\"service\":\"Access Manager\",\"status\":200}";

                server.AddRequest(new Request()
                                  .WithMethod("GET")
                                  .WithPath(string.Format("/v2/auth/grant/sub-key/{0}", PubnubCommon.SubscribeKey))
                                  .WithParameter("auth", authKey)
                                  .WithParameter("channel", channel)
                                  .WithParameter("m", "1")
                                  .WithParameter("pnsdk", PubnubCommon.EncodedSDK)
                                  .WithParameter("r", "1")
                                  .WithParameter("requestid", "myRequestId")
                                  .WithParameter("timestamp", "1356998400")
                                  .WithParameter("ttl", "20")
                                  .WithParameter("uuid", config.Uuid)
                                  .WithParameter("w", "1")
                                  .WithParameter("signature", "JMQKzXgfqNo-HaHuabC0gq0X6IkVMHa9AWBCg6BGN1Q=")
                                  .WithResponse(expected)
                                  .WithStatusCode(System.Net.HttpStatusCode.OK));

                pubnub.Grant().Channels(new string[] { channel }).AuthKeys(new string[] { authKey }).Read(true).Write(true).Manage(true).TTL(20).Async(new UTGrantResult());
                Thread.Sleep(1000);
                grantManualEvent.WaitOne(manualResetEventWaitTimeout);
            }

            if (receivedGrantMessage)
            {
                receivedGrantMessage = false;

                channel          = "hello_my_channel1";
                grantManualEvent = new ManualResetEvent(false);

                expected = "{\"message\":\"Success\",\"payload\":{\"level\":\"user\",\"subscribe_key\":\"demo-36\",\"ttl\":20,\"channel\":\"hello_my_channel1\",\"auths\":{\"myAuth\":{\"r\":1,\"w\":1,\"m\":1}}},\"service\":\"Access Manager\",\"status\":200}";

                server.AddRequest(new Request()
                                  .WithMethod("GET")
                                  .WithPath(string.Format("/v2/auth/grant/sub-key/{0}", PubnubCommon.SubscribeKey))
                                  .WithParameter("auth", authKey)
                                  .WithParameter("channel", channel)
                                  .WithParameter("m", "1")
                                  .WithParameter("pnsdk", PubnubCommon.EncodedSDK)
                                  .WithParameter("r", "1")
                                  .WithParameter("requestid", "myRequestId")
                                  .WithParameter("timestamp", "1356998400")
                                  .WithParameter("ttl", "20")
                                  .WithParameter("uuid", config.Uuid)
                                  .WithParameter("w", "1")
                                  .WithParameter("signature", "FVeU4RXzcxTzOf7xvmMyEPllc388HDpDfdT5lnGcLVE=")
                                  .WithResponse(expected)
                                  .WithStatusCode(System.Net.HttpStatusCode.OK));

                pubnub.Grant().Channels(new string[] { channel }).AuthKeys(new string[] { authKey }).Read(true).Write(true).Manage(true).TTL(20).Async(new UTGrantResult());
                Thread.Sleep(1000);
                grantManualEvent.WaitOne(manualResetEventWaitTimeout);
            }

            if (receivedGrantMessage)
            {
                receivedGrantMessage = false;

                channelGroupName = "hello_my_group";
                grantManualEvent = new ManualResetEvent(false);

                expected = "{\"message\":\"Success\",\"payload\":{\"level\":\"user\",\"subscribe_key\":\"demo-36\",\"ttl\":20,\"channel-group\":\"hello_my_group\",\"auths\":{\"myAuth\":{\"r\":1,\"w\":1,\"m\":1}}},\"service\":\"Access Manager\",\"status\":200}";

                server.AddRequest(new Request()
                                  .WithMethod("GET")
                                  .WithPath(string.Format("/v2/auth/grant/sub-key/{0}", PubnubCommon.SubscribeKey))
                                  .WithParameter("auth", authKey)
                                  .WithParameter("channel-group", channelGroupName)
                                  .WithParameter("m", "1")
                                  .WithParameter("pnsdk", PubnubCommon.EncodedSDK)
                                  .WithParameter("r", "1")
                                  .WithParameter("requestid", "myRequestId")
                                  .WithParameter("timestamp", "1356998400")
                                  .WithParameter("ttl", "20")
                                  .WithParameter("uuid", config.Uuid)
                                  .WithParameter("w", "1")
                                  .WithParameter("signature", "mnWJN7WSbajMt_LWpuiXGhcs3NUcVbU3L_MZpb9_blU=")
                                  .WithResponse(expected)
                                  .WithStatusCode(System.Net.HttpStatusCode.OK));

                pubnub.Grant().ChannelGroups(new string[] { channelGroupName }).AuthKeys(new string[] { authKey }).Read(true).Write(true).Manage(true).TTL(20).Async(new UTGrantResult());
                Thread.Sleep(1000);
                grantManualEvent.WaitOne(manualResetEventWaitTimeout);
            }

            pubnub.Destroy();
            pubnub.PubnubUnitTest = null;
            pubnub = null;

            Assert.IsTrue(receivedGrantMessage, "WhenSubscribedToWildcardChannel Grant access failed.");
        }