zcool321@sina.com 6 роки тому
батько
коміт
441afd2acc
1 змінених файлів з 28 додано та 0 видалено
  1. 28 0
      gtoken/gtoken_test.go

+ 28 - 0
gtoken/gtoken_test.go

@@ -30,3 +30,31 @@ func TestEncryptDecryptToken(t *testing.T) {
 	}
 
 }
+
+func BenchmarkEncryptDecryptToken(b *testing.B) {
+	b.Log("encrypt and decrypt token test ")
+	gtoken := gtoken.GfToken{}
+	gtoken.Init()
+
+	userKey := "123123"
+	token := gtoken.EncryptToken(userKey)
+	if !token.Success() {
+		b.Error(token.Json())
+	}
+	b.Log(token.DataString())
+
+	for i := 0; i < b.N; i++ {
+		token2 := gtoken.DecryptToken(token.GetString("token"))
+		if !token2.Success() {
+			b.Error(token2.Json())
+		}
+		b.Log(token2.DataString())
+		if userKey != token2.GetString("userKey") {
+			b.Error("token decrypt userKey error")
+		}
+		if token.GetString("uuid") != token2.GetString("uuid") {
+			b.Error("token decrypt uuid error")
+		}
+	}
+
+}