// TestStuffCanEncryption tests the StuffCan encryption. // Assumes that the input message is not serialized // Decrypted string should match zMqH/RTPlC8yrAZ2UhpEgLKUVzkMI2cikiaVg30AyUu7B6J0FLqCazRzDOmrsFsF func TestStuffCanEncryption(t *testing.T) { message := "{\"this stuff\":{\"can get\":\"complicated!\"}}" //encrypt encrypted := pubnubMessaging.EncryptString("enigma", message) if "zMqH/RTPlC8yrAZ2UhpEgLKUVzkMI2cikiaVg30AyUu7B6J0FLqCazRzDOmrsFsF" == encrypted { fmt.Println("StuffCan encryption: passed.") } else { t.Error("StuffCan encryption: failed.") } }
// TestHashEncryption tests the hash encryption. // Assumes that the input message is not serialized // Decrypted string should match GsvkCYZoYylL5a7/DKhysDjNbwn+BtBtHj2CvzC4Y4g= func TestHashEncryption(t *testing.T) { message := "{\"foo\":{\"bar\":\"foobar\"}}" //encrypt encrypted := pubnubMessaging.EncryptString("enigma", message) if "GsvkCYZoYylL5a7/DKhysDjNbwn+BtBtHj2CvzC4Y4g=" == encrypted { fmt.Println("Hash encryption: passed.") } else { t.Error("Hash encryption: failed.") } }
// TestYayEncryptionBasic tests the yay encryption. // Assumes that the input message is not serialized // Decrypted string should match q/xJqqN6qbiZMXYmiQC1Fw== func TestYayEncryptionBasic(t *testing.T) { message := "yay!" //encrypt encrypted := pubnubMessaging.EncryptString("enigma", message) if "q/xJqqN6qbiZMXYmiQC1Fw==" == encrypted { fmt.Println("Yay encryption basic: passed.") } else { t.Error("Yay encryption basic: failed.") } }
// TestGermanEncryption tests the German encryption. // Assumes that the input message is not serialized // Decrypted string should match stpgsG1DZZxb44J7mFNSzg== func TestGermanEncryption(t *testing.T) { message := "ÜÖ" b, err := json.Marshal(message) if err != nil { fmt.Println("error:", err) t.Error("Unicode encryption: failed.") } else { //encrypt encrypted := pubnubMessaging.EncryptString("enigma", string(b)) if "stpgsG1DZZxb44J7mFNSzg==" == encrypted { fmt.Println("German encryption: passed.") } else { t.Error("German encryption: failed.") } } }
// TestUnicodeEncryption tests the Unicode encryption. // Assumes that the input message is not serialized // Decrypted string should match +BY5/miAA8aeuhVl4d13Kg== func TestUnicodeEncryption(t *testing.T) { message := "漢語" b, err := json.Marshal(message) if err != nil { fmt.Println("error:", err) t.Error("Unicode encryption: failed.") } else { //encrypt encrypted := pubnubMessaging.EncryptString("enigma", string(b)) if "+BY5/miAA8aeuhVl4d13Kg==" == encrypted { fmt.Println("Unicode encryption: passed.") } else { t.Error("Unicode encryption: failed.") } } }
// TestPubNubEncryption tests the Pubnub Messaging API 1 encryption. // Assumes that the input message is not serialized // Decrypted string should match f42pIQcWZ9zbTbH8cyLwByD/GsviOE0vcREIEVPARR0= func TestPubNubEncryption(t *testing.T) { message := "Pubnub Messaging API 1" b, err := json.Marshal(message) if err != nil { fmt.Println("error:", err) t.Error("Pubnub Messaging API 1 encryption: failed.") } else { //encrypt encrypted := pubnubMessaging.EncryptString("enigma", string(b)) if "f42pIQcWZ9zbTbH8cyLwByD/GsviOE0vcREIEVPARR0=" == encrypted { fmt.Println("Pubnub Messaging API 1 encryption: passed.") } else { t.Error("Pubnub Messaging API 1 encryption: failed.") } } }
// TestPubNubEncryption2 tests the Pubnub Messaging API 2 encryption. // Assumes that the input message is not serialized // Decrypted string should match f42pIQcWZ9zbTbH8cyLwB/tdvRxjFLOYcBNMVKeHS54= func TestPubNubEncryption2(t *testing.T) { message := "Pubnub Messaging API 2" b, err := json.Marshal(message) if err != nil { fmt.Println("error:", err) t.Error("Pubnub Messaging API 2 encryption: failed.") } else { //encrypt encrypted := pubnubMessaging.EncryptString("enigma", string(b)) if "f42pIQcWZ9zbTbH8cyLwB/tdvRxjFLOYcBNMVKeHS54=" == encrypted { fmt.Println("Pubnub Messaging API 2 encryption: passed.") } else { t.Error("Pubnub Messaging API 2 encryption: failed.") } } }
// TestYayEncryption tests the yay encryption. // Assumes that the input message is serialized // Decrypted string should match q/xJqqN6qbiZMXYmiQC1Fw== func TestYayEncryption(t *testing.T) { message := "yay!" //serialize b, err := json.Marshal(message) if err != nil { fmt.Println("error:", err) t.Error("My object encryption: failed.") } else { //encrypt encrypted := pubnubMessaging.EncryptString("enigma", string(b)) if "Wi24KS4pcTzvyuGOHubiXg==" == encrypted { fmt.Println("Yay encryption: passed.") } else { t.Error("Yay encryption: failed.") } } }
// TestComplexClassEncryption tests the complex struct encryption. // Encrypted string should match uu3hDKcmV5/5mym7sIPJaf+W3Uu1xJLZLYaEBJPbZut+uwGHV5QmMWCOTTSOuBwcNk4bldx+y1ZAaHFETwkfMOOCHvdwrw6YcoyuJDqPglD+DEwLjUes50nEfrw7aMwmsKP2BmbyM+0mL2Nw30X4QP6lCcOaaUgXGWuMPJXfhrutSpiDDvJhSG6/eqZUEVmpKilxVnbsCqYGRWHHIE5dbuWE1odOot6oW4OobspaQtK2bBj/MNwFWwoZjLgyRi6Rxm0PRhgcOgxWneSrIW5UUf6xan4i4UfSN0PevVu5iRxwg1yLSISQViYihwFkc6ncJaUQ6nY+fESwHAn8IYGTYtuHc4j/C9pQwB5WhnoUaXRiJKchjnCf+zS6hyU7hlDZm7XdXRI6dZIIHGfBI5o2H/DmT3DFQM/mUZQLqmyFGM72QXV4bRIr0zUulTMOQgDVL2khic8bEZ28ji68ogNSnRMDMW81IzRInpv14zWyADRcab2tnlcQosmVwhDSJtnd func TestComplexClassEncryption(t *testing.T) { customComplexMessage := InitComplexMessage() //serialize b1, err := json.Marshal(customComplexMessage) if err != nil { fmt.Println("error:", err) t.Error("Custom complex encryption: failed.") } else { //encrypt encrypted := pubnubMessaging.EncryptString("enigma", string(b1)) if "uu3hDKcmV5/5mym7sIPJaf+W3Uu1xJLZLYaEBJPbZut+uwGHV5QmMWCOTTSOuBwcNk4bldx+y1ZAaHFETwkfMOOCHvdwrw6YcoyuJDqPglD+DEwLjUes50nEfrw7aMwmsKP2BmbyM+0mL2Nw30X4QP6lCcOaaUgXGWuMPJXfhrutSpiDDvJhSG6/eqZUEVmpKilxVnbsCqYGRWHHIE5dbuWE1odOot6oW4OobspaQtK2bBj/MNwFWwoZjLgyRi6Rxm0PRhgcOgxWneSrIW5UUf6xan4i4UfSN0PevVu5iRxwg1yLSISQViYihwFkc6ncJaUQ6nY+fESwHAn8IYGTYtuHc4j/C9pQwB5WhnoUaXRiJKchjnCf+zS6hyU7hlDZm7XdXRI6dZIIHGfBI5o2H/DmT3DFQM/mUZQLqmyFGM72QXV4bRIr0zUulTMOQgDVL2khic8bEZ28ji68ogNSnRMDMW81IzRInpv14zWyADRcab2tnlcQosmVwhDSJtnd" == encrypted { fmt.Println("Custom complex encryption: passed.") } else { t.Error("Custom complex encryption: failed.") } } }
// TestObjectEncryption tests the empty object encryption. // The output is not serialized // Encrypted string should match the serialized object func TestObjectEncryption(t *testing.T) { message := EmptyStruct{} //serialize b, err := json.Marshal(message) if err != nil { fmt.Println("error:", err) t.Error("Object encryption: failed.") } else { //encrypt encrypted := pubnubMessaging.EncryptString("enigma", string(b)) if "IDjZE9BHSjcX67RddfCYYg==" == encrypted { fmt.Println("Object encryption: passed.") } else { t.Error("Object encryption: failed.") } } }
// TestArrayEncryption tests the slice encryption. // Assumes that the input message is not serialized // Decrypted string should match Ns4TB41JjT2NCXaGLWSPAQ== func TestArrayEncryption(t *testing.T) { message := []string{} //serialize b, err := json.Marshal(message) if err != nil { fmt.Println("error:", err) t.Error("Slice encryption: failed.") } else { //encrypt encrypted := pubnubMessaging.EncryptString("enigma", string(b)) if "Ns4TB41JjT2NCXaGLWSPAQ==" == encrypted { fmt.Println("Slice encryption: passed.") } else { t.Error("Slice encryption: failed.") } } }
// TestMyObjectEncryption tests the custom object encryption. // The output is not serialized // Encrypted string should match the serialized object func TestMyObjectEncryption(t *testing.T) { message := CustomStruct{ Foo: "hi!", Bar: []int{1, 2, 3, 4, 5}, } //serialize b1, err := json.Marshal(message) if err != nil { fmt.Println("error:", err) t.Error("My object encryption: failed.") } else { //encrypt encrypted := pubnubMessaging.EncryptString("enigma", string(b1)) if "BMhiHh363wsb7kNk7krTtDcey/O6ZcoKDTvVc4yDhZY=" == encrypted { fmt.Println("My object encryption: passed.") } else { t.Error("My object encryption: failed.") } } }