Browse Source

make the queuedid fit 32 bytes, add test case

flashmob 5 years ago
parent
commit
9eef28f551
2 changed files with 13 additions and 1 deletions
  1. 2 1
      mail/envelope.go
  2. 11 0
      mail/envelope_test.go

+ 2 - 1
mail/envelope.go

@@ -171,7 +171,8 @@ func NewEnvelope(remoteAddr string, clientID uint64, iface string) *Envelope {
 
 
 func queuedID(clientID uint64, iface string) string {
 func queuedID(clientID uint64, iface string) string {
 	h := fnv.New128a()
 	h := fnv.New128a()
-	return fmt.Sprintf("%x", h.Sum([]byte(fmt.Sprintf("%v%v%v", time.Now(), clientID, iface))))
+	_, _ = h.Write([]byte(fmt.Sprintf("%v%v%v", time.Now(), clientID, iface)))
+	return fmt.Sprintf("%x", h.Sum([]byte{}))
 }
 }
 
 
 // ParseHeaders parses the headers into Header field of the Envelope struct.
 // ParseHeaders parses the headers into Header field of the Envelope struct.

+ 11 - 0
mail/envelope_test.go

@@ -160,3 +160,14 @@ func TestEncodedWordAhead(t *testing.T) {
 	}
 	}
 
 
 }
 }
+
+func TestQueuedID(t *testing.T) {
+	str := queuedID(555, "127.0.7.4")
+	if len(str) != 32 {
+		t.Error("queuedID needs to be 32 bytes in length")
+	}
+	str2 := queuedID(555, "127.0.7.4")
+	if str == str2 {
+		t.Error("hashes should not be equal")
+	}
+}