package main

import (
	"testing"
)

func TestEncodingMessage(t *testing.T) {
	SetupConfig()

	//明文：
	var msg = `<xml><ToUserName><![CDATA[gh_f09231355c68]]></ToUserName>
<FromUserName><![CDATA[oUN420bxqFqlx0ZQHciUOesZO3PE]]></FromUserName>
<CreateTime>1492972518</CreateTime>
<MsgType><![CDATA[event]]></MsgType>
<Event><![CDATA[CLICK]]></Event>
<EventKey><![CDATA[V1001_TODAY_MUSIC]]></EventKey>
</xml>`

	e := Encode(msg)
	//t.Log(e)
	d := Decode(e)

	if d != msg {
		t.Error("encode a message then decode it failed")
	}

	//预先加密和的密文，和msg相同
	var encrypted1 = "P2DoRtilYwJ1aM+VW1sGs6p11Rhcd/TrFYtvsw53SUVw2Knh27hF5IZUBxRXbz+k87zy983ec5aOwgS+WxYoejmGubaqiYy2yfCBNyGRlWfe+iWc2TnvPIEAJebSWuNOJ7FoITeMndr4tW391XxDdMom8I/VsqKnsZZAangUsxmA1ZEnP/d4Lx8/xt3qJKrJMa4Q8s9VsOOvzLIGhL1IN5bHaXN+CwgBTAUCrHD8AneiX5MLSv/74qozg+jKBSUebZrjRYuTymQ3TBh3pQXyRBQTZNrCAe1tlcNli9e5MSUMsHFIzGw/kiu93/5VkxCYRLgRDQKl9oam4+Rpxywir7EiT7I4X343l9ogcMLWX16evkLlQHoqBhLl6ZcfW7Nmq8/Ghy8jbuwqkR/0jLJ/avtjzgJOwaxdBUz4nYZ452rLJekxIvsmV6PZgCXRrKHzmpZX+i6hIRIWiIaDeMOEsw=="
	//不同的密文： （相同的明文）
	var encrypted2 = "yKlFGV+ukblgxH7PvN6jgCGGC8TkC6J9C0F1XnvcLQKS9R5RSJYib4EZZftpyfc5x6WDfM7++vunEawNz54Gu4746byRaqQyW9G6zX7o6ro5YDGbNuYpBflwi6bNM6hncIKYb8oH3VFHEvSsUb1eg4fNwdebeEhpixDlPPbwAUXOZ7FcN6UWkSiZhZMKZNSv42+u9GK/nFEv1Fa8nW4NWNLXU4V2OFM+5d0lAGb0I9pD69IsuUFeBuJ8ZOGPB4EVKI2xODpicJkYP3ym5ePpz3GC4EFk5JwIiPw+EYbqKH0ADNhrsRHtAzLh6rjyNWCVkij68XmWBJ8I8l38a/zycFZ4uvef7ceEByvhKIVM7p/eO55NOl/F6W6hmEQwOgw/7tPjrErA4aPuijPAjgtVw0ngb32O9/XRSe91h802oyhWwnoQgTF7tZqKLpJLxM9g+BiUar/13j0eivql0B6gWg=="

	f := Decode(encrypted1)
	g := Decode(encrypted2)

	//t.Log(f)
	//t.Log(g)
	if f != g {
		t.Error("decoding two different encryption to same message failed")
	}

	if f != msg {
		t.Error("Decoding itself failed")
	}

}
