Exemple #1
0
func TestUnpad(t *testing.T) {
	message := "yzJ2MMyt8So18nNXm4m3Dl0XuYAOJFj2JXG8P3BGlCsDsqM44ReH15MRGbEkJZCSqgMiX1wUK44Qz8gsTcmGcZm/7KtOa+kRnvgDpNkTuBUrDqSjmYeuBLqRIEIfoGrRNljbFmP1W9Zv8iVbJMmovF+gmNNiIzlC3J9dHK51/OgW7s2EASMQJr3UJZ26PoFmmXY/wYN+2EyRnT4PBRCocQ=="
	decrypted, _ := messaging.DecryptString("enigma", message)

	decMessage := fmt.Sprintf("%s", decrypted)

	if !strings.Contains(decMessage, `"user":{"key":"*****@*****.**"}`) || !strings.Contains(decMessage, `"key":"54651fa39868621628000002"`) {
		t.Error("TestPad: failed.")
	}
}
Exemple #2
0
// 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 := messaging.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.")
		}
	}
}
Exemple #3
0
// 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 := messaging.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.")
		}
	}
}
Exemple #4
0
// 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 := messaging.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.")
		}
	}
}
Exemple #5
0
// 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 := messaging.DecryptString("enigma", message)
	if decErr != nil {
		t.Error("German decryption: failed.")
	} else {
		data, _, _, err := messaging.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.")
			}
		}
	}
}
Exemple #6
0
// 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 := messaging.DecryptString("enigma", message)
	if decErr != nil {
		t.Error("Unicode decryption: failed.")
	} else {
		data, _, _, err := messaging.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.")
			}
		}
	}
}
Exemple #7
0
// 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 := messaging.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.")
			}
		}
	}
}
Exemple #8
0
// 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 := messaging.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.")
			}
		}
	}
}
Exemple #9
0
// 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 := messaging.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.")
			}
		}
	}
}
Exemple #10
0
// 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 := messaging.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.")
			}
		}
	}
}
Exemple #11
0
// 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 := messaging.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.")
			}
		}
	}
}
Exemple #12
0
// TestComplexClassDecryption tests the complex struct decryption.
// Decrypted string should match Bc846Ri5HK1ixqP/dzAyZq23Z/NBlcPn2UX8h38xTGINs72yF5gtU0t9fFEMxjY+DmezWt0nG7eN7RABrj697tK1nooVHYIxgDLMsjMTw5N0K+rUM823n7LcHfEoXaX8oH2E6zkg6iK5pmT8nlh6LF6Bw1G5zkluT8oTjnbFJcpEvTyT2ZKzcqptgYsE9XZiqgBMEfYqwphDzmOv+TjHkJai+paV0rzFxIfVK8KHCA14z+1kKDMPghlmzx2tUmmbQb04hjhvgDvvi3tknytYVqJo1L5jZkAZTVXRfed7wq+L+1V824c9AwVsG9iCv15/Jemjjfzk07MXawk+hjmQvjQDWLS/ww3vwkNXiuJITbVCPOBADwJhBnFqkkb/Hd8LaKwyFhWeXwoZWbqugDoYufUzJApf4Nl/4RthYoisqJIokmxiWvYeD1TuH+C457kDaEu3aJd+KdLf8k9QkmaDNqkZo9Z/BRkZ63oMna1aEBy7bSE3l/lw40dnhsMaYfYk
func TestComplexClassDecryption(t *testing.T) {
	message := "Bc846Ri5HK1ixqP/dzAyZq23Z/NBlcPn2UX8h38xTGINs72yF5gtU0t9fFEMxjY+DmezWt0nG7eN7RABrj697tK1nooVHYIxgDLMsjMTw5N0K+rUM823n7LcHfEoXaX8oH2E6zkg6iK5pmT8nlh6LF6Bw1G5zkluT8oTjnbFJcpEvTyT2ZKzcqptgYsE9XZiEn84zv0wjDMxSJzlM7cbe2JpLtR99mdkUf8SMVr+J0ym6Z9c02MKLP6bygWzdG9zTdkLSIxJE3R9Yt76XeRFdrbRNWkuQM/uItDsE23+8RKwZRyAScoDMwFAg+BSa6KF1tS6cJlyjxA8o5e9iWykKuHO0h1uAiapzTx9iZluOH2bVZgTUu1GABjXveMBAkrZ1eG4nVOlytsAr1oSekKvWxzyUEP2kFSrtQbg6oGECb1OMmj5bd21cx0vpDWr/juGT7/n4sBr7gYsWDvBaU7awN9Y7bcq14jtiXq/2iNNW0zoI3xe6+qByimHaiAgVoqO"
	//decrypt
	decrypted, decErr := messaging.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.")
			}
		}
	}
}
Exemple #13
0
// 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 := messaging.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.")
			}
		}
	}
}