public void TestHash() { //test unsafe surrogate and normal test string expected = "46-65-08-E8-6F-35-1D-95-27-3B-91-A1-A6-E0-BC-C2-2F-23-99-5A-49-A0-E0-61-91-C8-B9-7E-C5-2E-40-90"; //"83a644046796c6a0d76bc161f73b75b4"; PubnubCrypto pnCrypto = new PubnubCrypto("", new PNLoggingMethod(PNLogVerbosity.BODY)); string received = pnCrypto.ComputeHashRaw("test md5"); //string received = Utility.Md5("test md5"); UnityEngine.Debug.Log(received); Assert.IsTrue(expected.Equals(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); }