예제 #1
0
// 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 := messaging.EncryptString("enigma", message)
	if "zMqH/RTPlC8yrAZ2UhpEgLKUVzkMI2cikiaVg30AyUu7B6J0FLqCazRzDOmrsFsF" == encrypted {
		fmt.Println("StuffCan encryption: passed.")
	} else {
		t.Error("StuffCan encryption: failed.")
	}
}
예제 #2
0
// 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 := messaging.EncryptString("enigma", message)
	if "GsvkCYZoYylL5a7/DKhysDjNbwn+BtBtHj2CvzC4Y4g=" == encrypted {
		fmt.Println("Hash encryption: passed.")
	} else {
		t.Error("Hash encryption: failed.")
	}
}
예제 #3
0
// 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 := messaging.EncryptString("enigma", message)

	if "q/xJqqN6qbiZMXYmiQC1Fw==" == encrypted {
		fmt.Println("Yay encryption basic: passed.")
	} else {
		t.Error("Yay encryption basic: failed.")
	}
}
예제 #4
0
// 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 := messaging.EncryptString("enigma", string(b))
		if "stpgsG1DZZxb44J7mFNSzg==" == encrypted {
			fmt.Println("German encryption: passed.")
		} else {
			t.Error("German encryption: failed.")
		}
	}
}
예제 #5
0
// 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 := messaging.EncryptString("enigma", string(b))
		if "+BY5/miAA8aeuhVl4d13Kg==" == encrypted {
			fmt.Println("Unicode encryption: passed.")
		} else {
			t.Error("Unicode encryption: failed.")
		}
	}
}
예제 #6
0
// 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 := messaging.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.")
		}
	}
}
예제 #7
0
// 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 := messaging.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.")
		}
	}
}
예제 #8
0
// 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 := messaging.EncryptString("enigma", string(b))
		if "IDjZE9BHSjcX67RddfCYYg==" == encrypted {
			fmt.Println("Object encryption: passed.")
		} else {
			t.Error("Object encryption: failed.")
		}
	}
}
예제 #9
0
// 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 := messaging.EncryptString("enigma", string(b))
		if "Ns4TB41JjT2NCXaGLWSPAQ==" == encrypted {
			fmt.Println("Slice encryption: passed.")
		} else {
			t.Error("Slice encryption: failed.")
		}
	}
}
예제 #10
0
// 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 := messaging.EncryptString("enigma", string(b))
		if "Wi24KS4pcTzvyuGOHubiXg==" == encrypted {
			fmt.Println("Yay encryption: passed.")
		} else {
			t.Error("Yay encryption: failed.")
		}
	}
}
예제 #11
0
// TestComplexClassEncryption tests the complex struct encryption.
// Encrypted string should match Bc846Ri5HK1ixqP/dzAyZq23Z/NBlcPn2UX8h38xTGINs72yF5gtU0t9fFEMxjY+DmezWt0nG7eN7RABrj697tK1nooVHYIxgDLMsjMTw5N0K+rUM823n7LcHfEoXaX8oH2E6zkg6iK5pmT8nlh6LF6Bw1G5zkluT8oTjnbFJcpEvTyT2ZKzcqptgYsE9XZiqgBMEfYqwphDzmOv+TjHkJai+paV0rzFxIfVK8KHCA14z+1kKDMPghlmzx2tUmmbQb04hjhvgDvvi3tknytYVqJo1L5jZkAZTVXRfed7wq+L+1V824c9AwVsG9iCv15/Jemjjfzk07MXawk+hjmQvjQDWLS/ww3vwkNXiuJITbVCPOBADwJhBnFqkkb/Hd8LaKwyFhWeXwoZWbqugDoYufUzJApf4Nl/4RthYoisqJIokmxiWvYeD1TuH+C457kDaEu3aJd+KdLf8k9QkmaDNqkZo9Z/BRkZ63oMna1aEBy7bSE3l/lw40dnhsMaYfYk
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 := messaging.EncryptString("enigma", string(b1))
		fmt.Println("enc:", encrypted)
		if "Bc846Ri5HK1ixqP/dzAyZq23Z/NBlcPn2UX8h38xTGINs72yF5gtU0t9fFEMxjY+DmezWt0nG7eN7RABrj697tK1nooVHYIxgDLMsjMTw5N0K+rUM823n7LcHfEoXaX8oH2E6zkg6iK5pmT8nlh6LF6Bw1G5zkluT8oTjnbFJcpEvTyT2ZKzcqptgYsE9XZiEn84zv0wjDMxSJzlM7cbe2JpLtR99mdkUf8SMVr+J0ym6Z9c02MKLP6bygWzdG9zTdkLSIxJE3R9Yt76XeRFdrbRNWkuQM/uItDsE23+8RKwZRyAScoDMwFAg+BSa6KF1tS6cJlyjxA8o5e9iWykKuHO0h1uAiapzTx9iZluOH2bVZgTUu1GABjXveMBAkrZ1eG4nVOlytsAr1oSekKvWxzyUEP2kFSrtQbg6oGECb1OMmj5bd21cx0vpDWr/juGT7/n4sBr7gYsWDvBaU7awN9Y7bcq14jtiXq/2iNNW0zoI3xe6+qByimHaiAgVoqO" == encrypted {
			fmt.Println("Custom complex encryption: passed.")
		} else {
			t.Error("Custom complex encryption: failed.")
		}
	}
}
예제 #12
0
// 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 := messaging.EncryptString("enigma", string(b1))
		if "BMhiHh363wsb7kNk7krTtDcey/O6ZcoKDTvVc4yDhZY=" == encrypted {
			fmt.Println("My object encryption: passed.")
		} else {
			t.Error("My object encryption: failed.")
		}
	}
}
예제 #13
0
func TestPad(t *testing.T) {
	var bad_msg interface{}
	b := []byte(`{
	"kind": "click",
	"user": {"key" : "*****@*****.**"},
	"creationDate": 2416012257208,
	"key": "54651fa39868621628000002",
	"url": "http://www.google.com"
	}`)

	json.Unmarshal(b, &bad_msg)
	jsonSerialized, _ := json.Marshal(bad_msg)

	encrypted := messaging.EncryptString("enigma", fmt.Sprintf("%s", jsonSerialized))
	//fmt.Println(encrypted);
	expected := "yzJ2MMyt8So18nNXm4m3Dl0XuYAOJFj2JXG8P3BGlCsDsqM44ReH15MRGbEkJZCSqgMiX1wUK44Qz8gsTcmGcZm/7KtOa+kRnvgDpNkTuBUrDqSjmYeuBLqRIEIfoGrRNljbFmP1W9Zv8iVbJMmovF+gmNNiIzlC3J9dHK51/OgW7s2EASMQJr3UJZ26PoFmmXY/wYN+2EyRnT4PBRCocQ=="
	if encrypted != expected {
		t.Error("TestPad: failed.")
	}
}