public void TestBuildGlobalHereNowRequestCommon(bool ssl, bool showUUIDList, bool includeUserState, string authKey){
            string uuid = "customuuid";

            Pubnub pubnub = new Pubnub (
                Common.PublishKey,
                Common.SubscribeKey,
                "",
                "",
                ssl
            );
            pubnub.AuthenticationKey = authKey;
            string authKeyString = "";
            if (!string.IsNullOrEmpty(authKey)) {
                authKeyString = string.Format ("&auth={0}", pubnub.AuthenticationKey);
            }

            int disableUUID = (showUUIDList) ? 0 : 1;
            int userState = (includeUserState) ? 1 : 0;
            string parameters = string.Format ("disable_uuids={0}&state={1}", disableUUID, userState);

            Uri uri = BuildRequests.BuildGlobalHereNowRequest (showUUIDList, includeUserState,
                uuid, ssl, pubnub.Origin, pubnub.AuthenticationKey, Common.SubscribeKey
            );

            //http://pubsub.pubnub.com/v2/presence/sub_key/demo-36?disable_uuids=1&state=0&uuid=customuuid&auth=authKey&pnsdk=PubNub-CSharp-UnityOSX/3.6.9.0
            string expected = string.Format ("http{0}://{1}/v2/presence/sub_key/{2}?{3}&uuid={4}{5}&pnsdk={6}",
                ssl?"s":"", pubnub.Origin, Common.SubscribeKey, parameters,
                uuid, authKeyString, 
                Utility.EncodeUricomponent(PubnubUnity.Version, ResponseType.GlobalHereNow, false, false)
            );
            string received = uri.OriginalString;
            Common.LogAndCompare (expected, received);
        }
Exemple #2
0
        public void TestBuildPresenceHeartbeatRequestCommon(string[] channels, string userState,
                                                            bool ssl, string authKey)
        {
            string uuid = "customuuid";

            Pubnub pubnub = new Pubnub(
                Common.PublishKey,
                Common.SubscribeKey,
                "",
                "",
                ssl
                );

            pubnub.AuthenticationKey = authKey;
            string authKeyString = "";

            if (!string.IsNullOrEmpty(authKey))
            {
                authKeyString = string.Format("&auth={0}", pubnub.AuthenticationKey);
            }

            Uri uri = BuildRequests.BuildPresenceHeartbeatRequest(channels, userState, uuid, ssl,
                                                                  pubnub.Origin, pubnub.AuthenticationKey, Common.SubscribeKey
                                                                  );

            //https://pubsub.pubnub.com/v2/presence/sub_key/demo-36/channel/user_state_channel/heartbeat?uuid=customuuid&state={"k":"v"}&auth=authKey&pnsdk=PubNub-CSharp-UnityIOS/3.6.9.0

            string expected = string.Format("http{0}://{1}/v2/presence/sub_key/{2}/channel/{3}/heartbeat?uuid={4}{5}{6}{7}&pnsdk={8}",
                                            ssl?"s":"", pubnub.Origin, Common.SubscribeKey, string.Join(",", channels), uuid, (userState == "")?"":"&state=", userState,
                                            authKeyString, PubnubUnity.Version
                                            );
            string received = uri.ToString();

            Common.LogAndCompare(expected, received);
        }
Exemple #3
0
        public void TestBuildWhereNowRequestCommon(bool ssl, string authKey, string sessionUUID)
        {
            string uuid = "customuuid";

            Pubnub pubnub = new Pubnub(
                Common.PublishKey,
                Common.SubscribeKey,
                "",
                "",
                ssl
                );

            pubnub.AuthenticationKey = authKey;
            string authKeyString = "";

            if (!string.IsNullOrEmpty(authKey))
            {
                authKeyString = string.Format("&auth={0}", pubnub.AuthenticationKey);
            }

            Uri uri = BuildRequests.BuildWhereNowRequest(uuid, sessionUUID,
                                                         ssl, pubnub.Origin, pubnub.AuthenticationKey, Common.SubscribeKey
                                                         );

            //http://ps.pndsn.com/v2/presence/sub_key/demo-36/uuid/customuuid?uuid=&auth=authKey&pnsdk=PubNub-CSharp-UnityIOS/3.6.9.0
            string expected = string.Format("http{0}://{1}/v2/presence/sub_key/{2}/uuid/{3}?uuid={4}{5}&pnsdk={6}",
                                            ssl?"s":"", pubnub.Origin, Common.SubscribeKey, uuid, sessionUUID,
                                            authKeyString,
                                            Utility.EncodeUricomponent(PubnubUnity.Version, ResponseType.WhereNow, false, false)
                                            );
            string received = uri.OriginalString;

            Common.LogAndCompare(expected, received);
        }
Exemple #4
0
        public void TestBuildGetUserStateRequestCommon(bool ssl, string authKey)
        {
            string channel   = "user_state_channel";
            string userState = "{\"k\":\"v\"}";
            string uuid      = "customuuid";

            Pubnub pubnub = new Pubnub(
                Common.PublishKey,
                Common.SubscribeKey,
                "",
                "",
                ssl
                );

            pubnub.AuthenticationKey = authKey;
            string authKeyString = "";

            if (!string.IsNullOrEmpty(authKey))
            {
                authKeyString = string.Format("&auth={0}", pubnub.AuthenticationKey);
            }

            Uri uri = BuildRequests.BuildGetUserStateRequest(channel, uuid, ssl,
                                                             pubnub.Origin, pubnub.AuthenticationKey, Common.SubscribeKey
                                                             );

            //https://pubsub.pubnub.com/v2/presence/sub_key/demo-36/channel/user_state_channel/uuid/customuuid?uuid=customuuid&auth=authKey&pnsdk=PubNub-CSharp-UnityIOS/3.6.9.0
            string expected = string.Format("http{0}://{1}/v2/presence/sub_key/{2}/channel/{3}/uuid/{4}?uuid={6}{7}&pnsdk={8}",
                                            ssl?"s":"", pubnub.Origin, Common.SubscribeKey, channel, uuid, userState,
                                            uuid, authKeyString, PubnubUnity.Version
                                            );
            string received = uri.ToString();

            Common.LogAndCompare(expected, received);
        }
Exemple #5
0
        public void TestBuildSubscribeRequestCommon(string[] channels, object timetoken, string userState,
                                                    bool ssl, string authKey)
        {
            string uuid = "customuuid";

            Pubnub pubnub = new Pubnub(
                Common.PublishKey,
                Common.SubscribeKey,
                "",
                "",
                ssl
                );

            pubnub.AuthenticationKey = authKey;
            string authKeyString = "";

            if (!string.IsNullOrEmpty(authKey))
            {
                authKeyString = string.Format("&auth={0}", pubnub.AuthenticationKey);
            }

            Uri uri = BuildRequests.BuildMultiChannelSubscribeRequest(channels, timetoken, userState, uuid, ssl,
                                                                      pubnub.Origin, pubnub.AuthenticationKey, Common.SubscribeKey
                                                                      );

            //http://pubsub.pubnub.com/subscribe/demo-36/test/0/21221?uuid=customuuid&state={"k":"v"}&auth=authKey&pnsdk=PubNub-CSharp-UnityIOS/3.6.9.0
            string expected = string.Format("http{0}://{1}/subscribe/{2}/{3}/0/{4}?uuid={5}{6}{7}{8}&pnsdk={9}",
                                            ssl?"s":"", pubnub.Origin, Common.SubscribeKey, string.Join(",", channels), timetoken.ToString(),
                                            uuid, (userState == "")?"":"&state=", userState, authKeyString, PubnubUnity.Version
                                            );
            string received = uri.ToString();

            Common.LogAndCompare(expected, received);
        }
Exemple #6
0
        public void TestBuildLeaveRequestCommon(string[] channels, bool ssl, string authKey)
        {
            string uuid = "customuuid";

            Pubnub pubnub = new Pubnub(
                Common.PublishKey,
                Common.SubscribeKey,
                "",
                "",
                ssl
                );

            pubnub.AuthenticationKey = authKey;
            string authKeyString = "";

            if (!string.IsNullOrEmpty(authKey))
            {
                authKeyString = string.Format("&auth={0}", pubnub.AuthenticationKey);
            }

            Uri uri = BuildRequests.BuildMultiChannelLeaveRequest(channels, uuid, ssl,
                                                                  pubnub.Origin, pubnub.AuthenticationKey, Common.SubscribeKey
                                                                  );

            //https://pubsub.pubnub.com/v2/presence/sub_key/demo-36/channel/test/leave?uuid=customuuid&auth=authKey&pnsdk=PubNub-CSharp-UnityIOS/3.6.9.0
            string expected = string.Format("http{0}://{1}/v2/presence/sub_key/{2}/channel/{3}/leave?uuid={4}{5}&pnsdk={6}",
                                            ssl?"s":"", pubnub.Origin, Common.SubscribeKey, string.Join(",", channels),
                                            uuid, authKeyString, PubnubUnity.Version
                                            );
            string received = uri.ToString();

            Common.LogAndCompare(expected, received);
        }
Exemple #7
0
        public void TestBuildHereNowRequestCommon(bool testCh, bool testCg, bool ssl, bool showUUIDList, bool includeUserState, string authKey)
        {
            string channel         = "here_now_channel";
            string channelGroup    = "here_now_channelGroup";
            string channelGroupStr = string.Format("&channel-group={0}", Utility.EncodeUricomponent(channelGroup, PNOperationType.PNHereNowOperation, true, false));

            if (testCh && testCg)
            {
                // test both
            }
            else if (testCg)
            {
                channel = ",";
            }
            else
            {
                channelGroup    = "";
                channelGroupStr = "";
            }
            string uuid = "customuuid";

            PNConfiguration pnConfiguration = new PNConfiguration();

            pnConfiguration.Origin           = EditorCommon.Origin;
            pnConfiguration.SubscribeKey     = EditorCommon.SubscribeKey;
            pnConfiguration.PublishKey       = EditorCommon.PublishKey;
            pnConfiguration.Secure           = ssl;
            pnConfiguration.CipherKey        = "enigma";
            pnConfiguration.LogVerbosity     = PNLogVerbosity.BODY;
            pnConfiguration.PresenceTimeout  = 60;
            pnConfiguration.PresenceInterval = 30;
            pnConfiguration.UUID             = uuid;
            pnConfiguration.AuthKey          = authKey;

            PubNubUnity pnUnity = new PubNubUnity(pnConfiguration, null, null);

            string authKeyString = "";

            if (!string.IsNullOrEmpty(authKey))
            {
                authKeyString = string.Format("&auth={0}", pnConfiguration.AuthKey);
            }

            int    disableUUID = (showUUIDList) ? 0 : 1;
            int    userState   = (includeUserState) ? 1 : 0;
            string parameters  = string.Format("disable_uuids={0}&state={1}", disableUUID, userState);

            Uri uri = BuildRequests.BuildHereNowRequest(channel, channelGroup, showUUIDList, includeUserState, pnUnity);

            //http://ps.pndsn.com/v2/presence/sub_key/demo/channel/here_now_channel?disable_uuids=1&state=0&uuid=customuuid&auth=authKey&pnsdk=PubNub-CSharp-UnityOSX/3.6.9.0
            string expected = string.Format("http{0}://{1}/v2/presence/sub_key/{2}/channel/{3}?{4}{8}&uuid={5}{6}&pnsdk={7}",
                                            ssl?"s":"", pnConfiguration.Origin, EditorCommon.SubscribeKey, channel, parameters,
                                            uuid, authKeyString,
                                            Utility.EncodeUricomponent(pnUnity.Version, PNOperationType.PNHereNowOperation, false, true),
                                            channelGroupStr
                                            );
            string received = uri.OriginalString;

            EditorCommon.LogAndCompare(expected, received);
        }
Exemple #8
0
        public void SetGetCoroutineParams <T>(string[] multiChannel, string url, CurrentRequestType crt, ResponseType respType,
                                              int timeout, bool resumeOnReconnect, bool isTimeout
                                              )
        {
            List <ChannelEntity> channelEntities = Helpers.CreateChannelEntity <T>(multiChannel,
                                                                                   true, false, null, null,
                                                                                   null, null, null, null);

            RequestState <T> pubnubRequestState = BuildRequests.BuildRequestState <T> (channelEntities, respType,
                                                                                       resumeOnReconnect, 0, isTimeout, 0, typeof(T));

            CoroutineParams <T> cp = new CoroutineParams <T> (url, timeout, 0, crt, typeof(T), pubnubRequestState);

            GameObject     go = new GameObject("PubnubUnitTestCoroutine");
            CoroutineClass cc = go.AddComponent <CoroutineClass> ();

            cc.SetCoroutineParams <T>(crt, cp);

            CoroutineParams <T> cp2 = cc.GetCoroutineParams <T>(crt) as CoroutineParams <T>;

            Assert.True(cp.crt.Equals(cp2.crt));
            Assert.True(cp.pause.Equals(cp2.pause));
            Assert.True(cp.timeout.Equals(cp2.timeout));
            Assert.True(cp.url.Equals(cp2.url));
        }
        public void TestBuildTimeRequestCommon(bool ssl)
        {
            string          uuid            = "customuuid";
            PNConfiguration pnConfiguration = new PNConfiguration();

            pnConfiguration.Origin           = EditorCommon.Origin;
            pnConfiguration.SubscribeKey     = EditorCommon.SubscribeKey;
            pnConfiguration.PublishKey       = EditorCommon.PublishKey;
            pnConfiguration.Secure           = ssl;
            pnConfiguration.CipherKey        = "enigma";
            pnConfiguration.LogVerbosity     = PNLogVerbosity.BODY;
            pnConfiguration.PresenceTimeout  = 60;
            pnConfiguration.PresenceInterval = 30;
            pnConfiguration.UUID             = uuid;

            PubNubUnity pnUnity = new PubNubUnity(pnConfiguration, null, null);

            Uri uri = BuildRequests.BuildTimeRequest(pnUnity);

            //https://ps.pndsn.com/time/0?uuid=customuuid&pnsdk=PubNub-CSharp-UnityIOS/3.6.9.0
            string expected = string.Format("http{0}://{1}/time/0?uuid={2}&pnsdk={3}",
                                            ssl?"s":"", pnConfiguration.Origin, uuid,
                                            Utility.EncodeUricomponent(pnUnity.Version, PNOperationType.PNTimeOperation, false, false)
                                            );
            string received = uri.OriginalString;

            EditorCommon.LogAndCompare(expected, received);
        }
Exemple #10
0
        public void TestBuildAddChannelsToChannelGroupRequestCommon(string[] channels, bool ssl, string authKey, bool sendQueryParams)
        {
            Dictionary <string, string> queryParams = new Dictionary <string, string>();
            string queryParamString = "";

            if (sendQueryParams)
            {
                queryParams.Add("d", "f");
                queryParamString = "&d=f";
            }
            else
            {
                queryParams = null;
            }

            string channelGroup = "channelGroup";
            string uuid         = "customuuid";

            PNConfiguration pnConfiguration = new PNConfiguration();

            pnConfiguration.Origin           = EditorCommon.Origin;
            pnConfiguration.SubscribeKey     = EditorCommon.SubscribeKey;
            pnConfiguration.PublishKey       = EditorCommon.PublishKey;
            pnConfiguration.Secure           = ssl;
            pnConfiguration.CipherKey        = "enigma";
            pnConfiguration.LogVerbosity     = PNLogVerbosity.BODY;
            pnConfiguration.PresenceTimeout  = 60;
            pnConfiguration.PresenceInterval = 30;
            pnConfiguration.AuthKey          = authKey;
            pnConfiguration.UUID             = uuid;

            PubNubUnity pnUnity = new PubNubUnity(pnConfiguration, null, null);

            pnConfiguration.AuthKey = authKey;
            string authKeyString = "";

            if (!string.IsNullOrEmpty(authKey))
            {
                authKeyString = string.Format("&auth={0}", pnConfiguration.AuthKey);
            }

            Uri uri = BuildRequests.BuildAddChannelsToChannelGroupRequest(channels, "", channelGroup,
                                                                          pnUnity, queryParams
                                                                          );

            string ch = string.Join(",", channels);

            //http://ps.pndsn.com/v1/channel-registration/sub-key/demo-36/channel-group/channelGroup?add=addChannel1,%20addChannel2&uuid=customuuid&auth=authKey&pnsdk=PubNub-CSharp-UnityOSX%2F3.7
            string expected = string.Format("http{0}://{1}/v1/channel-registration/sub-key/{2}/channel-group/{3}?add={4}&uuid={5}{6}&pnsdk={7}{8}",
                                            ssl?"s":"", pnConfiguration.Origin, EditorCommon.SubscribeKey, channelGroup,
                                            Utility.EncodeUricomponent(ch, PNOperationType.PNAddChannelsToGroupOperation, true, true),
                                            uuid, authKeyString,
                                            Utility.EncodeUricomponent(pnUnity.Version, PNOperationType.PNAddChannelsToGroupOperation, false, true),
                                            queryParamString
                                            );
            string received = uri.OriginalString;

            EditorCommon.LogAndCompare(expected, received);
        }
        public void TestBuildSetUserStateRequestCommon(bool testCg, bool testCh, bool ssl, string authKey)
        {
            string channel         = "user_state_channel";
            string userState       = "{\"k\":\"v\"}";
            string uuid            = "customuuid";
            string channelGroup    = "user_state_channelGroup";
            string channelGroupStr = string.Format("&channel-group={0}", Utility.EncodeUricomponent(channelGroup, PNOperationType.PNSetStateOperation, true, false));

            if (testCh && testCg)
            {
                // test both
            }
            else if (testCg)
            {
                channel = ",";
            }
            else
            {
                channelGroup    = "";
                channelGroupStr = "";
            }

            PNConfiguration pnConfiguration = new PNConfiguration();

            pnConfiguration.Origin           = EditorCommon.Origin;
            pnConfiguration.SubscribeKey     = EditorCommon.SubscribeKey;
            pnConfiguration.PublishKey       = EditorCommon.PublishKey;
            pnConfiguration.Secure           = ssl;
            pnConfiguration.CipherKey        = "enigma";
            pnConfiguration.LogVerbosity     = PNLogVerbosity.BODY;
            pnConfiguration.PresenceTimeout  = 60;
            pnConfiguration.PresenceInterval = 30;
            pnConfiguration.AuthKey          = authKey;
            pnConfiguration.UUID             = uuid;

            PubNubUnity pnUnity = new PubNubUnity(pnConfiguration, null, null);

            string authKeyString = "";

            if (!string.IsNullOrEmpty(authKey))
            {
                authKeyString = string.Format("&auth={0}", pnConfiguration.AuthKey);
            }

            Uri uri = BuildRequests.BuildSetStateRequest(channel, channelGroup, userState, uuid, pnUnity);

            //https://ps.pndsn.com/v2/presence/sub_key/demo-36/channel/user_state_channel/uuid/customuuid/data?state={"k":"v"}&uuid=customuuid&pnsdk=PubNub-CSharp-UnityIOS/3.6.9.0
            //https://ps.pndsn.com/v2/presence/sub_key/demo-36/channel/user_state_channel/uuid/customuuid/data?state={"k":"v"}&uuid=customuuid&auth=authKey&pnsdk=PubNub-CSharp-UnityIOS/3.6.9.0
            string expected = string.Format("http{0}://{1}/v2/presence/sub_key/{2}/channel/{3}/uuid/{4}/data?state={5}{9}&uuid={6}{7}&pnsdk={8}",
                                            ssl?"s":"", pnConfiguration.Origin, EditorCommon.SubscribeKey, channel, uuid,
                                            Utility.EncodeUricomponent(userState, PNOperationType.PNSetStateOperation, false, false),
                                            uuid, authKeyString,
                                            Utility.EncodeUricomponent(pnUnity.Version, PNOperationType.PNSetStateOperation, false, false),
                                            channelGroupStr
                                            );
            string received = uri.OriginalString;

            EditorCommon.LogAndCompare(expected, received);
        }
        public void TestBuildRegisterDevicePushRequestCommon(bool ssl, string authKey, string pushToken, PNPushType pushType, bool sendQueryParams)
        {
            string channel = "push_channel";
            string uuid    = "customuuid";
            Dictionary <string, string> queryParams = new Dictionary <string, string>();
            string queryParamString = "";

            if (sendQueryParams)
            {
                queryParams.Add("d", "f");
                queryParamString = "&d=f";
            }
            else
            {
                queryParams = null;
            }


            PNConfiguration pnConfiguration = new PNConfiguration();

            pnConfiguration.Origin           = EditorCommon.Origin;
            pnConfiguration.SubscribeKey     = EditorCommon.SubscribeKey;
            pnConfiguration.PublishKey       = EditorCommon.PublishKey;
            pnConfiguration.Secure           = ssl;
            pnConfiguration.CipherKey        = "enigma";
            pnConfiguration.LogVerbosity     = PNLogVerbosity.BODY;
            pnConfiguration.PresenceTimeout  = 60;
            pnConfiguration.PresenceInterval = 30;
            pnConfiguration.UUID             = uuid;
            pnConfiguration.AuthKey          = authKey;

            PubNubUnity pnUnity = new PubNubUnity(pnConfiguration, null, null);

            string authKeyString = "";

            if (!string.IsNullOrEmpty(authKey))
            {
                authKeyString = string.Format("&auth={0}", pnConfiguration.AuthKey);
            }

            Uri uri = BuildRequests.BuildRegisterDevicePushRequest(channel, pushType, pushToken, pnUnity, queryParams);

            //[1, "Modified Channels"]
            //https://ps.pndsn.com/v1/push/sub-key/demo-36/devices/pushToken?add=push_channel&type=apns&uuid=customuuid&pnsdk=PubNub-CSharp-UnityIOS/3.6.9.0
            string expected = string.Format("http{0}://{1}/v1/push/sub-key/{2}/devices/{3}?add={4}&type={5}&uuid={6}{7}&pnsdk={8}{9}",
                                            ssl?"s":"", pnConfiguration.Origin, EditorCommon.SubscribeKey, pushToken,
                                            Utility.EncodeUricomponent(channel, PNOperationType.PNAddPushNotificationsOnChannelsOperation, true, false), pushType.ToString().ToLower(),
                                            uuid, authKeyString,
                                            Utility.EncodeUricomponent(pnUnity.Version, PNOperationType.PNAddPushNotificationsOnChannelsOperation, false, true),
                                            queryParamString
                                            );
            string received = uri.OriginalString;

            UnityEngine.Debug.Log("exp:" + expected);
            UnityEngine.Debug.Log(received);
            EditorCommon.LogAndCompare(expected, received);
        }
Exemple #13
0
        public void TestSignalCommon(bool ssl, bool sendQueryParams)
        {
            string channel   = EditorCommon.GetRandomChannelName();
            string message   = "Test signal";
            string uuid      = "customuuid";
            string signature = "0";

            Dictionary <string, string> queryParams = new Dictionary <string, string>();
            string queryParamString = "";

            if (sendQueryParams)
            {
                queryParams.Add("d", "f");
                queryParamString = "&d=f";
            }
            else
            {
                queryParams = null;
            }

            PNConfiguration pnConfiguration = new PNConfiguration();

            pnConfiguration.Origin           = EditorCommon.Origin;
            pnConfiguration.SubscribeKey     = EditorCommon.SubscribeKey;
            pnConfiguration.PublishKey       = EditorCommon.PublishKey;
            pnConfiguration.CipherKey        = "enigma";
            pnConfiguration.Secure           = ssl;
            pnConfiguration.LogVerbosity     = PNLogVerbosity.BODY;
            pnConfiguration.PresenceTimeout  = 60;
            pnConfiguration.PresenceInterval = 30;
            pnConfiguration.UUID             = uuid;

            PubNubUnity pnUnity = new PubNubUnity(pnConfiguration, null, null);


            string originalMessage = Helpers.JsonEncodePublishMsg(message, "", pnUnity.JsonLibrary, new PNLoggingMethod(pnConfiguration.LogVerbosity));

            Uri uri = BuildRequests.BuildSignalRequest(channel, originalMessage, pnUnity, queryParams);

https:      //ps.pndsn.com/signal/demo/demo/0/UnityUnitTests_69/0/%22Test%20signal%22?uuid=customuuid&pnsdk=PubNub-CSharp-UnityOSX%2F4.3.0
            string expected = string.Format("http{0}://{1}/signal/{2}/{3}/{4}/{5}/0/{6}?uuid={7}&pnsdk={8}{9}",
                                            ssl?"s":"",
                                            pnConfiguration.Origin,
                                            EditorCommon.PublishKey,
                                            EditorCommon.SubscribeKey,
                                            signature,
                                            channel,
                                            Utility.EncodeUricomponent(originalMessage, PNOperationType.PNPublishOperation, false, false),
                                            uuid,
                                            Utility.EncodeUricomponent(pnUnity.Version, PNOperationType.PNPublishOperation, false, false),
                                            queryParamString
                                            );

            string received = uri.OriginalString;

            EditorCommon.LogAndCompare(expected, received);
        }
Exemple #14
0
        public void TestBuildHereNowRequestCommon(bool testCh, bool testCg, bool ssl, bool showUUIDList, bool includeUserState, string authKey)
        {
            string channel         = "here_now_channel";
            string channelGroup    = "here_now_channelGroup";
            string channelGroupStr = string.Format("&channel-group={0}", Utility.EncodeUricomponent(channelGroup, ResponseType.HereNow, true, false));

            if (testCh && testCg)
            {
                // test both
            }
            else if (testCg)
            {
                channel = ",";
            }
            else
            {
                channelGroup    = "";
                channelGroupStr = "";
            }
            string uuid = "customuuid";

            Pubnub pubnub = new Pubnub(
                Common.PublishKey,
                Common.SubscribeKey,
                "",
                "",
                ssl
                );

            pubnub.AuthenticationKey = authKey;
            string authKeyString = "";

            if (!string.IsNullOrEmpty(authKey))
            {
                authKeyString = string.Format("&auth={0}", pubnub.AuthenticationKey);
            }

            int    disableUUID = (showUUIDList) ? 0 : 1;
            int    userState   = (includeUserState) ? 1 : 0;
            string parameters  = string.Format("disable_uuids={0}&state={1}", disableUUID, userState);

            Uri uri = BuildRequests.BuildHereNowRequest(channel, channelGroup, showUUIDList, includeUserState,
                                                        uuid, ssl, pubnub.Origin, pubnub.AuthenticationKey, Common.SubscribeKey
                                                        );

            //http://ps.pndsn.com/v2/presence/sub_key/demo-36/channel/here_now_channel?disable_uuids=1&state=0&uuid=customuuid&auth=authKey&pnsdk=PubNub-CSharp-UnityOSX/3.6.9.0
            string expected = string.Format("http{0}://{1}/v2/presence/sub_key/{2}/channel/{3}?{4}{8}&uuid={5}{6}&pnsdk={7}",
                                            ssl?"s":"", pubnub.Origin, Common.SubscribeKey, channel, parameters,
                                            uuid, authKeyString,
                                            Utility.EncodeUricomponent(PubnubUnity.Version, ResponseType.HereNow, false, true),
                                            channelGroupStr
                                            );
            string received = uri.OriginalString;

            Common.LogAndCompare(expected, received);
        }
        public void TestBuildDetailedHistoryRequestCommon(bool ssl, bool reverse, bool includeTimetoken,
                                                          string authKey, long startTime, long endTime, int count)
        {
            string channel = "history_channel";
            string uuid    = "customuuid";

            Pubnub pubnub = new Pubnub(
                Common.PublishKey,
                Common.SubscribeKey,
                "",
                "",
                ssl
                );

            pubnub.AuthenticationKey = authKey;
            string authKeyString = "";

            if (!string.IsNullOrEmpty(authKey))
            {
                authKeyString = string.Format("&auth={0}", pubnub.AuthenticationKey);
            }

            string startTimeString = "";
            string endTimeString   = "";

            if (startTime != -1)
            {
                startTimeString = string.Format("&start={0}", startTime.ToString());
            }
            if (endTime != -1)
            {
                endTimeString = string.Format("&end={0}", endTime.ToString());
            }


            Uri uri = BuildRequests.BuildDetailedHistoryRequest(channel, startTime, endTime, count, reverse,
                                                                includeTimetoken, uuid, ssl, pubnub.Origin, pubnub.AuthenticationKey, Common.SubscribeKey
                                                                );

            if (count == -1)
            {
                count = 100;
            }
            //Received:http://ps.pndsn.com/v2/history/sub-key/demo-36/channel/history_channel?count=90&reverse=true&start=14498416434364941&end=14498416799269095&auth=authKey&uuid=customuuid&pnsdk=PubNub-CSharp-UnityOSX/3.6.9.0
            //Received:https://ps.pndsn.com/v2/history/sub-key/demo-36/channel/history_channel?count=90&include_token=true&start=14498416434364941&end=14498416799269095&auth=authKey&uuid=customuuid&pnsdk=PubNub-CSharp-UnityOSX/3.6.9.0
            //http://ps.pndsn.com/v2/history/sub-key/demo-36/channel/publish_channel?count=90&start=14498416434364941&end=14498416799269095&auth=authKey&uuid=customuuid&pnsdk=PubNub-CSharp-UnityOSX/3.6.9.0
            string expected = string.Format("http{0}://{1}/v2/history/sub-key/{2}/channel/{3}?count={4}{5}{6}{7}{8}{9}&uuid={10}&pnsdk={11}",
                                            ssl?"s":"", pubnub.Origin, Common.SubscribeKey, channel, count,
                                            includeTimetoken?"&include_token=true":"", reverse?"&reverse=true":"",
                                            startTimeString, endTimeString, authKeyString, uuid,
                                            Utility.EncodeUricomponent(PubnubUnity.Version, ResponseType.DetailedHistory, false, true)
                                            );
            string received = uri.OriginalString;

            Common.LogAndCompare(expected, received);
        }
Exemple #16
0
        public void TestBuildPublishRequestCommon(bool ssl, bool storeInHistory, string secretKey,
                                                  string cipherKey, string authKey)
        {
            string channel   = "publish_channel";
            string message   = "Test message";
            string uuid      = "customuuid";
            string signature = "0";
            Pubnub pubnub    = new Pubnub(
                Common.PublishKey,
                Common.SubscribeKey,
                secretKey,
                cipherKey,
                ssl
                );

            pubnub.AuthenticationKey = authKey;
            string authKeyString = "";

            if (!string.IsNullOrEmpty(authKey))
            {
                authKeyString = string.Format("&auth={0}", pubnub.AuthenticationKey);
            }
            string originalMessage = Helpers.JsonEncodePublishMsg(message, cipherKey, pubnub.JsonPluggableLibrary);

            if (secretKey.Length > 0)
            {
                StringBuilder stringToSign = new StringBuilder();
                stringToSign
                .Append(Common.PublishKey)
                .Append('/')
                .Append(Common.SubscribeKey)
                .Append('/')
                .Append(secretKey)
                .Append('/')
                .Append(channel)
                .Append('/')
                .Append(originalMessage);      // 1

                // Sign Message
                signature = Utility.Md5(stringToSign.ToString());
            }

            Uri uri = BuildRequests.BuildPublishRequest(channel, originalMessage, storeInHistory, uuid, ssl,
                                                        pubnub.Origin, pubnub.AuthenticationKey, Common.PublishKey, Common.SubscribeKey,
                                                        cipherKey, secretKey
                                                        );

            //http://pubsub.pubnub.com/publish/demo-36/demo-36/0/publish_channel/0?uuid=customuuid&auth=authKey&pnsdk=PubNub-CSharp-UnityOSX/3.6.9.0
            string expected = string.Format("http{0}://{1}/publish/{2}/{3}/{4}/{5}/0/{6}?uuid={7}{8}{9}&pnsdk={10}",
                                            ssl?"s":"", pubnub.Origin, Common.PublishKey, Common.SubscribeKey, signature, channel, originalMessage,
                                            uuid, storeInHistory?"":"&store=0", authKeyString, PubnubUnity.Version
                                            );
            string received = uri.ToString();

            Common.LogAndCompare(expected, received);
        }
Exemple #17
0
        public void TestBuildLeaveRequestCommon(string[] channels, string[] channelGroups, bool ssl, string authKey)
        {
            string          uuid            = "customuuid";
            PNConfiguration pnConfiguration = new PNConfiguration();

            pnConfiguration.Origin       = EditorCommon.Origin;
            pnConfiguration.SubscribeKey = EditorCommon.SubscribeKey;
            pnConfiguration.PublishKey   = EditorCommon.PublishKey;
            pnConfiguration.Secure       = ssl;
            pnConfiguration.CipherKey    = "enigma";
            pnConfiguration.LogVerbosity = PNLogVerbosity.BODY;

            pnConfiguration.AuthKey = authKey;
            pnConfiguration.UUID    = uuid;


            PubNubUnity pnUnity = new PubNubUnity(pnConfiguration, null, null);

            string authKeyString = "";

            if (!string.IsNullOrEmpty(authKey))
            {
                authKeyString = string.Format("&auth={0}", pnConfiguration.AuthKey);
            }

            string cgStr = "";
            string cg    = "";

            if (channelGroups != null)
            {
                cg    = string.Join(",", channelGroups);
                cgStr = string.Format("&channel-group={0}", Utility.EncodeUricomponent(cg, PNOperationType.PNLeaveOperation, true, false));
            }

            string chStr = ",";
            string ch    = "";

            if (channels != null)
            {
                ch    = string.Join(",", channels);
                chStr = ch;
            }

            Uri uri = BuildRequests.BuildLeaveRequest(ch, cg, pnUnity);

            //https://ps.pndsn.com/v2/presence/sub_key/demo-36/channel/test/leave?uuid=customuuid&auth=authKey&pnsdk=PubNub-CSharp-UnityIOS/3.6.9.0
            string expected = string.Format("http{0}://{1}/v2/presence/sub_key/{2}/channel/{3}/leave?uuid={4}{7}{5}&pnsdk={6}",
                                            ssl?"s":"", pnConfiguration.Origin, EditorCommon.SubscribeKey, chStr,
                                            uuid, authKeyString, Utility.EncodeUricomponent(pnUnity.Version, PNOperationType.PNLeaveOperation, false, true),
                                            cgStr
                                            );
            string received = uri.OriginalString;

            EditorCommon.LogAndCompare(expected, received);
        }
        public void TestBuildGlobalHereNowRequestCommon(bool ssl, bool showUUIDList, bool includeUserState, string authKey, bool sendQueryParams)
        {
            Dictionary <string, string> queryParams = new Dictionary <string, string>();
            string queryParamString = "";

            if (sendQueryParams)
            {
                queryParams.Add("d", "f");
                queryParamString = "&d=f";
            }
            else
            {
                queryParams = null;
            }
            string uuid = "customuuid";

            PNConfiguration pnConfiguration = new PNConfiguration();

            pnConfiguration.Origin           = EditorCommon.Origin;
            pnConfiguration.SubscribeKey     = EditorCommon.SubscribeKey;
            pnConfiguration.PublishKey       = EditorCommon.PublishKey;
            pnConfiguration.Secure           = ssl;
            pnConfiguration.CipherKey        = "enigma";
            pnConfiguration.LogVerbosity     = PNLogVerbosity.BODY;
            pnConfiguration.PresenceTimeout  = 60;
            pnConfiguration.PresenceInterval = 30;
            pnConfiguration.UUID             = uuid;
            pnConfiguration.AuthKey          = authKey;

            PubNubUnity pnUnity = new PubNubUnity(pnConfiguration, null, null);

            string authKeyString = "";

            if (!string.IsNullOrEmpty(authKey))
            {
                authKeyString = string.Format("&auth={0}", pnConfiguration.AuthKey);
            }

            int    disableUUID = (showUUIDList) ? 0 : 1;
            int    userState   = (includeUserState) ? 1 : 0;
            string parameters  = string.Format("disable_uuids={0}&state={1}", disableUUID, userState);

            Uri uri = BuildRequests.BuildHereNowRequest("", "", showUUIDList, includeUserState, pnUnity, queryParams);

            //http://ps.pndsn.com/v2/presence/sub_key/demo?disable_uuids=1&state=0&uuid=customuuid&auth=authKey&pnsdk=PubNub-CSharp-UnityOSX/3.6.9.0
            string expected = string.Format("http{0}://{1}/v2/presence/sub_key/{2}?{3}&uuid={4}{5}&pnsdk={6}{7}",
                                            ssl?"s":"", pnConfiguration.Origin, EditorCommon.SubscribeKey, parameters,
                                            uuid, authKeyString,
                                            Utility.EncodeUricomponent(pnUnity.Version, PNOperationType.PNHereNowOperation, false, true),
                                            queryParamString
                                            );
            string received = uri.OriginalString;

            EditorCommon.LogAndCompare(expected, received);
        }
Exemple #19
0
        //remove channels
        //remove cg
        public void TestBuildRemoveChannelsFromChannelGroupRequestCommon(string[] channels, bool ssl, string authKey)
        {
            string channelGroup = "channelGroup";
            string uuid         = "customuuid";

            PNConfiguration pnConfiguration = new PNConfiguration();

            pnConfiguration.Origin           = EditorCommon.Origin;
            pnConfiguration.SubscribeKey     = EditorCommon.SubscribeKey;
            pnConfiguration.PublishKey       = EditorCommon.PublishKey;
            pnConfiguration.Secure           = ssl;
            pnConfiguration.CipherKey        = "enigma";
            pnConfiguration.LogVerbosity     = PNLogVerbosity.BODY;
            pnConfiguration.PresenceTimeout  = 60;
            pnConfiguration.PresenceInterval = 30;
            pnConfiguration.AuthKey          = authKey;
            pnConfiguration.UUID             = uuid;

            PubNubUnity pnUnity = new PubNubUnity(pnConfiguration, null, null);

            pnConfiguration.AuthKey = authKey;
            string authKeyString = "";

            if (!string.IsNullOrEmpty(authKey))
            {
                authKeyString = string.Format("&auth={0}", pnConfiguration.AuthKey);
            }

            Uri uri = BuildRequests.BuildRemoveChannelsFromChannelGroupRequest(channels, "", channelGroup,
                                                                               pnUnity
                                                                               );

            string ch     = "";
            string chStr  = "";
            string chStr2 = "/remove";

            if (channels != null && channels.Length > 0)
            {
                ch     = string.Join(",", channels);
                chStr  = string.Format("remove={0}&", Utility.EncodeUricomponent(ch, PNOperationType.PNRemoveChannelsFromGroupOperation, true, false));
                chStr2 = "";
            }

            //http://ps.pndsn.com/v1/channel-registration/sub-key/demo-36/channel-group/channelGroup?add=addChannel1,%20addChannel2&uuid=customuuid&auth=authKey&pnsdk=PubNub-CSharp-UnityOSX%2F3.7
            string expected = string.Format("http{0}://{1}/v1/channel-registration/sub-key/{2}/channel-group/{3}{8}?{4}uuid={5}{6}&pnsdk={7}",
                                            ssl?"s":"", pnConfiguration.Origin, EditorCommon.SubscribeKey, channelGroup,
                                            chStr, uuid, authKeyString,
                                            Utility.EncodeUricomponent(pnUnity.Version, PNOperationType.PNRemoveChannelsFromGroupOperation, false, true),
                                            chStr2

                                            );
            string received = uri.OriginalString;

            EditorCommon.LogAndCompare(expected, received);
        }
        public void TestGetMessageActionsCommon(bool ssl, bool sendQueryParams, long start, long end, int limit)
        {
            string uuid = "customuuid";

            Dictionary <string, string> queryParams = new Dictionary <string, string>();
            string queryParamString = "";

            if (sendQueryParams)
            {
                queryParams.Add("d", "f");
                queryParamString = "&d=f";
            }
            else
            {
                queryParams = null;
            }

            PNConfiguration pnConfiguration = new PNConfiguration();

            pnConfiguration.Origin           = EditorCommon.Origin;
            pnConfiguration.SubscribeKey     = EditorCommon.SubscribeKey;
            pnConfiguration.PublishKey       = EditorCommon.PublishKey;
            pnConfiguration.CipherKey        = "enigma";
            pnConfiguration.Secure           = ssl;
            pnConfiguration.LogVerbosity     = PNLogVerbosity.BODY;
            pnConfiguration.PresenceTimeout  = 60;
            pnConfiguration.PresenceInterval = 30;
            pnConfiguration.UUID             = uuid;

            PubNubUnity pnUnity     = new PubNubUnity(pnConfiguration, null, null);
            string      channelName = "message_actions_channel";
            string      tt          = "15742286266685611";
            string      att         = "15742286266685611";

            Uri uri = BuildRequests.BuildGetMessageActionsRequest(channelName, start, end, limit, pnUnity, queryParams);

            //https://ps.pndsn.com/v1/message-actions/demo/channel/message_actions_channel?uuid=customuuid&limit=10&start=15742286266685611&end=15742286266685611&pnsdk=PubNub-CSharp-UnityOSX%2F4.5.0
            string expected = string.Format("http{0}://{1}/v1/message-actions/{2}/channel/message_actions_channel?uuid={3}{6}{7}{8}&pnsdk={4}{5}",
                                            ssl?"s":"",
                                            pnConfiguration.Origin,
                                            EditorCommon.SubscribeKey,
                                            uuid,
                                            Utility.EncodeUricomponent(pnUnity.Version, PNOperationType.PNPublishOperation, false, false),
                                            queryParamString,
                                            limit > 0?"&limit=" + limit.ToString():"",
                                            start > 0?"&start=" + start.ToString():"",
                                            end > 0?"&end=" + end.ToString():""
                                            );

            string received = uri.OriginalString;

            EditorCommon.LogAndCompare(expected, received);
        }
Exemple #21
0
        public void TestBuildGrantRequestCommon(string channel, bool ssl, bool read, bool write, int ttl,
                                                string cipherKey, string authKey)
        {
            string uuid   = "customuuid";
            Pubnub pubnub = new Pubnub(
                Common.PublishKey,
                Common.SubscribeKey,
                "",
                "",
                ssl
                );
            Uri uri = BuildRequests.BuildGrantAccessRequest(channel, read, write, ttl, uuid, ssl, pubnub.Origin,
                                                            authKey, Common.PublishKey, Common.SubscribeKey, cipherKey, Common.SecretKey
                                                            );

            //https://pubsub.pubnub.com/v1/auth/grant/sub-key/demo-36?signature=RlJ5QMGPMxNj9C2J6emNaXUymQ8pbsUM3y8_Wz25Zdg=&channel=access_manager_channel&pnsdk=PubNub-CSharp-UnityIOS/3.6.9.0&r=1&timestamp=1450074813&ttl=10&uuid=customuuid&w=1
            string expected1 = string.Format("http{0}://{1}/v1/auth/grant/sub-key/{2}?signature=",
                                             ssl ? "s" : "", pubnub.Origin, Common.SubscribeKey);

            string expected2 = string.Format("{0}{1}&pnsdk={2}&r={3}&timestamp=",
                                             (channel == "")?"":"&channel=", channel,
                                             Utility.EncodeUricomponent(PubnubUnity.Version, ResponseType.GrantAccess, false, true),
                                             Convert.ToInt32(read).ToString());

            string expected3 = string.Format("&ttl={0}&uuid={1}&w={2}",
                                             ttl, uuid, Convert.ToInt32(write).ToString()
                                             );

            string received = uri.OriginalString;

            UnityEngine.Debug.Log("Expected:" + expected1);
            UnityEngine.Debug.Log("Expected:" + expected2);
            UnityEngine.Debug.Log("Expected:" + expected3);
            UnityEngine.Debug.Log("Received:" + received);

            if (!received.Contains(expected1))
            {
                Assert.Fail("expected1 doesn't match");
            }
            if (!received.Contains(expected2))
            {
                Assert.Fail("expected2 doesn't match");
            }
            if (!received.Contains(expected3))
            {
                Assert.Fail("expected3 doesn't match");
            }

            Assert.IsTrue(true);
        }
Exemple #22
0
        public void TestBuildWhereNowRequestCommon(bool ssl, string authKey, string uuid, bool sendQueryParams)
        {
            string sessionUUID = "customuuid";
            Dictionary <string, string> queryParams = new Dictionary <string, string>();
            string queryParamString = "";

            if (sendQueryParams)
            {
                queryParams.Add("d", "f");
                queryParamString = "&d=f";
            }
            else
            {
                queryParams = null;
            }
            PNConfiguration pnConfiguration = new PNConfiguration();

            pnConfiguration.Origin           = EditorCommon.Origin;
            pnConfiguration.SubscribeKey     = EditorCommon.SubscribeKey;
            pnConfiguration.PublishKey       = EditorCommon.PublishKey;
            pnConfiguration.Secure           = ssl;
            pnConfiguration.CipherKey        = "enigma";
            pnConfiguration.LogVerbosity     = PNLogVerbosity.BODY;
            pnConfiguration.PresenceTimeout  = 60;
            pnConfiguration.PresenceInterval = 30;
            pnConfiguration.UUID             = sessionUUID;
            pnConfiguration.AuthKey          = authKey;

            PubNubUnity pnUnity = new PubNubUnity(pnConfiguration, null, null);

            string authKeyString = "";

            if (!string.IsNullOrEmpty(authKey))
            {
                authKeyString = string.Format("&auth={0}", pnConfiguration.AuthKey);
            }

            Uri uri = BuildRequests.BuildWhereNowRequest(uuid, pnUnity, queryParams);

            //http://ps.pndsn.com/v2/presence/sub_key/demo-36/uuid/customuuid?uuid=&auth=authKey&pnsdk=PubNub-CSharp-UnityIOS/3.6.9.0
            string expected = string.Format("http{0}://{1}/v2/presence/sub_key/{2}/uuid/{3}?uuid={4}{5}&pnsdk={6}{7}",
                                            ssl?"s":"", pnConfiguration.Origin, EditorCommon.SubscribeKey, uuid, sessionUUID,
                                            authKeyString,
                                            Utility.EncodeUricomponent(pnUnity.Version, PNOperationType.PNWhereNowOperation, false, false),
                                            queryParamString
                                            );
            string received = uri.OriginalString;

            EditorCommon.LogAndCompare(expected, received);
        }
Exemple #23
0
        //remove channels
        //remove cg
        public void TestBuildRemoveChannelsFromChannelGroupRequestCommon(string[] channels, bool ssl, string authKey)
        {
            string channelGroup = "channelGroup";
            string uuid         = "customuuid";

            Pubnub pubnub = new Pubnub(
                Common.PublishKey,
                Common.SubscribeKey,
                "",
                "",
                ssl


                );

            pubnub.AuthenticationKey = authKey;
            string authKeyString = "";

            if (!string.IsNullOrEmpty(authKey))
            {
                authKeyString = string.Format("&auth={0}", pubnub.AuthenticationKey);
            }

            Uri uri = BuildRequests.BuildRemoveChannelsFromChannelGroupRequest(channels, "", channelGroup,
                                                                               uuid, ssl, pubnub.Origin, pubnub.AuthenticationKey, Common.SubscribeKey
                                                                               );

            string ch     = "";
            string chStr  = "";
            string chStr2 = "/remove";

            if (channels != null && channels.Length > 0)
            {
                ch     = string.Join(",", channels);
                chStr  = string.Format("remove={0}&", Utility.EncodeUricomponent(ch, ResponseType.ChannelGroupRemove, true, false));
                chStr2 = "";
            }

            //http://pubsub.pubnub.com/v1/channel-registration/sub-key/demo-36/channel-group/channelGroup?add=addChannel1,%20addChannel2&uuid=customuuid&auth=authKey&pnsdk=PubNub-CSharp-UnityOSX%2F3.7
            string expected = string.Format("http{0}://{1}/v1/channel-registration/sub-key/{2}/channel-group/{3}{8}?{4}uuid={5}{6}&pnsdk={7}",
                                            ssl?"s":"", pubnub.Origin, Common.SubscribeKey, channelGroup,
                                            chStr, uuid, authKeyString,
                                            Utility.EncodeUricomponent(PubnubUnity.Version, ResponseType.ChannelGroupRemove, false, true),
                                            chStr2

                                            );
            string received = uri.OriginalString;

            Common.LogAndCompare(expected, received);
        }
Exemple #24
0
        public void TestBuildAuditRequestCommon(string channel, bool ssl, string cipherKey, string authKey)
        {
            string uuid   = "customuuid";
            Pubnub pubnub = new Pubnub(
                Common.PublishKey,
                Common.SubscribeKey,
                "",
                "",
                ssl
                );
            Uri uri = BuildRequests.BuildAuditAccessRequest(channel, uuid, ssl, pubnub.Origin,
                                                            authKey, Common.PublishKey, Common.SubscribeKey, cipherKey, Common.SecretKey
                                                            );

            //http://pubsub.pubnub.com/v1/auth/audit/sub-key/demo-36?signature=z3fwOXFHyyaSfEbt8QwAvVzCviLgxxefRmPMDv7Ipns=&channel=access_manager_channel&pnsdk=PubNub-CSharp-UnityIOS/3.6.9.0&timestamp=1450102082&uuid=customuuid
            string expected1 = string.Format("http{0}://{1}/v1/auth/audit/sub-key/{2}?signature=",
                                             ssl ? "s" : "", pubnub.Origin, Common.SubscribeKey);

            string expected2 = string.Format("{0}{1}&pnsdk={2}&timestamp=",
                                             (channel == "")?"":"&channel=", channel,
                                             Utility.EncodeUricomponent(PubnubUnity.Version, ResponseType.AuditAccess, false, true));

            string expected3 = string.Format("&uuid={0}", uuid);

            string received = uri.OriginalString;

            UnityEngine.Debug.Log("Expected:" + expected1);
            UnityEngine.Debug.Log("Expected:" + expected2);
            UnityEngine.Debug.Log("Expected:" + expected3);
            UnityEngine.Debug.Log("Received:" + received);

            if (!received.Contains(expected1))
            {
                Assert.Fail("expected1 doesn't match");
            }
            if (!received.Contains(expected2))
            {
                Assert.Fail("expected2 doesn't match");
            }
            if (!received.Contains(expected3))
            {
                Assert.Fail("expected3 doesn't match");
            }

            Assert.IsTrue(true);
        }
Exemple #25
0
        //GetChannels
        //Get All CG
        public void TestBuildGetChannelsForChannelGroupRequestCommon(bool allCg,
                                                                     bool ssl, string authKey)
        {
            string channelGroup    = "channelGroup";
            string channelGroupStr = "channel-group/";

            if (allCg)
            {
                channelGroup    = "";
                channelGroupStr = "channel-group";
            }
            string uuid = "customuuid";

            Pubnub pubnub = new Pubnub(
                Common.PublishKey,
                Common.SubscribeKey,
                "",
                "",
                ssl
                );

            pubnub.AuthenticationKey = authKey;
            string authKeyString = "";

            if (!string.IsNullOrEmpty(authKey))
            {
                authKeyString = string.Format("&auth={0}", pubnub.AuthenticationKey);
            }

            Uri uri = BuildRequests.BuildGetChannelsForChannelGroupRequest("", channelGroup, allCg,
                                                                           uuid, ssl, pubnub.Origin, pubnub.AuthenticationKey, Common.SubscribeKey
                                                                           );

            //http://pubsub.pubnub.com/v1/channel-registration/sub-key/demo-36/channel-group/channelGroup?add=addChannel1,%20addChannel2&uuid=customuuid&auth=authKey&pnsdk=PubNub-CSharp-UnityOSX%2F3.7
            string expected = string.Format("http{0}://{1}/v1/channel-registration/sub-key/{2}/{8}{3}?uuid={5}{6}&pnsdk={7}",
                                            ssl?"s":"", pubnub.Origin, Common.SubscribeKey, channelGroup,
                                            "",
                                            uuid, authKeyString,
                                            Utility.EncodeUricomponent(PubnubUnity.Version, ResponseType.ChannelGroupGet, false, true),
                                            channelGroupStr

                                            );
            string received = uri.OriginalString;

            Common.LogAndCompare(expected, received);
        }
Exemple #26
0
        public void TestBuildGetChannelsPushRequestCommon(bool ssl, string authKey, string pushToken, PNPushType pushType)
        {
            string uuid = "customuuid";

            PNConfiguration pnConfiguration = new PNConfiguration();

            pnConfiguration.Origin           = EditorCommon.Origin;
            pnConfiguration.SubscribeKey     = EditorCommon.SubscribeKey;
            pnConfiguration.PublishKey       = EditorCommon.PublishKey;
            pnConfiguration.Secure           = ssl;
            pnConfiguration.CipherKey        = "enigma";
            pnConfiguration.LogVerbosity     = PNLogVerbosity.BODY;
            pnConfiguration.PresenceTimeout  = 60;
            pnConfiguration.PresenceInterval = 30;
            pnConfiguration.UUID             = uuid;
            pnConfiguration.AuthKey          = authKey;

            PubNubUnity pnUnity = new PubNubUnity(pnConfiguration, null, null);

            string authKeyString = "";

            if (!string.IsNullOrEmpty(authKey))
            {
                authKeyString = string.Format("&auth={0}", pnConfiguration.AuthKey);
            }

            Uri uri = BuildRequests.BuildGetChannelsPushRequest(pushType, pushToken, pnUnity);

            //[1, "Modified Channels"]
            //["push_channel"]
            //https://ps.pndsn.com/v1/push/sub-key/demo-36/devices/pushToken?type=wns&uuid=customuuid&auth=authKey&pnsdk=PubNub-CSharp-UnityIOS/3.6.9.0
            //https://ps.pndsn.com/v1/push/sub-key/demo-36/devices/pushToken?type=mpns&uuid=customuuid&auth=authKey&pnsdk=PubNub-CSharp-UnityIOS/3.6.9.0
            string expected = string.Format("http{0}://{1}/v1/push/sub-key/{2}/devices/{3}?type={4}&uuid={5}{6}&pnsdk={7}",
                                            ssl?"s":"", pnConfiguration.Origin, EditorCommon.SubscribeKey, pushToken,
                                            pushType.ToString().ToLower(),
                                            uuid, authKeyString,
                                            Utility.EncodeUricomponent(pnUnity.Version, PNOperationType.PNPushNotificationEnabledChannelsOperation, false, true)
                                            );
            string received = uri.OriginalString;

            UnityEngine.Debug.Log("exp:" + expected);
            UnityEngine.Debug.Log(received);
            EditorCommon.LogAndCompare(expected, received);
        }
        public void TestBuildTimeRequestCommon(bool ssl){
            string uuid = "customuuid";
            Pubnub pubnub = new Pubnub (
                Common.PublishKey,
                Common.SubscribeKey,
                "",
                "",
                ssl
            );
            Uri uri = BuildRequests.BuildTimeRequest (uuid, ssl, pubnub.Origin);

            //https://pubsub.pubnub.com/time/0?uuid=customuuid&pnsdk=PubNub-CSharp-UnityIOS/3.6.9.0
            string expected = string.Format ("http{0}://{1}/time/0?uuid={2}&pnsdk={3}",
                ssl?"s":"", pubnub.Origin, uuid, 
                Utility.EncodeUricomponent(PubnubUnity.Version, ResponseType.Time, false, false)
            );
            string received = uri.OriginalString;
            Common.LogAndCompare (expected, received);
        }
Exemple #28
0
        public void TestBuildGetChannelsPushRequestCommon(bool ssl, string authKey, string pushToken, PushTypeService pushType)
        {
            string uuid = "customuuid";

            Pubnub pubnub = new Pubnub(
                Common.PublishKey,
                Common.SubscribeKey,
                "",
                "",
                ssl
                );

            pubnub.AuthenticationKey = authKey;
            string authKeyString = "";

            if (!string.IsNullOrEmpty(authKey))
            {
                authKeyString = string.Format("&auth={0}", pubnub.AuthenticationKey);
            }

            Uri uri = BuildRequests.BuildGetChannelsPushRequest(pushType, pushToken, uuid, ssl,
                                                                pubnub.Origin, pubnub.AuthenticationKey, Common.SubscribeKey
                                                                );

            //[1, "Modified Channels"]
            //["push_channel"]
            //https://pubsub.pubnub.com/v1/push/sub-key/demo-36/devices/pushToken?type=wns&uuid=customuuid&auth=authKey&pnsdk=PubNub-CSharp-UnityIOS/3.6.9.0
            //https://pubsub.pubnub.com/v1/push/sub-key/demo-36/devices/pushToken?type=mpns&uuid=customuuid&auth=authKey&pnsdk=PubNub-CSharp-UnityIOS/3.6.9.0
            string expected = string.Format("http{0}://{1}/v1/push/sub-key/{2}/devices/{3}?type={4}&uuid={5}{6}&pnsdk={7}",
                                            ssl?"s":"", pubnub.Origin, Common.SubscribeKey, pushToken,
                                            pushType.ToString().ToLower(),
                                            uuid, authKeyString, PubnubUnity.Version
                                            );
            string received = uri.ToString();

            UnityEngine.Debug.Log("exp:" + expected);
            UnityEngine.Debug.Log(received);
            Common.LogAndCompare(expected, received);
        }
        public void TestBuildHereNowRequestCommon(bool ssl, bool showUUIDList, bool includeUserState, string authKey)
        {
            string channel = "here_now_channel";
            string uuid    = "customuuid";

            Pubnub pubnub = new Pubnub(
                Common.PublishKey,
                Common.SubscribeKey,
                "",
                "",
                ssl
                );

            pubnub.AuthenticationKey = authKey;
            string authKeyString = "";

            if (!string.IsNullOrEmpty(authKey))
            {
                authKeyString = string.Format("&auth={0}", pubnub.AuthenticationKey);
            }

            int    disableUUID = (showUUIDList) ? 0 : 1;
            int    userState   = (includeUserState) ? 1 : 0;
            string parameters  = string.Format("disable_uuids={0}&state={1}", disableUUID, userState);

            Uri uri = BuildRequests.BuildHereNowRequest(channel, showUUIDList, includeUserState,
                                                        uuid, ssl, pubnub.Origin, pubnub.AuthenticationKey, Common.SubscribeKey
                                                        );

            //http://pubsub.pubnub.com/v2/presence/sub_key/demo-36/channel/here_now_channel?disable_uuids=1&state=0&uuid=customuuid&auth=authKey&pnsdk=PubNub-CSharp-UnityOSX/3.6.9.0
            string expected = string.Format("http{0}://{1}/v2/presence/sub_key/{2}/channel/{3}?{4}&uuid={5}{6}&pnsdk={7}",
                                            ssl?"s":"", pubnub.Origin, Common.SubscribeKey, channel, parameters,
                                            uuid, authKeyString, PubnubUnity.Version
                                            );
            string received = uri.ToString();

            Common.LogAndCompare(expected, received);
        }
        public void TestBuildPublishRequestCommonWithTTL(bool sendMeta, bool ssl, bool storeInHistory, string secretKey, string cipherKey, string authKey, int ttl, bool replicate)
        {
            string channel   = "publish_channel";
            string message   = "Test message";
            string uuid      = "customuuid";
            string signature = "0";

            PNConfiguration pnConfiguration = new PNConfiguration();

            pnConfiguration.Origin           = EditorCommon.Origin;
            pnConfiguration.SubscribeKey     = EditorCommon.SubscribeKey;
            pnConfiguration.PublishKey       = EditorCommon.PublishKey;
            pnConfiguration.SecretKey        = secretKey;
            pnConfiguration.Secure           = ssl;
            pnConfiguration.CipherKey        = "enigma";
            pnConfiguration.LogVerbosity     = PNLogVerbosity.BODY;
            pnConfiguration.PresenceTimeout  = 60;
            pnConfiguration.PresenceInterval = 30;
            pnConfiguration.AuthKey          = authKey;
            pnConfiguration.UUID             = uuid;

            PubNubUnity pnUnity = new PubNubUnity(pnConfiguration, null, null);

            string authKeyString = "";

            if (!string.IsNullOrEmpty(authKey))
            {
                authKeyString = string.Format("&auth={0}", pnConfiguration.AuthKey);
            }

            string meta     = "";
            string metadata = "{\"region\":\"east\"}";

            if (sendMeta)
            {
                meta = string.Format("&meta={0}", Utility.EncodeUricomponent(metadata, PNOperationType.PNPublishOperation, false, false));
            }
            else
            {
                metadata = "";
            }

            string originalMessage = Helpers.JsonEncodePublishMsg(message, cipherKey, pnUnity.JsonLibrary, new PNLoggingMethod(pnConfiguration.LogVerbosity));

            if (secretKey.Length > 0)
            {
                StringBuilder stringToSign = new StringBuilder();
                stringToSign
                .Append(EditorCommon.PublishKey)
                .Append('/')
                .Append(EditorCommon.SubscribeKey)
                .Append('/')
                .Append(secretKey)
                .Append('/')
                .Append(channel)
                .Append('/')
                .Append(originalMessage);      // 1

                // Sign Message
                //signature = Utility.Md5 (stringToSign.ToString ());
                PubnubCrypto pnCrypto = new PubnubCrypto(cipherKey, new PNLoggingMethod(PNLogVerbosity.BODY));
                signature = pnCrypto.ComputeHashRaw(stringToSign.ToString());
            }

            Uri uri = BuildRequests.BuildPublishRequest(channel, originalMessage, storeInHistory, metadata, 0, ttl, false, replicate, pnUnity);

            string ttlStr = (ttl == -1) ? "" : string.Format("&ttl={0}", ttl.ToString());

            //http://ps.pndsn.com/publish/demo-36/demo-36/0/publish_channel/0?uuid=customuuid&auth=authKey&pnsdk=PubNub-CSharp-UnityOSX/3.6.9.0
            string expected = string.Format("http{0}://{1}/publish/{2}/{3}/{4}/{5}/0/{6}?uuid={7}&seqn=0{8}{12}{13}{11}{9}&pnsdk={10}",
                                            ssl?"s":"", pnConfiguration.Origin, EditorCommon.PublishKey, EditorCommon.SubscribeKey, signature, channel,
                                            Utility.EncodeUricomponent(originalMessage, PNOperationType.PNPublishOperation, false, false),
                                            uuid, storeInHistory?"":"&store=0", authKeyString,
                                            Utility.EncodeUricomponent(pnUnity.Version, PNOperationType.PNPublishOperation, false, false),
                                            meta,
                                            ttlStr,
                                            replicate?"":"&norep=true"
                                            );

            string received = uri.OriginalString;

            EditorCommon.LogAndCompare(expected, received);
        }