// TestHashDecryption tests the hash decryption. // Assumes that the input message is deserialized // Decrypted string should match {\"foo\":{\"bar\":\"foobar\"}} func TestHashDecryption(t *testing.T) { message := "GsvkCYZoYylL5a7/DKhysDjNbwn+BtBtHj2CvzC4Y4g=" //decrypt decrypted, decErr := pubnubMessaging.DecryptString("enigma", message) if decErr != nil { t.Error("Hash decryption: failed.") } else { if "{\"foo\":{\"bar\":\"foobar\"}}" == decrypted { fmt.Println("Hash decryption: passed.") } else { t.Error("Hash decryption: failed.") } } }
// TestYayDecryptionBasic tests the yay decryption. // Assumes that the input message is deserialized // Decrypted string should match yay! func TestYayDecryptionBasic(t *testing.T) { message := "q/xJqqN6qbiZMXYmiQC1Fw==" //decrypt decrypted, decErr := pubnubMessaging.DecryptString("enigma", message) if decErr != nil { t.Error("Yay decryption basic: failed.") } else { if "yay!" == decrypted { fmt.Println("Yay decryption basic: passed.") } else { t.Error("Yay decryption basic: failed.") } } }
// TestStuffCanDecryption tests the StuffCan decryption. // Assumes that the input message is deserialized // Decrypted string should match {\"this stuff\":{\"can get\":\"complicated!\"}} func TestStuffCanDecryption(t *testing.T) { message := "zMqH/RTPlC8yrAZ2UhpEgLKUVzkMI2cikiaVg30AyUu7B6J0FLqCazRzDOmrsFsF" //decrypt decrypted, decErr := pubnubMessaging.DecryptString("enigma", message) if decErr != nil { t.Error("StuffCan decryption: failed.") } else { if "{\"this stuff\":{\"can get\":\"complicated!\"}}" == decrypted { fmt.Println("StuffCan decryption: passed.") } else { t.Error("StuffCan decryption: failed.") } } }
// TestGermanDecryption tests the German decryption. // Assumes that the input message is deserialized // Decrypted string should match ÜÖ func TestGermanDecryption(t *testing.T) { message := "stpgsG1DZZxb44J7mFNSzg==" //decrypt decrypted, decErr := pubnubMessaging.DecryptString("enigma", message) if decErr != nil { t.Error("German decryption: failed.") } else { data, _, _, err := pubnubMessaging.ParseJson([]byte(decrypted.(string)), "") if err != nil { t.Error("German decryption: failed.", err) } else { if "ÜÖ" == data { fmt.Println("German decryption: passed.") } else { t.Error("German decryption: failed.") } } } }
// TestUnicodeDecryption tests the Unicode decryption. // Assumes that the input message is deserialized // Decrypted string should match 漢語 func TestUnicodeDecryption(t *testing.T) { message := "+BY5/miAA8aeuhVl4d13Kg==" //decrypt decrypted, decErr := pubnubMessaging.DecryptString("enigma", message) if decErr != nil { t.Error("Unicode decryption: failed.") } else { data, _, _, err := pubnubMessaging.ParseJson([]byte(decrypted.(string)), "") if err != nil { t.Error("Unicode decryption: failed.", err) } else { if "漢語" == data { fmt.Println("Unicode decryption: passed.") } else { t.Error("Unicode decryption: failed.") } } } }
// TestPubNubDecryption tests the Pubnub Messaging API 1 decryption. // Assumes that the input message is deserialized // Decrypted string should match Pubnub Messaging API 1 func TestPubNubDecryption(t *testing.T) { message := "f42pIQcWZ9zbTbH8cyLwByD/GsviOE0vcREIEVPARR0=" //decrypt decrypted, decErr := pubnubMessaging.DecryptString("enigma", message) if decErr != nil { t.Error("Pubnub Messaging API 1 decryption: failed.") } else { b, err := json.Marshal("Pubnub Messaging API 1") if err != nil { fmt.Println("error:", err) t.Error("Pubnub Messaging API 1 decryption: failed.") } else { if string(b) == decrypted { fmt.Println("Pubnub Messaging API 1 decryption: passed.") } else { t.Error("Pubnub Messaging API 1 decryption: failed.") } } } }
// TestPubNubDecryption2 tests the Pubnub Messaging API 2 decryption. // Assumes that the input message is deserialized // Decrypted string should match Pubnub Messaging API 2 func TestPubNubDecryption2(t *testing.T) { message := "f42pIQcWZ9zbTbH8cyLwB/tdvRxjFLOYcBNMVKeHS54=" //decrypt decrypted, decErr := pubnubMessaging.DecryptString("enigma", message) if decErr != nil { t.Error("Pubnub Messaging API 2 decryption: failed.") } else { b, err := json.Marshal("Pubnub Messaging API 2") if err != nil { fmt.Println("error:", err) t.Error("Pubnub Messaging API 2 decryption: failed.") } else { if string(b) == decrypted { fmt.Println("Pubnub Messaging API 2 decryption: passed.") } else { t.Error("Pubnub Messaging API 2 decryption: failed.") } } } }
// TestYayDecryption tests the yay decryption. // Assumes that the input message is serialized // Decrypted string should match yay! func TestYayDecryption(t *testing.T) { message := "Wi24KS4pcTzvyuGOHubiXg==" //decrypt decrypted, decErr := pubnubMessaging.DecryptString("enigma", message) if decErr != nil { t.Error("Yay decryption: failed.") } else { //serialize b, err := json.Marshal("yay!") if err != nil { fmt.Println("error:", err) t.Error("Yay decryption: failed.") } else { if string(b) == decrypted { fmt.Println("Yay decryption: passed.") } else { t.Error("Yay decryption: failed.") } } } }
// TestObjectDecryption tests the empty object decryption. // Assumes that the input message is deserialized // And the output message has to been deserialized. // Decrypted string should match IDjZE9BHSjcX67RddfCYYg== func TestObjectDecryption(t *testing.T) { message := "IDjZE9BHSjcX67RddfCYYg==" //decrypt decrypted, decErr := pubnubMessaging.DecryptString("enigma", message) if decErr != nil { t.Error("Object decryption: failed.") } else { emptyStruct := EmptyStruct{} b, err := json.Marshal(emptyStruct) if err != nil { fmt.Println("error:", err) t.Error("Object decryption: failed.") } else { if string(b) == decrypted { fmt.Println("Object decryption: passed.") } else { t.Error("Object decryption: failed.") } } } }
// TestArrayDecryption tests the slice decryption. // Assumes that the input message is deserialized // And the output message has to been deserialized. // Decrypted string should match Ns4TB41JjT2NCXaGLWSPAQ== func TestArrayDecryption(t *testing.T) { message := "Ns4TB41JjT2NCXaGLWSPAQ==" //decrypt decrypted, decErr := pubnubMessaging.DecryptString("enigma", message) if decErr != nil { t.Error("Slice decryption: failed.") } else { slice := []string{} b, err := json.Marshal(slice) if err != nil { fmt.Println("error:", err) t.Error("Slice decryption: failed.") } else { if string(b) == decrypted { fmt.Println("Slice decryption: passed.") } else { t.Error("Slice decryption: failed.") } } } }
// TestComplexClassDecryption tests the complex struct decryption. // Decrypted string should match uu3hDKcmV5/5mym7sIPJaf+W3Uu1xJLZLYaEBJPbZut+uwGHV5QmMWCOTTSOuBwcNk4bldx+y1ZAaHFETwkfMOOCHvdwrw6YcoyuJDqPglD+DEwLjUes50nEfrw7aMwmsKP2BmbyM+0mL2Nw30X4QP6lCcOaaUgXGWuMPJXfhrutSpiDDvJhSG6/eqZUEVmpKilxVnbsCqYGRWHHIE5dbuWE1odOot6oW4OobspaQtK2bBj/MNwFWwoZjLgyRi6Rxm0PRhgcOgxWneSrIW5UUf6xan4i4UfSN0PevVu5iRxwg1yLSISQViYihwFkc6ncJaUQ6nY+fESwHAn8IYGTYtuHc4j/C9pQwB5WhnoUaXRiJKchjnCf+zS6hyU7hlDZm7XdXRI6dZIIHGfBI5o2H/DmT3DFQM/mUZQLqmyFGM72QXV4bRIr0zUulTMOQgDVL2khic8bEZ28ji68ogNSnRMDMW81IzRInpv14zWyADRcab2tnlcQosmVwhDSJtnd func TestComplexClassDecryption(t *testing.T) { message := "uu3hDKcmV5/5mym7sIPJaf+W3Uu1xJLZLYaEBJPbZut+uwGHV5QmMWCOTTSOuBwcNk4bldx+y1ZAaHFETwkfMOOCHvdwrw6YcoyuJDqPglD+DEwLjUes50nEfrw7aMwmsKP2BmbyM+0mL2Nw30X4QP6lCcOaaUgXGWuMPJXfhrutSpiDDvJhSG6/eqZUEVmpKilxVnbsCqYGRWHHIE5dbuWE1odOot6oW4OobspaQtK2bBj/MNwFWwoZjLgyRi6Rxm0PRhgcOgxWneSrIW5UUf6xan4i4UfSN0PevVu5iRxwg1yLSISQViYihwFkc6ncJaUQ6nY+fESwHAn8IYGTYtuHc4j/C9pQwB5WhnoUaXRiJKchjnCf+zS6hyU7hlDZm7XdXRI6dZIIHGfBI5o2H/DmT3DFQM/mUZQLqmyFGM72QXV4bRIr0zUulTMOQgDVL2khic8bEZ28ji68ogNSnRMDMW81IzRInpv14zWyADRcab2tnlcQosmVwhDSJtnd" //decrypt decrypted, decErr := pubnubMessaging.DecryptString("enigma", message) if decErr != nil { t.Error("Custom complex decryption: failed.") } else { customComplexMessage := InitComplexMessage() b, err := json.Marshal(customComplexMessage) if err != nil { fmt.Println("error:", err) t.Error("Custom complex decryption: failed.") } else { if string(b) == decrypted { fmt.Println("Custom complex decryption: passed.") } else { t.Error("Custom complex decryption: failed.") } } } }
// TestMyObjectDecryption tests the custom object decryption. // Assumes that the input message is deserialized // And the output message has to been deserialized. // Decrypted string should match BMhiHh363wsb7kNk7krTtDcey/O6ZcoKDTvVc4yDhZY= func TestMyObjectDecryption(t *testing.T) { message := "BMhiHh363wsb7kNk7krTtDcey/O6ZcoKDTvVc4yDhZY=" //decrypt decrypted, decErr := pubnubMessaging.DecryptString("enigma", message) if decErr != nil { t.Error("My object decryption: failed.") } else { customStruct := CustomStruct{ Foo: "hi!", Bar: []int{1, 2, 3, 4, 5}, } b, err := json.Marshal(customStruct) if err != nil { fmt.Println("error:", err) t.Error("My object decryption: failed.") } else { if string(b) == decrypted { fmt.Println("My object decryption: passed.") } else { t.Error("My object decryption: failed.") } } } }