예제 #1
0
        public void RunAssertions(PubNubUnity pnUnity,
                                  string compiledUserStateA,
                                  bool connectCallbackSentA, bool hasChannelGroupsA, bool hasChannelA,
                                  bool hasChannelsOrChannelGroupsA, bool hasPresenceChannelsA, int currentSubscribedChannelGroupsCountA,
                                  int currentSubscribedChannelsCountA, string[] allChannelGroupsA, string[] allChannelsA,
                                  string[] allNonPresenceChannelsOrChannelGroupsA, string[] allPresenceChannelsOrChannelGroupsA,
                                  string[] channelsAndChannelGroupsAwaitingConnectCallbackA, string[] allSubscribedChannelsAndChannelGroupsA

                                  )
        {
            List <ChannelEntity> allChannelGroups = pnUnity.SubscriptionInstance.AllChannelGroups;
            List <ChannelEntity> allChannels      = pnUnity.SubscriptionInstance.AllChannels;
            List <ChannelEntity> allNonPresenceChannelsOrChannelGroups           = pnUnity.SubscriptionInstance.AllNonPresenceChannelsOrChannelGroups;
            List <ChannelEntity> allPresenceChannelsOrChannelGroups              = pnUnity.SubscriptionInstance.AllPresenceChannelsOrChannelGroups;
            List <ChannelEntity> allSubscribedChannelsAndChannelGroups           = pnUnity.SubscriptionInstance.AllSubscribedChannelsAndChannelGroups;
            List <ChannelEntity> channelsAndChannelGroupsAwaitingConnectCallback = pnUnity.SubscriptionInstance.ChannelsAndChannelGroupsAwaitingConnectCallback;
            string compiledUserState   = pnUnity.SubscriptionInstance.CompiledUserState;
            bool   connectCallbackSent = pnUnity.SubscriptionInstance.ConnectCallbackSent;
            int    currentSubscribedChannelGroupsCount = pnUnity.SubscriptionInstance.CurrentSubscribedChannelGroupsCount;
            int    currentSubscribedChannelsCount      = pnUnity.SubscriptionInstance.CurrentSubscribedChannelsCount;
            bool   hasChannelGroups           = pnUnity.SubscriptionInstance.HasChannelGroups;
            bool   hasChannel                 = pnUnity.SubscriptionInstance.HasChannels;
            bool   hasChannelsOrChannelGroups = pnUnity.SubscriptionInstance.HasChannelsOrChannelGroups;
            bool   hasPresenceChannels        = pnUnity.SubscriptionInstance.HasPresenceChannels;

            Assert.True(compiledUserState.Equals(compiledUserStateA), compiledUserState);
            Assert.True(connectCallbackSent.Equals(connectCallbackSentA), connectCallbackSent.ToString());
            Assert.True(hasChannelGroups.Equals(hasChannelGroupsA), hasChannelGroups.ToString());
            Assert.True(hasChannel.Equals(hasChannelA), hasChannel.ToString());
            Assert.True(hasChannelsOrChannelGroups.Equals(hasChannelsOrChannelGroupsA), hasChannelsOrChannelGroups.ToString());
            Assert.True(hasPresenceChannels.Equals(hasPresenceChannelsA), hasPresenceChannels.ToString());
            Assert.True(currentSubscribedChannelGroupsCount.Equals(currentSubscribedChannelGroupsCountA), currentSubscribedChannelGroupsCount.ToString());
            Assert.True(currentSubscribedChannelsCount.Equals(currentSubscribedChannelsCountA), currentSubscribedChannelsCount.ToString());

            bool allChannelGroupsFound = ParseListCE(allChannelGroups,
                                                     allChannelGroupsA);

            Assert.True(allChannelGroupsFound);

            bool allChannelsFound = ParseListCE(allChannels,
                                                allChannelsA);

            Assert.True(allChannelsFound);

            bool allNonPresenceChannelsOrChannelGroupsFound = ParseListCE(allNonPresenceChannelsOrChannelGroups,
                                                                          allNonPresenceChannelsOrChannelGroupsA);

            Assert.True(allNonPresenceChannelsOrChannelGroupsFound);

            bool allPresenceChannelsOrChannelGroupsFound = ParseListCE(allPresenceChannelsOrChannelGroups,
                                                                       allPresenceChannelsOrChannelGroupsA);

            Assert.True(allPresenceChannelsOrChannelGroupsFound);

            bool channelsAndChannelGroupsAwaitingConnectCallbackFound = ParseListCE(channelsAndChannelGroupsAwaitingConnectCallback,
                                                                                    channelsAndChannelGroupsAwaitingConnectCallbackA);

            Assert.True(channelsAndChannelGroupsAwaitingConnectCallbackFound);

            bool allSubscribedChannelsAndChannelGroupsFound = ParseListCE(allSubscribedChannelsAndChannelGroups,
                                                                          allSubscribedChannelsAndChannelGroupsA);

            Assert.True(allSubscribedChannelsAndChannelGroupsFound);
        }
예제 #2
0
        public void TestCBORTokensCommon()
        {
            string t1 = "p0F2AkF0Gl2AX-JDdHRsCkNyZXOkRGNoYW6gQ2dycKBDdXNyoWl1LTMzNTIwNTUPQ3NwY6Fpcy0xNzA3OTgzGB9DcGF0pERjaGFuoENncnCgQ3VzcqBDc3BjoERtZXRhoENzaWdYINqGs2EyEMHPZrp6znVqTBzXNBAD_31hUH3JuUSWE2A6";
            string t2 = "p0F2AkF0Gl2AaMlDdHRsCkNyZXOkRGNoYW6gQ2dycKBDdXNyoWl1LTE5NzQxMDcPQ3NwY6Fpcy0yMzExMDExGB9DcGF0pERjaGFuoENncnCgQ3VzcqBDc3BjoERtZXRhoENzaWdYIO1ti19DLbEKK-s_COJPlM1xtZCpP8K4sV51nvRPTIxf";
            string t3 = "p0F2AkF0Gl2CEiRDdHRsA0NyZXOkRGNoYW6gQ2dycKBDdXNyoW50ZXN0dXNlcl8xNjY2ORgfQ3NwY6FvdGVzdHNwYWNlXzE1MDExGB9DcGF0pERjaGFuoENncnCgQ3VzcqBDc3BjoERtZXRhoENzaWdYIMqDoIOYPP9ULfXKLDK3eoGQ-C8nJxPTWFCDAc-Flxu7";
            string t4 = "p0F2AkF0Gl2CEiVDdHRsA0NyZXOkRGNoYW6gQ2dycKBDdXNyoENzcGOgQ3BhdKREY2hhbqBDZ3JwoEN1c3KhY14uKhgfQ3NwY6FjXi4qGB9EbWV0YaBDc2lnWCDfqMStM0r1GgghNjt1MPeSaA0ADTw6aGsuQgMT3jYylg==";

            PNConfiguration pnConfiguration = new PNConfiguration();

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

            pnConfiguration.StoreTokensOnGrant = true;
            pnConfiguration.SecretKey          = "";

            PubNub pn = new PubNub(pnConfiguration);

            pn.SetTokens(new List <string> {
                t1, t2, t3, t4
            });

            GrantResourcesWithPermissions g = pn.GetTokens();

            Assert.IsTrue(g.Channels.Count.Equals(0));
            Assert.IsTrue(g.Groups.Count.Equals(0));
            Assert.IsTrue(g.ChannelsPattern.Count.Equals(0));
            Assert.IsTrue(g.GroupsPattern.Count.Equals(0));
            foreach (KeyValuePair <string, UserSpacePermissionsWithToken> kvp in g.Users)
            {
                Debug.Log(kvp.Key + "===>" + kvp.Value);
                UserSpacePermissionsWithToken u;

                if (g.Users.TryGetValue(kvp.Key, out u))
                {
                    Debug.Log(kvp.Key + "=======>" + u.Token);
                }
            }
            UserSpacePermissionsWithToken u1;

            if (g.Users.TryGetValue("testuser_16669", out u1))
            {
                Debug.Log("testuser_16669 =======>" + u1.Token);
            }
            else
            {
                Debug.Log("testuser_16669 not found");
            }
            Debug.Log(g.Users.ContainsKey("testuser_16669"));
            Debug.Log(g.Users.ContainsKey("u-1974107"));
            Debug.Log(g.Users.ContainsKey("u-3352055"));
            Assert.IsTrue(g.Users["testuser_16669"].BitMaskPerms.Equals(31));
            Assert.IsTrue(g.Users["testuser_16669"].TTL.Equals(3));
            Assert.IsTrue(g.Users["testuser_16669"].Timestamp.Equals(1568805412));

            Assert.IsTrue(g.Users["testuser_16669"].Token.Equals(t3));
            Assert.IsTrue(g.Users["testuser_16669"].Permissions.Read.Equals(true));
            Assert.IsTrue(g.Users["testuser_16669"].Permissions.Write.Equals(true));
            Assert.IsTrue(g.Users["testuser_16669"].Permissions.Delete.Equals(true));
            Assert.IsTrue(g.Users["testuser_16669"].Permissions.Create.Equals(true));
            Assert.IsTrue(g.Users["testuser_16669"].Permissions.Manage.Equals(true));

            Assert.IsTrue(g.Spaces["testspace_15011"].Token.Equals(t3));
            Assert.IsTrue(g.Spaces["testspace_15011"].Permissions.Read.Equals(true));
            Assert.IsTrue(g.Spaces["testspace_15011"].Permissions.Write.Equals(true));
            Assert.IsTrue(g.Spaces["testspace_15011"].Permissions.Delete.Equals(true));
            Assert.IsTrue(g.Spaces["testspace_15011"].Permissions.Create.Equals(true));
            Assert.IsTrue(g.Spaces["testspace_15011"].Permissions.Manage.Equals(true));

            Assert.IsTrue(g.Users["u-1974107"].Token.Equals(t2));
            Assert.IsTrue(g.Spaces["s-1707983"].Token.Equals(t1));

            Assert.IsTrue(g.UsersPattern["^.*"].Token.Equals(t4));
            Assert.IsTrue(g.SpacesPattern["^.*"].Token.Equals(t4));

            GrantResourcesWithPermissions g2 = pn.GetTokensByResource(PNResourceType.PNUUIDMetadata);

            Assert.IsTrue(g2.Users["testuser_16669"].BitMaskPerms.Equals(31));
            Assert.IsTrue(g2.Users["testuser_16669"].TTL.Equals(3));
            Assert.IsTrue(g2.Users["testuser_16669"].Timestamp.Equals(1568805412));

            Assert.IsTrue(g2.Users["testuser_16669"].Token.Equals(t3));
            Assert.IsTrue(g2.Users["testuser_16669"].Permissions.Read.Equals(true));
            Assert.IsTrue(g2.Users["testuser_16669"].Permissions.Write.Equals(true));
            Assert.IsTrue(g2.Users["testuser_16669"].Permissions.Delete.Equals(true));
            Assert.IsTrue(g2.Users["testuser_16669"].Permissions.Create.Equals(true));
            Assert.IsTrue(g2.Users["testuser_16669"].Permissions.Manage.Equals(true));
            Assert.IsTrue(g2.Users["u-1974107"].Token.Equals(t2));
            Assert.IsTrue(g2.UsersPattern["^.*"].Token.Equals(t4));

            GrantResourcesWithPermissions g3 = pn.GetTokensByResource(PNResourceType.PNChannelMetadata);

            Assert.IsTrue(g3.Spaces["testspace_15011"].BitMaskPerms.Equals(31));
            Assert.IsTrue(g3.Spaces["testspace_15011"].TTL.Equals(3));
            Assert.IsTrue(g3.Spaces["testspace_15011"].Timestamp.Equals(1568805412));

            Assert.IsTrue(g3.Spaces["testspace_15011"].Token.Equals(t3));
            Assert.IsTrue(g3.Spaces["testspace_15011"].Permissions.Read.Equals(true));
            Assert.IsTrue(g3.Spaces["testspace_15011"].Permissions.Write.Equals(true));
            Assert.IsTrue(g3.Spaces["testspace_15011"].Permissions.Delete.Equals(true));
            Assert.IsTrue(g3.Spaces["testspace_15011"].Permissions.Create.Equals(true));
            Assert.IsTrue(g3.Spaces["testspace_15011"].Permissions.Manage.Equals(true));
            Assert.IsTrue(g3.Spaces["s-1707983"].Token.Equals(t1));
            Assert.IsTrue(g3.SpacesPattern["^.*"].Token.Equals(t4));

            string g4 = pn.GetToken("testspace_15011", PNResourceType.PNChannelMetadata);

            Debug.Log("g4" + g4);
            Assert.IsTrue(g4.Equals(t3));
            string g5 = pn.GetToken("testuser_16669", PNResourceType.PNUUIDMetadata);

            Assert.IsTrue(g5.Equals(t3));
            string g6 = pn.GetToken("^.*", PNResourceType.PNChannelMetadata);

            Assert.IsTrue(g6.Equals(t4));
            string g7 = pn.GetToken("^.*", PNResourceType.PNUUIDMetadata);

            Assert.IsTrue(g7.Equals(t4));
            string g8 = pn.GetToken("NONEXISTENT", PNResourceType.PNChannelMetadata);

            Assert.IsTrue(g8.Equals(t4));
            string g9 = pn.GetToken("NONEXISTENT", PNResourceType.PNUUIDMetadata);

            Assert.IsTrue(g9.Equals(t4));
        }
예제 #3
0
        public void TestBuildDetailedHistoryRequestCommon(bool ssl, bool reverse, bool includeTimetoken,
                                                          string authKey, long startTime, long endTime, int count, bool sendQueryParams, bool withMeta)
        {
            string channel = "history_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.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 startTimeString = "";
            string endTimeString   = "";

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

            if (count == -1)
            {
                count = 100;
            }

            Uri uri = BuildRequests.BuildHistoryRequest(channel, startTime, endTime, (uint)count, reverse,
                                                        includeTimetoken, pnUnity, queryParams, withMeta
                                                        );

            if (count == -1)
            {
                count = 100;
            }
            //Received:http://ps.pndsn.com/v2/history/sub-key/demo/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/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/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}{13}{9}&uuid={10}&pnsdk={11}{12}",
                                            ssl?"s":"", pnConfiguration.Origin, EditorCommon.SubscribeKey, channel, count,
                                            includeTimetoken?"&include_token=true":"", reverse?"&reverse=true":"",
                                            startTimeString, endTimeString, authKeyString, uuid,
                                            Utility.EncodeUricomponent(pnUnity.Version, PNOperationType.PNHistoryOperation, false, true),
                                            queryParamString, withMeta?"&include_meta=true":""
                                            );
            string received = uri.OriginalString;

            EditorCommon.LogAndCompare(expected, received);
        }
예제 #4
0
        public void TestSubscription()
        {
            PNConfiguration pnConfiguration = new PNConfiguration();

            pnConfiguration.Origin           = EditorCommon.Origin;
            pnConfiguration.SubscribeKey     = EditorCommon.SubscribeKey;
            pnConfiguration.PublishKey       = EditorCommon.PublishKey;
            pnConfiguration.CipherKey        = "enigma";
            pnConfiguration.LogVerbosity     = PNLogVerbosity.BODY;
            pnConfiguration.PresenceTimeout  = 60;
            pnConfiguration.PresenceInterval = 30;
            PubNubUnity pnUnity = new PubNubUnity(pnConfiguration, null, null);

            pnUnity.SubscriptionInstance.CleanUp();
            PNLoggingMethod pnLog = new PNLoggingMethod(pnConfiguration.LogVerbosity);
            //Add CE with ch cg, ch-pres, cgpres, 2 awaiting connect callback with userstate
            List <ChannelEntity> channelEntities = EditorCommon.CreateListOfChannelEntities(true, true, true, true, pnLog);

            pnUnity.SubscriptionInstance.Add(channelEntities);

            // Test All
            RunAssertions(pnUnity, "{\"ch1\":{\"k\":\"v\",\"k2\":\"v2\"},\"ch2\":{\"k3\":\"v3\",\"k4\":\"v4\"},\"ch2-pnpres\":{\"k7\":\"v7\",\"k8\":\"v8\"},\"ch7\":{\"k7\":\"v7\",\"k8\":\"v8\"},\"cg1\":{\"k5\":\"v5\",\"k6\":\"v6\"},\"cg2\":{\"k7\":\"v7\",\"k8\":\"v8\"},\"cg2-pnpres\":{\"k7\":\"v7\",\"k8\":\"v8\"},\"cg8\":{\"k7\":\"v7\",\"k8\":\"v8\"}}",
                          false, true, true, true, true, 4, 4,
                          new string[] { "cg1", "cg2", "cg2-pnpres", "cg8" },
                          new string[] { "ch1", "ch2", "ch2-pnpres", "ch7" },
                          new string[] { "ch1", "ch2", "ch7", "cg1", "cg2", "cg8" },
                          new string[] { "cg2-pnpres", "ch2-pnpres" },
                          new string[] { "ch7", "cg8" },
                          new string[] { "ch1", "ch2", "ch2-pnpres", "ch7", "cg1", "cg2", "cg2-pnpres", "cg8" });


            // Delete 2
            ChannelEntity ce = Helpers.CreateChannelEntity("ch2", false, false, null, pnLog);

            pnUnity.SubscriptionInstance.Delete(ce);
            ChannelEntity ce2 = Helpers.CreateChannelEntity("cg2", false, true, null, pnLog);

            pnUnity.SubscriptionInstance.Delete(ce2);

            // Test All
            RunAssertions(pnUnity, "{\"ch1\":{\"k\":\"v\",\"k2\":\"v2\"},\"ch2-pnpres\":{\"k7\":\"v7\",\"k8\":\"v8\"},\"ch7\":{\"k7\":\"v7\",\"k8\":\"v8\"},\"cg1\":{\"k5\":\"v5\",\"k6\":\"v6\"},\"cg2-pnpres\":{\"k7\":\"v7\",\"k8\":\"v8\"},\"cg8\":{\"k7\":\"v7\",\"k8\":\"v8\"}}",
                          false, true, true, true, true, 3, 3,
                          new string[] { "cg1", "cg2-pnpres", "cg8" },
                          new string[] { "ch1", "ch2-pnpres", "ch7" },
                          new string[] { "ch1", "ch7", "cg1", "cg8" },
                          new string[] { "cg2-pnpres", "ch2-pnpres" },
                          new string[] { "ch7", "cg8" },
                          new string[] { "ch1", "ch2-pnpres", "ch7", "cg1", "cg2-pnpres", "cg8" });


            // UpdateOrAddUserStateOfEntity
            ChannelEntity ce3     = Helpers.CreateChannelEntity("ch1", false, false, null, pnLog);
            var           dictSMN = new Dictionary <string, object>();

            dictSMN.Add("k", "v9");

            pnUnity.SubscriptionInstance.TryUpdateOrAddUserStateOfEntity(ref ce3, dictSMN, true);

            // Test All
            RunAssertions(pnUnity, "{\"ch1\":{\"k\":\"v9\",\"k2\":\"v2\"},\"ch2-pnpres\":{\"k7\":\"v7\",\"k8\":\"v8\"},\"ch7\":{\"k7\":\"v7\",\"k8\":\"v8\"},\"cg1\":{\"k5\":\"v5\",\"k6\":\"v6\"},\"cg2-pnpres\":{\"k7\":\"v7\",\"k8\":\"v8\"},\"cg8\":{\"k7\":\"v7\",\"k8\":\"v8\"}}",
                          false, true, true, true, true, 3, 3,
                          new string[] { "cg1", "cg2-pnpres", "cg8" },
                          new string[] { "ch1", "ch2-pnpres", "ch7" },
                          new string[] { "ch1", "ch7", "cg1", "cg8" },
                          new string[] { "cg2-pnpres", "ch2-pnpres" },
                          new string[] { "ch7", "cg8" },
                          new string[] { "ch1", "ch2-pnpres", "ch7", "cg1", "cg2-pnpres", "cg8" });

            // UpdateIsAwaitingConnectCallbacksOfEntity
            ChannelEntity ce4 = Helpers.CreateChannelEntity("ch7", false, false, null, pnLog);
            ChannelEntity ce5 = Helpers.CreateChannelEntity("cg8", false, true, null, pnLog);

            List <ChannelEntity> lstCE = new List <ChannelEntity>();

            lstCE.Add(ce4);
            lstCE.Add(ce5);

            pnUnity.SubscriptionInstance.UpdateIsAwaitingConnectCallbacksOfEntity(lstCE, false);

            // Test All
            RunAssertions(pnUnity, "{\"ch1\":{\"k\":\"v9\",\"k2\":\"v2\"},\"ch2-pnpres\":{\"k7\":\"v7\",\"k8\":\"v8\"},\"ch7\":{\"k7\":\"v7\",\"k8\":\"v8\"},\"cg1\":{\"k5\":\"v5\",\"k6\":\"v6\"},\"cg2-pnpres\":{\"k7\":\"v7\",\"k8\":\"v8\"},\"cg8\":{\"k7\":\"v7\",\"k8\":\"v8\"}}",
                          true, true, true, true, true, 3, 3,
                          new string[] { "cg1", "cg2-pnpres", "cg8" },
                          new string[] { "ch1", "ch2-pnpres", "ch7" },
                          new string[] { "ch1", "ch7", "cg1", "cg8" },
                          new string[] { "cg2-pnpres", "ch2-pnpres" },
                          new string[] { "ch7", "cg8" },
                          new string[] { "ch1", "ch2-pnpres", "ch7", "cg1", "cg2-pnpres", "cg8" });

            // CleanUp
            pnUnity.SubscriptionInstance.CleanUp();

            // Test All

            RunAssertions(pnUnity, String.Empty,
                          false, false, false, false, false, 0, 0,
                          new string[] {},
                          new string[] {},
                          new string[] {},
                          new string[] {},
                          new string[] {},
                          new string[] {});
        }
        public void TestBuildSubscribeRequestCommon(string[] channels, string[] channelGroups,
                                                    object timetoken, string userState,
                                                    bool ssl, string authKey, string filterExpr, string region, int presenceHeartbeat, bool sendQueryParams)
        {
            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;
            if (presenceHeartbeat != 0)
            {
                pnConfiguration.PresenceTimeout = presenceHeartbeat;
            }
            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 tt = "0";

            if (timetoken == null)
            {
                tt = "0";
            }
            else
            {
                tt = timetoken.ToString();
            }
            if (string.IsNullOrEmpty(tt))
            {
                tt = "0";
            }
            string ttStr = string.Format("&tt={0}", tt);

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

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

            string phb = "";
            // if (presenceHeartbeat != 0) {
            //     phb = string.Format("&heartbeat={0}", presenceHeartbeat);
            // }

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

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

            Uri uri = BuildRequests.BuildSubscribeRequest(ch, cg, tt, userState, region, filterExpr, pnUnity, queryParams);

            string filterExpression = "";

            if (!string.IsNullOrEmpty(filterExpr))
            {
                filterExpression = string.Format("&filter-expr=({0})", Utility.EncodeUricomponent(filterExpr, PNOperationType.PNSubscribeOperation, false, false));
            }

            string reg = "";

            if (!string.IsNullOrEmpty(region))
            {
                reg = string.Format("&tr=({0})", Utility.EncodeUricomponent(region, PNOperationType.PNSubscribeOperation, false, false));
            }

            //http://ps.pndsn.com/v2/subscribe/demo-36/test/0?uuid=customuuid&tt=21221&state={"k":"v"}&auth=authKey&pnsdk=PubNub-CSharp-UnityIOS/3.6.9.0
            //http://ps.pndsn.com/v2/subscribe/demo-36/test/0?uuid=customuuid&tt=0&filter-expr=(region%20%3D%3D%20%22east%22)&channel-group=cg&auth=authKey&pnsdk=PubNub-CSharp-UnityOSX/3.7
            string expected = string.Format("http{0}://{1}/v2/subscribe/{2}/{3}/0?uuid={5}{4}{10}{11}{6}{7}{12}{8}{13}{15}&pnsdk={9}{14}",
                                            ssl?"s":"", pnConfiguration.Origin, pnConfiguration.SubscribeKey,
                                            chStr,
                                            ttStr,
                                            uuid,
                                            (userState == "")?"":"&state=",
                                            Utility.EncodeUricomponent(userState, PNOperationType.PNSubscribeOperation, false, false),
                                            authKeyString,
                                            Utility.EncodeUricomponent(pnUnity.Version, PNOperationType.PNSubscribeOperation, false, false),
                                            filterExpression,
                                            reg,
                                            cgStr,
                                            phb,
                                            queryParamString,
                                            (pnConfiguration.PresenceTimeout > 0)?string.Format("&heartbeat={0}", pnConfiguration.PresenceTimeout) : ""
                                            );
            string received = uri.OriginalString;

            EditorCommon.LogAndCompare(expected, received);
        }
예제 #6
0
        public void TestBuildGetUserStateRequestCommon(bool testCg, bool testCh, 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 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.PNGetStateOperation, 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.BuildGetStateRequest(channel, channelGroup, uuid, pnUnity, queryParams);

            //https://ps.pndsn.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}{9}{7}&pnsdk={8}{10}",
                                            ssl?"s":"", pnConfiguration.Origin, EditorCommon.SubscribeKey, channel, uuid,
                                            Utility.EncodeUricomponent(userState, PNOperationType.PNGetStateOperation, false, false),
                                            uuid, authKeyString,
                                            Utility.EncodeUricomponent(pnUnity.Version, PNOperationType.PNGetStateOperation, false, false),
                                            channelGroupStr,
                                            queryParamString
                                            );
            string received = uri.OriginalString;

            EditorCommon.LogAndCompare(expected, received);
        }
예제 #7
0
        public void BuildUnregisterDevicePushRequestCommon(bool ssl, string authKey, string pushToken, PNPushType pushType, bool sendQueryParams, bool withAPNS2, bool withEnvProd, bool withTopic)
        {
            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.BuildRemoveAllDevicePushRequest(pushType, pushToken, pnUnity, queryParams);

            if (withAPNS2)
            {
                uri = BuildRequests.BuildRemoveAllDevicePushRequest(pushType, pushToken, pnUnity, queryParams, (withTopic)?"topic":"", (withEnvProd)?PNPushEnvironment.Production: PNPushEnvironment.Development);
            }

            //[1, "Removed Device"]
            //https://ps.pndsn.com/v1/push/sub-key/demo-36/devices/pushToken/remove?type=wns&uuid=customuuid&auth=authKey&pnsdk=PubNub-CSharp-UnityIOS/3.6.9.0
            string expected = string.Format("http{0}://{1}/{9}/push/sub-key/{2}/{10}/{3}/remove?type={4}{12}{11}&uuid={5}{6}&pnsdk={7}{8}",
                                            ssl?"s":"", pnConfiguration.Origin, EditorCommon.SubscribeKey, pushToken,
                                            pushType.ToString().ToLower(),
                                            uuid, authKeyString,
                                            Utility.EncodeUricomponent(pnUnity.Version, PNOperationType.PNRemoveAllPushNotificationsOperation, false, true),
                                            queryParamString,
                                            (withAPNS2)?"v2":"v1",
                                            (withAPNS2)?"devices-apns2":"devices",
                                            (withAPNS2)?((withEnvProd)?"&environment=production":"&environment=development"):"",
                                            (withAPNS2)?((withTopic)?"&topic=topic":""):""
                                            );
            string received = uri.OriginalString;

            UnityEngine.Debug.Log("exp:" + expected);
            UnityEngine.Debug.Log(received);
            EditorCommon.LogAndCompare(expected, received);
        }
예제 #8
0
        //GetChannels
        //Get All CG
        public void TestBuildGetChannelsForChannelGroupRequestCommon(bool allCg, 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 channelGroupStr = "channel-group/";

            if (allCg)
            {
                channelGroup    = "";
                channelGroupStr = "channel-group";
            }
            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);

            string authKeyString = "";

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

            Uri uri = BuildRequests.BuildGetChannelsForChannelGroupRequest("", channelGroup, allCg,
                                                                           pnUnity, queryParams
                                                                           );

            //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}/{8}{3}?uuid={5}{6}&pnsdk={7}{9}",
                                            ssl?"s":"", pnConfiguration.Origin, EditorCommon.SubscribeKey, channelGroup,
                                            "",
                                            uuid, authKeyString,
                                            Utility.EncodeUricomponent(pnUnity.Version, PNOperationType.PNChannelsForGroupOperation, false, true),
                                            channelGroupStr,
                                            queryParamString
                                            );
            string received = uri.OriginalString;

            EditorCommon.LogAndCompare(expected, received);
        }
 public FetchMessagesReq(PubNubUnity pn, Action <PNFetchMessagesResult, PNStatus> callback) : base(pn)
 {
     base.Callback = callback;
 }